Kaynağa Gözat

Initial commit

feature/use_fb_data
Figg 5 ay önce
işleme
c803998be1
6 değiştirilmiş dosya ile 103 ekleme ve 0 silme
  1. 2
    0
      .gitignore
  2. 29
    0
      Readme.md
  3. 1
    0
      data/html_content.html
  4. 21
    0
      docker/Dockerfile
  5. 3
    0
      docker/requirements.txt
  6. 47
    0
      python/script.py

+ 2
- 0
.gitignore Dosyayı Görüntüle

@@ -0,0 +1,2 @@
1
+# ignore execution files
2
+output/

+ 29
- 0
Readme.md Dosyayı Görüntüle

@@ -0,0 +1,29 @@
1
+
2
+# Million Project Member Graph
3
+
4
+Ce projet cherche à générer un graphe représentant les membres du groupe sous forme d'un nuage de points et leur lien de relation avec la personne l'y ayant ajouté.
5
+
6
+Le graphe prend la forme d'un arbre avec un seul noeud racine, le fondateur du groupe (c'est Elias). Il n'y a théoriquement pas de boucle puisque chaque membre est ajouté par une personne qu'il ne peut pas ajouter à son tour, sauf dans le cas particulier où une personne quitte le groupe et se fait réinviter par une personne qui se trouvait dans sons sous-arbre ; Et l'interprétation de ce cas comme une boucle dépend de la manière de compiler les données.
7
+## Exécution
8
+
9
+Le projet s'exécute dans un container docker.
10
+Il vous faut d'abord builder l'image :
11
+
12
+```bash
13
+  docker build --tag million_graph --file docker/Dockerfile .
14
+```
15
+
16
+Puis l'exécuter dans un container. La sortie du script est récupérée dans le dossier output/
17
+
18
+```bash
19
+docker run --rm --mount type=bind,src=$PWD/output,dst=/home/user/mil/output million_graph
20
+```
21
+
22
+Pour l'information, l'architecture du répertoire de travail dans l'image docker est construite différemment du répertoire du projet. Elle se présente ainsi :
23
+
24
+```
25
+/home/user/mil/
26
+├── data/
27
+│   └── data files
28
+└── script.py
29
+```

+ 1
- 0
data/html_content.html
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 21
- 0
docker/Dockerfile Dosyayı Görüntüle

@@ -0,0 +1,21 @@
1
+# Utiliser une image Python de base
2
+FROM python:3.11
3
+
4
+RUN useradd --create-home --shell /bin/bash user
5
+USER user
6
+
7
+# Créer un répertoire de travail
8
+WORKDIR /home/user/mil
9
+
10
+COPY docker/requirements.txt ./
11
+
12
+RUN pip install --no-cache-dir --upgrade pip \
13
+  && pip install --no-cache-dir -r requirements.txt
14
+
15
+# Copier le script Python et tout autre fichier nécessaire dans le conteneur
16
+COPY python/script.py .
17
+COPY data/html_content.html data/
18
+
19
+
20
+# Définir la commande par défaut pour exécuter le script Python
21
+CMD ["python", "script.py"]

+ 3
- 0
docker/requirements.txt Dosyayı Görüntüle

@@ -0,0 +1,3 @@
1
+beautifulsoup4
2
+pycairo
3
+igraph

+ 47
- 0
python/script.py Dosyayı Görüntüle

@@ -0,0 +1,47 @@
1
+import igraph as ig
2
+import math
3
+from bs4 import BeautifulSoup
4
+
5
+
6
+with open('./data/html_content.html', 'r', encoding='utf-8') as fichier:
7
+    html_content = fichier.read()
8
+
9
+def extraire_nom(entree, username=None):
10
+    if entree.startswith("Ouzhpennet gant "):
11
+        return entree.split("Ouzhpennet gant ")[1]
12
+    elif entree == "Ajouté(e) par vous":
13
+        return username
14
+    elif entree == "Créateur du groupe":
15
+        return None
16
+    else:
17
+        return None
18
+
19
+soup = BeautifulSoup(html_content, 'html.parser')
20
+arr = soup.get_text(separator='\n', strip=True).split('\n')[:-2]
21
+
22
+edges_as_names = [(extraire_nom(b, username='Maël Delanoë'), a) for a,b in zip(arr[:-2:2], arr[1::2])]
23
+vertices_as_names = list(set([i for tuple in edges_as_names for i in tuple if i is not None]))
24
+root = [vertices_as_names.index(child) for parent, child in edges_as_names if parent is None]
25
+
26
+edges_as_indexes = [(vertices_as_names.index(parent), vertices_as_names.index(child)) for parent, child in edges_as_names if parent is not None]
27
+nb_vertices = len(vertices_as_names)
28
+
29
+g = ig.Graph(nb_vertices, edges_as_indexes)
30
+g.vs["name"] = vertices_as_names
31
+
32
+#print(g)
33
+
34
+outputfile = "./output/output_plot.png"
35
+
36
+visual_style = {}
37
+visual_style["vertex_size"] = 2
38
+visual_style["vertex_color"] = "blue"
39
+visual_style["vertex_label"] = g.vs["name"]
40
+visual_style["edge_width"] = 0.5
41
+visual_style["edge_arrow_width"] = 20
42
+visual_style["bbox"] = (2160, 1920)
43
+visual_style["layout"] = "rt_circular"
44
+visual_style["margin"] = 100
45
+visual_style["vertex_label_angle"] = math.pi * 1.5
46
+visual_style["vertex_label_dist"] = 10
47
+ig.plot(g, outputfile, **visual_style)

Loading…
İptal
Kaydet