Skip to content

Commit

Permalink
Implements scenario changes from #277
Browse files Browse the repository at this point in the history
Changes how scenarios works per description in #277 and updates relevant documentation about API changes.

Also:
- various efficiencies and consistency fixes
  • Loading branch information
e-lo committed Mar 7, 2023
1 parent 837586f commit f8379c3
Show file tree
Hide file tree
Showing 3 changed files with 512 additions and 564 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,19 @@ my_network.apply_project_card(...) # returns
my_network.write_roadway_network(...) # returns

## Scenario Building
my_scenario = scenario_from_network(roadway_network, transit_network)
my_scenario.add_projects(directory, keyword)
my_scenario.write_networks(directory, format)
my_scenario = Scenario.create_scenario(
base_scenario=my_base_scenario,
card_search_dir=project_card_directory,
tags = ["baseline-2050"]
)
my_scenario.apply_all_projects()
my_scenario.write("my_project/baseline", "baseline-2050")
my_scenario.summarize(outfile="scenario_summary_baseline.txt")

my_scenario.add_projects_from_files(list_of_build_project_card_files)
my_scenario.queued_projects
my_scenario.apply_all_projects()
my_scenario.write("my_project/build", "baseline")

```
## Attribution
Expand Down
75 changes: 20 additions & 55 deletions network_wrangler/projectcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import os
import yaml
import json
from typing import List

from typing import List, Collection
from pathlib import Path
from jsonschema import validate
from jsonschema.exceptions import ValidationError
from jsonschema.exceptions import SchemaError
Expand All @@ -21,6 +21,8 @@ class ProjectCard(object):
valid: Boolean indicating if data conforms to project card data schema
"""

FILE_TYPES = ["wr", "wrangler", "yml", "yaml"]

TRANSIT_CATEGORIES = ["Transit Service Property Change", "Add Transit"]

# categories that may affect transit, but only as a secondary
Expand Down Expand Up @@ -110,7 +112,7 @@ def read_wrangler_card(path_to_card: str) -> dict:
_yaml, _pycode = cardfile.read().split(delim)
WranglerLogger.debug("_yaml: {}\n_pycode: {}".format(_yaml, _pycode))

attribute_dictionary = yaml.safe_load(_yaml)
attribute_dictionary = yaml.safe_load(_yaml.lower())
attribute_dictionary["file"] = path_to_card
attribute_dictionary["pycode"] = _pycode.lstrip("\n")

Expand All @@ -129,7 +131,7 @@ def read_yml(path_to_card: str) -> dict:
WranglerLogger.debug("Reading YAML-Style Project Card")

with open(path_to_card, "r") as cardfile:
attribute_dictionary = yaml.safe_load(cardfile)
attribute_dictionary = yaml.safe_load(cardfile.read().lower())
attribute_dictionary["file"] = path_to_card

return attribute_dictionary
Expand Down Expand Up @@ -194,10 +196,23 @@ def validate_project_card_schema(
except yaml.YAMLError as exc:
WranglerLogger.error(exc.message)

def has_any_tags(self, tags: Collection[str]) -> bool:
"""Returns true if ProjectCard has at lest one tag in tags list.
args:
tags: list of tags to search for
"""
if tags and set(tags).isdisjoint(self.tags):
WranglerLogger.debug(
f"Project card tags: {self.tags} don't match search tags: {tags}"
)
return False
return True

@staticmethod
def build_link_selection_query(
selection: dict,
unique_model_link_identifiers: [],
unique_model_link_identifiers: list,
mode: List[str] = ["drive_access"],
ignore=[],
):
Expand Down Expand Up @@ -263,53 +278,3 @@ def build_link_selection_query(
sel_query = sel_query + ")"

return sel_query

def roadway_attribute_change(self, card: dict):
"""
Probably delete.
Reads a Roadway Attribute Change card.
args:
card: the project card stored in a dictionary
"""
WranglerLogger.info(card.get("Category"))

def new_roadway(self, card: dict):
"""
Probably delete.
Reads a New Roadway card.
args:
card: the project card stored in a dictionary
"""
WranglerLogger.info(card.get("Category"))

def transit_attribute_change(self, card: dict):
"""
Probably delete.
Reads a Transit Service Attribute Change card.
args:
card: the project card stored in a dictionary
"""
WranglerLogger.info(card.get("Category"))

def new_transit_right_of_way(self, card: dict):
"""
Probably delete.
Reads a New Transit Dedicated Right of Way card.
args:
card: the project card stored in a dictionary
"""
WranglerLogger.info(card.get("Category"))

def parallel_managed_lanes(self, card: dict):
"""
Probably delete.
Reads a Parallel Managed lanes card.
args:
card: the project card stored in a dictionary
"""
WranglerLogger.info(card.get("Category"))
Loading

0 comments on commit f8379c3

Please sign in to comment.