Spaces:
Sleeping
Sleeping
Commit
·
33d7cfe
1
Parent(s):
02b756e
initial commit
Browse files- psychohistory.py +4 -3
psychohistory.py
CHANGED
@@ -32,12 +32,14 @@ def generate_tree(current_x, current_y, depth, max_depth, max_nodes, x_range, G,
|
|
32 |
return node_count_per_depth
|
33 |
|
34 |
|
|
|
35 |
def build_graph_from_json(json_data, G):
|
36 |
-
"""Builds a graph from JSON data."""
|
37 |
|
38 |
def add_event(parent_id, event_data, depth):
|
39 |
node_id = len(G.nodes)
|
40 |
prob = event_data['probability'] / 100.0
|
|
|
41 |
pos = (depth, prob, event_data['event_number'])
|
42 |
label = event_data['name']
|
43 |
G.add_node(node_id, pos=pos, label=label)
|
@@ -53,11 +55,10 @@ def build_graph_from_json(json_data, G):
|
|
53 |
|
54 |
# Iterate through all top-level events
|
55 |
for event_data in json_data.get('events', {}).values():
|
56 |
-
root_id = len(G.nodes)
|
57 |
-
G.add_node(root_id, pos=(0, event_data['probability'] / 100.0, event_data['event_number']), label=event_data['name'])
|
58 |
add_event(None, event_data, 0) # Add each event as a root node
|
59 |
|
60 |
|
|
|
61 |
def find_paths(G):
|
62 |
"""Finds paths with highest/lowest probability and longest/shortest durations."""
|
63 |
best_path, worst_path = None, None
|
|
|
32 |
return node_count_per_depth
|
33 |
|
34 |
|
35 |
+
|
36 |
def build_graph_from_json(json_data, G):
|
37 |
+
"""Builds a graph from JSON data, handling subevents recursively."""
|
38 |
|
39 |
def add_event(parent_id, event_data, depth):
|
40 |
node_id = len(G.nodes)
|
41 |
prob = event_data['probability'] / 100.0
|
42 |
+
# Use event_number as the z-coordinate for better visualization
|
43 |
pos = (depth, prob, event_data['event_number'])
|
44 |
label = event_data['name']
|
45 |
G.add_node(node_id, pos=pos, label=label)
|
|
|
55 |
|
56 |
# Iterate through all top-level events
|
57 |
for event_data in json_data.get('events', {}).values():
|
|
|
|
|
58 |
add_event(None, event_data, 0) # Add each event as a root node
|
59 |
|
60 |
|
61 |
+
|
62 |
def find_paths(G):
|
63 |
"""Finds paths with highest/lowest probability and longest/shortest durations."""
|
64 |
best_path, worst_path = None, None
|