Commit 9d4823d2 authored by Vincent-Xavier JUMEL's avatar Vincent-Xavier JUMEL
Browse files

Merge branch '14-lecture-entree-json' into 'master'

Resolve "Recherche des binômes "forts""

Fusion du travail de lecture des fichiers

Closes #12 

See merge request !8
parents 9a723972 babf3424
Pipeline #179225 passed with stage
in 48 seconds
{
"Alexia": {"Kellian": 2, "Christelle": 1},
"Isabelle": {"Inès R.": 1, "Kanel": 2},
"Inès R.": {"Isabelle": 1, "Amin": 2},
"Caroline": {"Isabelle": 1, "Amin": 2},
"Kanel": {"Isabelle": 1, "Lakchika": 2},
"Jannah": {"Anita": 2, "Lucy": 1},
"Amin": {"Lakchika": 1, "Inès L.": 2},
"Alexandre": {"Isabelle": 1, "Lakchika": 2},
"Salsabile": {"Alexis": 2, "Christelle": 1},
"Christelle": {"Salsabile": 1, "Alexis": 2},
"Alexis": {"Salsabile": 1, "Christelle": 2},
"Kellian": {"J-B": 1, "Amin": 2},
"J-B": {"Kellian": 1, "Amin": 2},
"Inès L.": {"Nina": 2, "Isabelle": 1},
"Nina": {"Isabelle": 2, "Prémina": 1},
"Maysha": {"Sanaa": 2, "Lakchika": 1},
"Mickaël": {"Sanaa": 2, "Lakchika": 1},
"Abderahmaine": {"J-B": 1, "Maysha": 2},
"Corentin": {"Maysha": 2, "Sanaa": 1},
"Warrick": {"Isabelle": 1, "Prémina": 2},
"Prémina": {"Lakchika": 1, "Clara": 2},
"Clara": {"Prémina": 1, "Warrick": 2},
"Lakchika": {"Sanaa": 2, "Prémina": 1},
"Douygu": {"Nina": 1, "Prémina": 2},
"Anita": {"Lucy": 1, "Jannah": 2},
"Lucy": {"Anita": 1, "Jannah": 2},
"Sanaa": {"Lakchika": 1, "Maysha": 2}
}
#!/usr/bin/env python
from setuptools import setup, find_packages
from setuptools import setup
setup(name='sociogramme',
version='0.1',
......
......@@ -2,74 +2,50 @@ import doctest
from matplotlib import pyplot as plt
import networkx as nx
from numpy import zeros
import copy # pour copier le dictionnaire de données afin de le modifier
# sans modifier le dictionnaire initial
exemple_graphe = {
'Alexia': {'Kellian': 2, 'Christelle': 1},
'Isabelle': {'Inès R.': 1, 'Kanel': 2},
'Inès R.': {'Isabelle': 1, 'Amin': 2},
'Caroline': {'Isabelle': 1, 'Amin': 2},
'Kanel': {'Isabelle': 1, 'Lakchika': 2},
'Jannah': {'Anita': 2, 'Lucy': 1},
'Amin': {'Lakchika': 1, 'Inès L.': 2},
'Alexandre': {'Isabelle': 1, 'Lakchika': 2},
'Salsabile': {'Alexis': 2, 'Christelle': 1},
'Christelle': {'Salsabile': 1, 'Alexis': 2},
'Alexis': {'Salsabile': 1, 'Christelle': 2},
'Kellian': {'J-B': 1, 'Amin': 2},
'J-B': {'Kellian': 1, 'Amin': 2},
'Inès L.': {'Nina': 2, 'Isabelle': 1},
'Nina': {'Isabelle': 2, 'Prémina': 1},
'Maysha': {'Sanaa': 2, 'Lakchika': 1},
'Mickaël': {'Sanaa': 2, 'Lakchika': 1},
'Abderahmaine': {'J-B': 1, 'Maysha': 2},
'Corentin': {'Maysha': 2, 'Sanaa': 1},
'Warrick': {'Isabelle': 1, 'Prémina': 2},
'Prémina': {'Lakchika': 1, 'Clara': 2},
'Clara': {'Prémina': 1, 'Warrick': 2},
'Lakchika': {'Sanaa': 2, 'Prémina': 1},
'Douygu': {'Nina': 1, 'Prémina': 2},
'Anita': {'Lucy': 1, 'Jannah': 2},
'Lucy': {'Anita': 1, 'Jannah': 2},
'Sanaa': {'Lakchika': 1, 'Maysha': 2}
}
# TODO: Lire un fichier json passer en argument
dict_amis_numeros = {
0: {20: 2, 15: 1},
1: {13: 1, 18: 2},
2: {17: 2, 7: 1},
3: {24: 1, 7: 2},
4: {18: 1, 11: 2},
5: {14: 2, 19: 1},
6: {13: 1, 4: 2},
7: {3: 2, 24: 1},
8: {23: 1, 26: 2},
9: {25: 1, 20: 2},
10: {23: 2, 22: 1},
11: {13: 1, 22: 2},
12: {13: 1, 4: 2},
13: {16: 2, 12: 1},
14: {17: 1, 4: 2},
15: {5: 2, 19: 1},
16: {13: 1, 18: 2},
17: {4: 2, 15: 1},
18: {23: 1, 25: 2},
19: {5: 1, 14: 2},
20: {18: 1, 25: 2},
21: {18: 1, 25: 2},
22: {13: 2, 23: 1},
23: {18: 1, 8: 2},
24: {3: 2, 7: 1},
25: {18: 1, 20: 2},
26: {13: 1, 23: 2}
}
# TODO: automatiser la génération de ce dictonnaire à partir du graphe
# précédent.
import copy
# pour copier le dictionnaire de données afin de le modifier sans modifier le
# dictionnaire initial
import json
def lire_entree_json():
"""
Cette fonction lit un fichier json en entrée et renvoie le dictionnaire
associé.
"""
with open('data_exemple.json', 'r') as fichier:
donnees = fichier.read()
exemple_graphe = json.loads(donnees)
return exemple_graphe
def associer_eleves_numeros(dictionnaire):
"""
Cette fonction prend en entrée un dictionnaire et renvoie un dictionnaire
associant les élèves à un numero d'ordre.
"""
dict_eleves_numero = {}
for k1,v1 in enumerate(dictionnaire):
dict_eleves_numero[v1] = k1
return dict_eleves_numero
def graphe_numerique(dictionnaire,dict_eleves_numero):
"""
Cette fonction prend en entrée un dictionnaire (le graphe) et renvoie un
dictionnaire (le graphe) purement numérique.
"""
dict_amis_numeros = dict((dict_eleves_numero[key], value) for (key, value) in dictionnaire.items())
print(dict_amis_numeros)
for v in dict_amis_numeros.items():
dict_amis_numeros[v[0]] = dict((dict_eleves_numero[key], value) for (key, value) in v[1].items())
return dict_amis_numeros
exemple_graphe = lire_entree_json()
dict_eleves_numero = associer_eleves_numeros(exemple_graphe)
dict_amis_numeros = graphe_numerique(exemple_graphe, dict_eleves_numero)
def cree_dict_classe_liste(dictionnaire):
"""
......
from src.main import *
exemple_graphe = {
'Alexia': {'Kellian': 2, 'Christelle': 1},
'Isabelle': {'Inès R.': 1, 'Kanel': 2},
'Inès R.': {'Isabelle': 1, 'Amin': 2},
'Caroline': {'Isabelle' : 1, 'Amin': 2},
'Kanel': {'Isabelle': 1, 'Lakchika': 2},
'Jannah': {'Anita':2 , 'Lucy': 1},
'Amin': {'Lakchika': 1, 'Inès L.': 2},
'Alexandre': {'Isabelle': 1, 'Lakchika': 2},
'Salsabile': {'Alexis': 2,'Christelle': 1},
'Christelle': {'Salsabile': 1, 'Alexis': 2},
'Alexis': {'Salsabile': 1, 'Christelle': 2},
'Kellian': {'J-B':1, 'Amin': 2},
'J-B': {'Kellian': 1, 'Amin': 2},
'Inès L.': {'Nina': 2, 'Isabelle': 1},
'Nina': {'Isabelle': 2, 'Prémina': 1},
'Maysha': {'Sanaa': 2, 'Lakchika': 1},
'Mickaël': {'Sanaa': 2, 'Lakchika': 1},
'Abderahmaine': {'J-B': 1,'Maysha': 2},
'Corentin': {'Maysha': 2, 'Sanaa': 1},
'Warrick': {'Isabelle': 1, 'Prémina': 2},
'Prémina': {'Lakchika': 1, 'Clara': 2},
'Clara': {'Prémina': 1, 'Warrick': 2},
'Lakchika': {'Sanaa': 2,'Prémina': 1},
'Douygu': {'Nina': 1, 'Prémina': 2},
'Anita': {'Lucy': 1, 'Jannah': 2},
'Lucy': {'Anita': 1, 'Jannah': 2},
'Sanaa':{'Lakchika': 1,'Maysha':2}
}
dict_amis_numeros = {0: {11: 2, 9: 1}, 1: {2: 1, 4: 2}, 2: {1: 1, 6: 2}, 3: {1: 1, 6: 2}, 4: {1: 1, 22: 2}, 5: {24: 2, 25: 1}, 6: {22: 1, 13: 2}, 7: {1: 1, 22: 2}, 8: {10: 2, 9: 1}, 9: {8: 1, 10: 2}, 10: {8: 1, 9: 2}, 11: {12: 1, 6: 2}, 12: {11: 1, 6: 2}, 13: {14: 2, 1: 1}, 14: {1: 2, 20: 1}, 15: {26: 2, 22: 1}, 16: {26: 2, 22: 1}, 17: {12: 1, 15: 2}, 18: {15: 2, 26: 1}, 19: {1: 1, 20: 2}, 20: {22: 1, 21: 2}, 21: {20: 1, 19: 2}, 22: {26: 2, 20: 1}, 23: {14: 1, 20: 2}, 24: {25: 1, 5: 2}, 25: {24: 1, 5: 2}, 26: {22: 1, 15: 2}}
def test_lire_entree_json():
assert lire_entree_json() == exemple_graphe
def test_associer_eleves_numeros():
assert associer_eleves_numeros({'Alexia':{1}, 'Bernard': {2}}) == \
{'Alexia': 0, 'Bernard': 1}
def test_graphe_numerique():
assert graphe_numerique(exemple_graphe, \
associer_eleves_numeros(exemple_graphe)) == \
dict_amis_numeros
......@@ -6,36 +6,6 @@ from numpy import matrix, zeros
from src.main import *
exemple_graphe = {
'Alexia': {'Kellian': 2, 'Christelle': 1},
'Isabelle': {'Inès R.': 1, 'Kanel': 2},
'Inès R.': {'Isabelle': 1, 'Amin': 2},
'Caroline': {'Isabelle' : 1, 'Amin': 2},
'Kanel': {'Isabelle': 1, 'Lakchika': 2},
'Jannah': {'Anita':2 , 'Lucy': 1},
'Amin': {'Lakchika': 1, 'Inès L.': 2},
'Alexandre': {'Isabelle': 1, 'Lakchika': 2},
'Salsabile': {'Alexis': 2,'Christelle': 1},
'Christelle': {'Salsabile': 1, 'Alexis': 2},
'Alexis': {'Salsabile': 1, 'Christelle': 2},
'Kellian': {'J-B':1, 'Amin': 2},
'J-B': {'Kellian': 1, 'Amin': 2},
'Inès L.': {'Nina': 2, 'Isabelle': 1},
'Nina': {'Isabelle': 2, 'Prémina': 1},
'Maysha': {'Sanaa': 2, 'Lakchika': 1},
'Mickaël': {'Sanaa': 2, 'Lakchika': 1},
'Abderahmaine': {'J-B': 1,'Maysha': 2},
'Corentin': {'Maysha': 2, 'Sanaa': 1},
'Warrick': {'Isabelle': 1, 'Prémina': 2},
'Prémina': {'Lakchika': 1, 'Clara': 2},
'Clara': {'Prémina': 1, 'Warrick': 2},
'Lakchika': {'Sanaa': 2,'Prémina': 1},
'Douygu': {'Nina': 1, 'Prémina': 2},
'Anita': {'Lucy': 1, 'Jannah': 2},
'Lucy': {'Anita': 1, 'Jannah': 2},
'Sanaa':{'Lakchika': 1,'Maysha':2}
}
def test_cree_graphe():
assert nx.algorithms.is_isomorphic(cree_graphe_nx(exemple_graphe),
......@@ -58,13 +28,14 @@ def test_renvoyer_cycles(entree,attendu):
def test_sommets_cycles_3():
assert sommets_cycles_3(creation_matrice_adj(dict_amis_numeros)) == \
[3, 7, 8, 18, 20, 23, 24, 25, 26]
[5, 8, 9, 10, 15, 19, 20, 21, 22, 24, 25, 26]
def test_recherche_binomes():
assert recherche_binomes(creation_matrice_adj(dict_amis_numeros)) \
== [[3, 7], [3, 24], [5, 19], [7, 24], [8, 23], [12, 13], \
[13, 16], [18, 23], [18, 25], [20, 25]]
== [[1, 2], [1, 4], [5, 24], [5, 25], [8, 9], [8, 10], \
[9, 10], [11, 12], [15, 26], [20, 21], [20, 22], \
[22, 26], [24, 25]]
def test_dedoublonner():
......
......@@ -13,5 +13,5 @@ deps = pytest
# ... or run any other command line tool you need to run here
commands =
pytest --doctest-modules
pytest --cov=. tests/
pytest --cov=src tests/
pytest
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment