1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
-
- from million.model.message import Message
- import million.parse.fb_exports as fb
- import re
- import math
- import igraph as ig
-
- DATA_PATH = './data/'
-
- export = fb.parse_dirfiles(DATA_PATH)
-
-
- def extraire_nom(entree: Message):
- if entree.content is None:
- return None
-
- regex = r"(.+) a(?:vez)? ajouté (.+)(?: et (.+))? au groupe."
-
- match = re.match(regex, entree.content)
- if match is not None:
- return (
- match.group(1) if match.group(1) != "Vous" else entree.sender_name,
- *tuple(match.group(2).split(" et "))
- )
- else:
- return None
-
-
- invites = []
- for message in export.messages:
- noms = extraire_nom(message)
- if noms is None:
- continue
-
- invites.append((message, noms))
-
-
- print(f"Total invites: {len(invites)}")
-
- edges = []
- for invite in invites:
- for invitee in invite[1]:
- edges.append((invite[0].sender_name, invitee))
-
- vertices_as_names = list(set([edge[0] for edge in edges] + [edge[1] for edge in edges]))
-
- # Create a graph
- nb_vertices = len(vertices_as_names)
- vertices_as_indexes = {name: i for i, name in enumerate(vertices_as_names)}
- edges_as_indexes = [(vertices_as_indexes[edge[0]], vertices_as_indexes[edge[1]]) for edge in edges]
-
- g = ig.Graph(nb_vertices, edges_as_indexes)
- g.vs["name"] = vertices_as_names
-
- # Plot the graph
-
- visual_style = {
- "vertex_size": 2,
- "vertex_label": g.vs["name"],
- "vertex_label_size": 10,
- "vertex_color": "blue",
- "edge_width": 0.5,
- "edges_arrow_width": 20,
- "layout": g.layout("rt_circular"),
- "bbox": (2160, 1920),
- "margin": 100,
- "vertex_label_angle": math.pi * 1.5,
- "vertex_label_dist": 10,
- }
-
- ig.plot(g, "output/invite_graph.png", **visual_style)
|