瀏覽代碼

Updated script to use new module to plot paternity graph

DEV-Mael
Figg 4 月之前
父節點
當前提交
64056730f2
共有 3 個檔案被更改,包括 114 行新增24 行删除
  1. 36
    24
      million/scripts/script.py
  2. 77
    0
      poetry.lock
  3. 1
    0
      pyproject.toml

+ 36
- 24
million/scripts/script.py 查看文件

@@ -1,47 +1,59 @@
1
-import igraph as ig
2 1
 import math
3
-from bs4 import BeautifulSoup
2
+from million.model.member_movement import MovementType
3
+from million.parsing.facebook_parser import parse_facebook_exports_from_folder
4
+from million.processing.members_movements import compute_members_movements
5
+import igraph as ig
4 6
 
7
+facebook_data_path = './assets/facebook_exports/'
8
+facebook_exports = parse_facebook_exports_from_folder(facebook_data_path)
5 9
 
6
-with open('./data/html_content.html', 'r', encoding='utf-8') as fichier:
7
-    html_content = fichier.read()
10
+messages = facebook_exports.messages if facebook_exports else []
11
+movements = compute_members_movements(messages)
8 12
 
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
13
+aliases = {
14
+    '🥇Victor Mélou' : 'Victor Mélou',
15
+    '🥉 Augustin Lhotelier Ivey' : 'Augustin Lhotelier Ivey',
16
+    '🥈 Maël Delanoë' : 'Maël Delanoë',
17
+    'Lucas Roulin 👄' : 'Lucas Roulin'
18
+}
18 19
 
19
-soup = BeautifulSoup(html_content, 'html.parser')
20
-arr = soup.get_text(separator='\n', strip=True).split('\n')[:-2]
21 20
 
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]
21
+edges_as_names = []
25 22
 
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]
23
+seen_names = set()
24
+for move in movements:
25
+    if move.movementType == MovementType.IN and move.member not in seen_names:
26
+        seen_names.add(move.member)
27
+        edges_as_names.append((move.initiator, move.member))
28
+
29
+vertices_as_names = [b for _,b in edges_as_names]
30
+vertices_as_names.insert(0, '')
27 31
 nb_vertices = len(vertices_as_names)
28 32
 
33
+edges_as_indexes = []
34
+for a,b in edges_as_names:
35
+    if a in aliases: a = aliases[a]
36
+    a_idx = vertices_as_names.index(a)
37
+    b_idx = vertices_as_names.index(b)
38
+    if a_idx == b_idx: a_idx = 0
39
+    edges_as_indexes.append((a_idx, b_idx))
40
+
29 41
 g = ig.Graph(nb_vertices, edges_as_indexes)
30 42
 g.vs["name"] = vertices_as_names
31 43
 
32 44
 #print(g)
33 45
 
34
-outputfile = "./output/output_plot.png"
46
+outputfile = "./results/output_plot.png"
35 47
 
36 48
 visual_style = {}
37 49
 visual_style["vertex_size"] = 2
38 50
 visual_style["vertex_color"] = "blue"
39 51
 visual_style["vertex_label"] = g.vs["name"]
40
-visual_style["edge_width"] = 0.5
52
+visual_style["edge_width"] = 0.75
41 53
 visual_style["edge_arrow_width"] = 20
42
-visual_style["bbox"] = (2160, 1920)
54
+visual_style["bbox"] = (1920, 1920)
43 55
 visual_style["layout"] = "rt_circular"
44 56
 visual_style["margin"] = 100
45 57
 visual_style["vertex_label_angle"] = math.pi * 1.5
46
-visual_style["vertex_label_dist"] = 10
47
-ig.plot(g, outputfile, **visual_style)
58
+visual_style["vertex_label_dist"] = 5
59
+ig.plot(g, outputfile, **visual_style)

+ 77
- 0
poetry.lock 查看文件

@@ -0,0 +1,77 @@
1
+# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
2
+
3
+[[package]]
4
+name = "igraph"
5
+version = "0.11.6"
6
+description = "High performance graph data structures and algorithms"
7
+optional = false
8
+python-versions = ">=3.8"
9
+files = [
10
+    {file = "igraph-0.11.6-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:3f8b837181e8e87676be3873ce87cc92cc234efd58a2da2f6b4e050db150fcf4"},
11
+    {file = "igraph-0.11.6-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:245c4b7d7657849eff80416f5df4525c8fc44c74a981ee4d44f0ef2612c3bada"},
12
+    {file = "igraph-0.11.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bdb7be3d165073c0136295c0808e9edc57ba096cdb26e94086abb04561f7a292"},
13
+    {file = "igraph-0.11.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:58974e20df2986a1ae52a16e51ecb387cc0cbeb41c5c0ddff4d373a1bbf1d9c5"},
14
+    {file = "igraph-0.11.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7bef14de5e8ab70724a43808b1ed14aaa6fe1002f87e592289027a3827a8f44a"},
15
+    {file = "igraph-0.11.6-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:86c1e98de2e32d074df8510bf18abfa1f4c5fda4cb28a009985a5d746b0c0125"},
16
+    {file = "igraph-0.11.6-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:ebc5b3d702158abeb2e4d2414374586a2b932e1a07e48352b470600e1733d528"},
17
+    {file = "igraph-0.11.6-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:0efe6d0fb22d3987a800eb3857ed04df9eb4c5dddd0998be05232cb646f1c337"},
18
+    {file = "igraph-0.11.6-cp38-cp38-win32.whl", hash = "sha256:f4e68b27497b1c8ada2fb2bc35ef3fa7b0d72e84306b3d648d3de240fc618c32"},
19
+    {file = "igraph-0.11.6-cp38-cp38-win_amd64.whl", hash = "sha256:5665b33dfbfca5f54ce9b4fea6b97903bd0e99fb1b02acf5e57e600bdfa5a355"},
20
+    {file = "igraph-0.11.6-cp39-abi3-macosx_10_9_x86_64.whl", hash = "sha256:8aabef03d787b519d1075dfc0da4a1109fb113b941334883e3e7947ac30a459e"},
21
+    {file = "igraph-0.11.6-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:1f2cc4a518d99cdf6cae514f85e93e56852bc8c325b3abb96037d1d690b5975f"},
22
+    {file = "igraph-0.11.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c1e859238be52ab8ccc614d18f9362942bc88ce543afc12548f81ae99b10801d"},
23
+    {file = "igraph-0.11.6-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d61fbe5e85eb4ae9efe08c461f9bdeedb02a2b5739fbc223d324a71f40a28be2"},
24
+    {file = "igraph-0.11.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b6620ba39df29fd42151becf82309b54e57148233c9c3ef890eed62e25eed8a5"},
25
+    {file = "igraph-0.11.6-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:59666589bb3d07f310cda2c5106a8adeeb77c2ef27fecf1c6438b6091f4ca69d"},
26
+    {file = "igraph-0.11.6-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:8750b6d6caebf199cf7dc41c931f58e330153779707391e30f0a29f02666fb6e"},
27
+    {file = "igraph-0.11.6-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:967d6f2c30fe94317da15e459374d0fb8ca3e56020412f201ecd07dd5b5352f2"},
28
+    {file = "igraph-0.11.6-cp39-abi3-win32.whl", hash = "sha256:9744f95a67319eb6cb487ceabf30f5d7940de34bada51f0ba63adbd23e0f94ad"},
29
+    {file = "igraph-0.11.6-cp39-abi3-win_amd64.whl", hash = "sha256:b80e69eb11faa9c57330a9ffebdde5808966efe1c1f638d4d4827ea04df7aca8"},
30
+    {file = "igraph-0.11.6-pp310-pypy310_pp73-macosx_10_15_x86_64.whl", hash = "sha256:0329c16092e2ea7930d5f8368666ce7cb704900cc0ea04e4afe9ea1dd46e44af"},
31
+    {file = "igraph-0.11.6-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:21752313f449bd8688e5688e95ea7231cea5e9199c7162535029be0d9af848ac"},
32
+    {file = "igraph-0.11.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ea25e136c6c4161f53ff58868b23ff6c845193050ab0e502236d68e5d4174e32"},
33
+    {file = "igraph-0.11.6-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ac84433a03aef15e4b810010b08882b09854a3669450ccf31e392dbe295d2a66"},
34
+    {file = "igraph-0.11.6-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ac697a44e3573169fa2b28c9c37dcf9cf01e0f558b845dd7123860d4c7c8fb89"},
35
+    {file = "igraph-0.11.6-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:bdeae8bf35316eb1fb27bf667dcf5ecf5fcfb0b8f51831bc1b00c39c09c2d73b"},
36
+    {file = "igraph-0.11.6-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ad7e4aa442935de72554b96733bf6d7f09eac5cee97988a2562bdd3ca173cfa3"},
37
+    {file = "igraph-0.11.6-pp38-pypy38_pp73-macosx_11_0_arm64.whl", hash = "sha256:8d2818780358a686178866d01568b9df1f29678581734ad7a78882bab54df004"},
38
+    {file = "igraph-0.11.6-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2352276a20d979f1dea360af4202bb9f0c9a7d2c77f51815c0e625165e82013d"},
39
+    {file = "igraph-0.11.6-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:687fdab543b507d622fa3043f4227e5b26dc61dcf8ff8c0919fccddcc655f8b8"},
40
+    {file = "igraph-0.11.6-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:57f7f8214cd48c9a4d97f7346a4152ba2d4ac95fb5ee0df4ecf224fce4ba3d14"},
41
+    {file = "igraph-0.11.6-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:2b9cc69ede53f76ffae03b066609aa90184dd68ef15da8c104a97cebb9210838"},
42
+    {file = "igraph-0.11.6-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:591e1e447c3f0092daf7613a3eaedab83f9a0b0adbaf7702724c5117ded038a5"},
43
+    {file = "igraph-0.11.6-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:ca558eb331bc687bc33e5cd23717e22676e9412f8cda3a31d30c996a0487610d"},
44
+    {file = "igraph-0.11.6-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bf43c30e08debb087c9e3da69aa5cf1b6732968da34d55a614e3421b9a452146"},
45
+    {file = "igraph-0.11.6-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1d38e8d7db72b187d9d2211d0d06b3271fa9f32b04d49d789e2859b5480db0d0"},
46
+    {file = "igraph-0.11.6-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1a318b059051ff78144a1c3cb880f4d933c812bcdb3d833a49cd7168d0427672"},
47
+    {file = "igraph-0.11.6-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:2c54027add809b3c5b6685b8deca4ea4763fd000b9ea45c7ee46b7c9d61ff15e"},
48
+    {file = "igraph-0.11.6.tar.gz", hash = "sha256:837f233256c3319f2a35a6a80d94eafe47b43791ef4c6f9e9871061341ac8e28"},
49
+]
50
+
51
+[package.dependencies]
52
+texttable = ">=1.6.2"
53
+
54
+[package.extras]
55
+cairo = ["cairocffi (>=1.2.0)"]
56
+doc = ["Sphinx (>=7.0.0)", "pydoctor (>=23.4.0)", "sphinx-gallery (>=0.14.0)", "sphinx-rtd-theme (>=1.3.0)"]
57
+matplotlib = ["matplotlib (>=3.6.0)"]
58
+plotly = ["plotly (>=5.3.0)"]
59
+plotting = ["cairocffi (>=1.2.0)"]
60
+test = ["Pillow (>=9)", "cairocffi (>=1.2.0)", "matplotlib (>=3.6.0)", "networkx (>=2.5)", "numpy (>=1.19.0)", "pandas (>=1.1.0)", "plotly (>=5.3.0)", "pytest (>=7.0.1)", "pytest-timeout (>=2.1.0)", "scipy (>=1.5.0)"]
61
+test-musl = ["cairocffi (>=1.2.0)", "networkx (>=2.5)", "pytest (>=7.0.1)", "pytest-timeout (>=2.1.0)"]
62
+
63
+[[package]]
64
+name = "texttable"
65
+version = "1.7.0"
66
+description = "module to create simple ASCII tables"
67
+optional = false
68
+python-versions = "*"
69
+files = [
70
+    {file = "texttable-1.7.0-py2.py3-none-any.whl", hash = "sha256:72227d592c82b3d7f672731ae73e4d1f88cd8e2ef5b075a7a7f01a23a3743917"},
71
+    {file = "texttable-1.7.0.tar.gz", hash = "sha256:2d2068fb55115807d3ac77a4ca68fa48803e84ebb0ee2340f858107a36522638"},
72
+]
73
+
74
+[metadata]
75
+lock-version = "2.0"
76
+python-versions = "^3.11"
77
+content-hash = "99093655c8cdcdbc6f9c7e0c519a5e9683d11c85fdff4490869ca603894be43e"

+ 1
- 0
pyproject.toml 查看文件

@@ -6,6 +6,7 @@ packages = [{include = "million"}]
6 6
 
7 7
 [tool.poetry.dependencies]
8 8
 python = "^3.11"
9
+igraph = "^0.11.6"
9 10
 
10 11
 
11 12
 [build-system]

Loading…
取消
儲存