Skip to content

Commit

Permalink
feat: find projects/scenarios by name instead of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
HagenFritz committed May 22, 2024
1 parent fd2db2e commit e79a73c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 38 deletions.
23 changes: 7 additions & 16 deletions snippets/explore_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,16 @@ def main():
# -----------------
# Find project by name
name_to_find = "212096 - 401 FIRST STREET (College Station)" # replace with your project name
projects = projects_api.get_projects()
project_id = projects[0]["id"] # default to first project
for project in projects:
if project["name"] == name_to_find:
print(f"Found Project: {project['id']} - {project['name']}")
project_id = project["id"]
break
project = projects_api.find_project_by_name(name=name_to_find)
project_id = project["id"]

# Find scenario by name
scenario_to_find = "Full Schedule" # replace with your scenario name
scenarios = scenarios_api.get_scenarios(project_id=project_id)
print(json.dumps(scenarios, indent=4))
scenario_id = scenarios[0]["id"] # default to first scenario
for scenario in scenarios:
if scenario["name"] == scenario_to_find:
print(f"Found Scenario:")
print(json.dumps(scenario, indent=4))
scenario_id = scenario["id"]
# don't break since there are might be multiple matching scenarios and we want to get the latest
matching_scenarios = scenarios_api.find_scenario_by_name(
project_id=project_id,
scenario_name=scenario_to_find
)
scenario_id = matching_scenarios[-1].get("id")

print("Get All Activities")
activities = activity_api.get_activities(
Expand Down
12 changes: 6 additions & 6 deletions snippets/explore_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def main():
# View Scenario Details
# ---------------------
# Get latest scenario for "Full Schedule"
scenario_id = scenarios[0]["id"] # default to the first scenario in the list
for scenario in scenarios:
if scenario["name"] == "Full Schedule":
scenario_id = scenario["id"]
print("Scenario Summay: 'Full Schedule'")
print(json.dumps(scenario, indent=4))
scenario_to_find = "Full Schedule" # replace with your scenario name
matching_scenarios = scenarios_api.find_scenario_by_name(
project_id=project_id,
scenario_name=scenario_to_find
)
scenario_id = matching_scenarios[-1].get("id")

print(f"Getting scenario details for Scenario {scenario_id}")
scenario_details = scenarios_api.get_scenario_details(
Expand Down
23 changes: 7 additions & 16 deletions snippets/plot_earned_days.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,16 @@ def main():
# ---------------------------------------------------------
# Find project by name
name_to_find = "212096 - 401 FIRST STREET (College Station)" # replace with your project name
projects = projects_api.get_projects()
project_id = projects[0]["id"] # default to first project
for project in projects:
if project["name"] == name_to_find:
print(f"Found Project: {project['id']} - {project['name']}")
project_id = project["id"]
break
project = projects_api.find_project_by_name(name=name_to_find)
project_id = project["id"]

# Find scenario by name
scenario_to_find = "Full Schedule" # replace with your scenario name
scenarios = scenarios_api.get_scenarios(project_id=project_id)
print(json.dumps(scenarios, indent=4))
scenario_id = scenarios[0]["id"] # default to first scenario
for scenario in scenarios:
if scenario["name"] == scenario_to_find:
print(f"Found Scenario:")
print(json.dumps(scenario, indent=4))
scenario_id = scenario["id"]
# don't break since there are might be multiple matching scenarios and we want to get the latest
matching_scenarios = scenarios_api.find_scenario_by_name(
project_id=project_id,
scenario_name=scenario_to_find
)
scenario_id = matching_scenarios[-1].get("id")

# Check data
complete_curve = scenarios_api.get_earned_schedule_curve(
Expand Down

0 comments on commit e79a73c

Please sign in to comment.