Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ThomasLengeling/f814377c01093c8c9a575842d632b258 to your computer and use it in GitHub Desktop.
Save ThomasLengeling/f814377c01093c8c9a575842d632b258 to your computer and use it in GitHub Desktop.
# Load data into a Python dictionary
print("loading file: "+file_name+".json")
with open(file_name+"_dir.json", 'r') as file:
data = json.load(file)
unique_modes = set()
# Traverse all agents and their trips to gather modes
for agent in data.get("agents", []):
for trip in agent.get("trips", []):
mode_value = trip.get("mode")
if mode_value is not None:
unique_modes.add(mode_value)
# Convert the set to a list (optional) and print
unique_modes_list = list(unique_modes)
print("Unique modes:", unique_modes_list)
from collections import Counter
mode_counter = Counter()
# Collect the 'mode' values from every trip
for agent in data.get("agents", []):
for trip in agent.get("trips", []):
mode_value = trip.get("mode")
if mode_value:
mode_counter[mode_value] += 1
# Print the count of each distinct mode
for mode, count in mode_counter.items():
print(f"Mode: {mode}, Count: {count}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment