Spaces:
Sleeping
Sleeping
neuralworm
commited on
Commit
•
d5919f3
1
Parent(s):
bca33fd
initial commit
Browse files- psychohistory.py +2 -13
psychohistory.py
CHANGED
@@ -34,7 +34,7 @@ def generate_tree(current_x, current_y, depth, max_depth, max_nodes, x_range, G,
|
|
34 |
|
35 |
def build_graph_from_json(json_data, G):
|
36 |
"""Builds a graph from JSON data."""
|
37 |
-
data = json.loads(json_data)
|
38 |
|
39 |
def add_event(parent_id, event_data, depth):
|
40 |
node_id = len(G.nodes)
|
@@ -52,7 +52,7 @@ def build_graph_from_json(json_data, G):
|
|
52 |
for subevent in subevents:
|
53 |
add_event(node_id, subevent, depth + 1)
|
54 |
|
55 |
-
root_event = list(
|
56 |
root_id = len(G.nodes)
|
57 |
G.add_node(root_id, pos=(0, root_event['probability'] / 100.0, root_event['event_number']), label=root_event['name'])
|
58 |
add_event(None, root_event, 0)
|
@@ -188,14 +188,3 @@ def main(json_data):
|
|
188 |
draw_path_3d(G, shortest_path, 'shortest_duration_path.png', 'purple')
|
189 |
|
190 |
return 'global_tree.png' # Return the filename of the global tree
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
if __name__ == "__main__":
|
196 |
-
if len(sys.argv) < 2:
|
197 |
-
print("Usage: python script.py <mode> [input_file]")
|
198 |
-
else:
|
199 |
-
mode = sys.argv[1]
|
200 |
-
input_file = sys.argv[2] if len(sys.argv) > 2 else None
|
201 |
-
main(mode, input_file)
|
|
|
34 |
|
35 |
def build_graph_from_json(json_data, G):
|
36 |
"""Builds a graph from JSON data."""
|
37 |
+
# data = json.loads(json_data) # No need to load JSON here
|
38 |
|
39 |
def add_event(parent_id, event_data, depth):
|
40 |
node_id = len(G.nodes)
|
|
|
52 |
for subevent in subevents:
|
53 |
add_event(node_id, subevent, depth + 1)
|
54 |
|
55 |
+
root_event = list(json_data.get('events', {}).values())[0] # Use json_data directly
|
56 |
root_id = len(G.nodes)
|
57 |
G.add_node(root_id, pos=(0, root_event['probability'] / 100.0, root_event['event_number']), label=root_event['name'])
|
58 |
add_event(None, root_event, 0)
|
|
|
188 |
draw_path_3d(G, shortest_path, 'shortest_duration_path.png', 'purple')
|
189 |
|
190 |
return 'global_tree.png' # Return the filename of the global tree
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|