neuralworm commited on
Commit
88b1bc3
1 Parent(s): ddfd741

better graph

Browse files
Files changed (1) hide show
  1. psychohistory.py +4 -3
psychohistory.py CHANGED
@@ -27,9 +27,9 @@ def build_graph_from_json(json_data, G):
27
  for subevent in subevents:
28
  add_event(node_id, subevent, depth + 1)
29
 
30
- # Start from the root event (assuming there's only one top-level event)
31
- root_event = list(json_data.get('events', {}).values())[0]
32
- add_event(None, root_event, 0)
33
 
34
 
35
  def find_paths(G):
@@ -83,6 +83,7 @@ def find_paths(G):
83
 
84
  return best_path, best_mean_prob, worst_path, worst_mean_prob, longest_duration_path, shortest_duration_path
85
 
 
86
  def draw_path_3d(G, path, filename='path_plot_3d.png', highlight_color='blue'):
87
  """Draws only the specific path in 3D using networkx and matplotlib
88
  and saves the figure to a file."""
 
27
  for subevent in subevents:
28
  add_event(node_id, subevent, depth + 1)
29
 
30
+ # Iterate through all top-level events (this is the corrected part)
31
+ for event_data in json_data.get('events', {}).values():
32
+ add_event(None, event_data, 0) # Add each event as a root node
33
 
34
 
35
  def find_paths(G):
 
83
 
84
  return best_path, best_mean_prob, worst_path, worst_mean_prob, longest_duration_path, shortest_duration_path
85
 
86
+
87
  def draw_path_3d(G, path, filename='path_plot_3d.png', highlight_color='blue'):
88
  """Draws only the specific path in 3D using networkx and matplotlib
89
  and saves the figure to a file."""