|
| 1 | +import requests |
| 2 | +import networkx as nx |
| 3 | +import matplotlib.pyplot as plt |
| 4 | + |
| 5 | +# === Fetch remote JSON === |
| 6 | +url = "https://raw.githubusercontent.com/SingularityNET-Archive/SingularityNET-Archive/refs/heads/main/Data/Snet-Ambassador-Program/Meeting-Summaries/2025/meeting-summaries-array.json" # Replace with your URL |
| 7 | +response = requests.get(url) |
| 8 | +if response.status_code != 200: |
| 9 | + raise Exception(f"Failed to fetch JSON. Status code: {response.status_code}") |
| 10 | +data = response.json() |
| 11 | + |
| 12 | +# Ensure list of workgroups |
| 13 | +if isinstance(data, dict): |
| 14 | + workgroups = [data] |
| 15 | +elif isinstance(data, list): |
| 16 | + workgroups = data |
| 17 | +else: |
| 18 | + raise Exception("Unexpected JSON structure") |
| 19 | + |
| 20 | +G = nx.DiGraph() |
| 21 | + |
| 22 | +# Helper for safe nested access |
| 23 | +def safe_get(d, keys, default=None): |
| 24 | + for key in keys: |
| 25 | + if isinstance(d, dict) and key in d: |
| 26 | + d = d[key] |
| 27 | + else: |
| 28 | + return default |
| 29 | + return d |
| 30 | + |
| 31 | +# === Loop through all workgroups === |
| 32 | +for wg_data in workgroups: |
| 33 | + workgroup = safe_get(wg_data, ["workgroup"], "Unknown Workgroup") |
| 34 | + meeting_id = safe_get(wg_data, ["workgroup_id"], f"MeetingID_{workgroup}") |
| 35 | + meeting_info = safe_get(wg_data, ["meetingInfo"], {}) |
| 36 | + |
| 37 | + G.add_node(workgroup, type="Workgroup") |
| 38 | + G.add_node(meeting_id, type="Meeting", |
| 39 | + date=meeting_info.get("date", ""), |
| 40 | + typeOfMeeting=meeting_info.get("typeOfMeeting", "")) |
| 41 | + G.add_edge(workgroup, meeting_id, relation="has_meeting") |
| 42 | + |
| 43 | + # Host & Documenter |
| 44 | + host = meeting_info.get("host", "Unknown Host") |
| 45 | + documenter = meeting_info.get("documenter", "Unknown Documenter") |
| 46 | + for person in [host, documenter]: |
| 47 | + G.add_node(person, type="Person") |
| 48 | + G.add_edge(meeting_id, person, relation="hosted_by" if person == host else "documented_by") |
| 49 | + |
| 50 | + # Attendees |
| 51 | + people_present = meeting_info.get("peoplePresent", "") |
| 52 | + for person in [p.strip() for p in people_present.split(",") if p.strip()]: |
| 53 | + G.add_node(person, type="Person") |
| 54 | + G.add_edge(meeting_id, person, relation="attended_by") |
| 55 | + |
| 56 | + # Working Docs |
| 57 | + for doc in meeting_info.get("workingDocs", []): |
| 58 | + title = doc.get("title", "Untitled Document") |
| 59 | + link = doc.get("link", "") |
| 60 | + G.add_node(title, type="Document", link=link) |
| 61 | + G.add_edge(meeting_id, title, relation="references_doc") |
| 62 | + |
| 63 | + # Agenda Items |
| 64 | + for agenda in wg_data.get("agendaItems", []): |
| 65 | + agenda_status = agenda.get("status", "unknown") |
| 66 | + agenda_id = f"Agenda_{agenda_status}_{meeting_id}" |
| 67 | + G.add_node(agenda_id, type="AgendaItem", status=agenda_status) |
| 68 | + G.add_edge(meeting_id, agenda_id, relation="has_agenda") |
| 69 | + |
| 70 | + # ActionItems |
| 71 | + for action in agenda.get("actionItems", []): |
| 72 | + action_text = action.get("text", "Unnamed Action") |
| 73 | + action_id = action_text[:40] + "..." |
| 74 | + G.add_node(action_id, type="ActionItem", dueDate=action.get("dueDate", "")) |
| 75 | + G.add_edge(agenda_id, action_id, relation="has_actionItem") |
| 76 | + assignee = action.get("assignee") |
| 77 | + if assignee: |
| 78 | + G.add_node(assignee, type="Person") |
| 79 | + G.add_edge(action_id, assignee, relation="assigned_to") |
| 80 | + |
| 81 | + # DecisionItems |
| 82 | + for decision in agenda.get("decisionItems", []): |
| 83 | + dec_text = decision.get("decision", "Unnamed Decision") |
| 84 | + dec_id = dec_text[:40] + "..." |
| 85 | + G.add_node(dec_id, type="DecisionItem", |
| 86 | + effect=decision.get("effect"), |
| 87 | + rationale=decision.get("rationale")) |
| 88 | + G.add_edge(agenda_id, dec_id, relation="has_decisionItem") |
| 89 | + |
| 90 | + # Tags & Emotions |
| 91 | + tags = safe_get(wg_data, ["tags"], {}) |
| 92 | + for topic in tags.get("topicsCovered", "").split(","): |
| 93 | + topic = topic.strip() |
| 94 | + if topic: |
| 95 | + G.add_node(topic, type="Tag") |
| 96 | + G.add_edge(meeting_id, topic, relation="tagged_with") |
| 97 | + |
| 98 | + for emotion in tags.get("emotions", "").split(","): |
| 99 | + emotion = emotion.strip() |
| 100 | + if emotion: |
| 101 | + G.add_node(emotion, type="Emotion") |
| 102 | + G.add_edge(meeting_id, emotion, relation="tagged_with") |
| 103 | + |
| 104 | +# === Visualize the graph === |
| 105 | +plt.figure(figsize=(20, 14)) |
| 106 | +pos = nx.spring_layout(G, seed=42) |
| 107 | +nx.draw(G, pos, with_labels=True, node_color="lightblue", node_size=2000, font_size=8, arrows=True) |
| 108 | +edge_labels = nx.get_edge_attributes(G, "relation") |
| 109 | +nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=7) |
| 110 | +plt.savefig("graph2.png") |
0 commit comments