-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from vnopenroads/jamiecook/perf
Jamiecook/perf
- Loading branch information
Showing
7 changed files
with
114 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
|
||
from schematics import Model | ||
from schematics.types import FloatType, ModelType | ||
|
||
|
||
class ScenarioGrowthRates(Model): | ||
motorcycle = FloatType(required=True) | ||
small_car = FloatType(required=True) | ||
medium_car = FloatType(required=True) | ||
delivery = FloatType(required=True) | ||
four_wheel_drive = FloatType(required=True) | ||
light_truck = FloatType(required=True) | ||
medium_truck = FloatType(required=True) | ||
heavy_truck = FloatType(required=True) | ||
articulated_truck = FloatType(required=True) | ||
small_bus = FloatType(required=True) | ||
medium_bus = FloatType(required=True) | ||
large_bus = FloatType(required=True) | ||
|
||
|
||
class GrowthRates(Model): | ||
very_low = ModelType(ScenarioGrowthRates) | ||
low = ModelType(ScenarioGrowthRates) | ||
medium = ModelType(ScenarioGrowthRates) | ||
high = ModelType(ScenarioGrowthRates) | ||
very_high = ModelType(ScenarioGrowthRates) | ||
|
||
|
||
class Config(Model): | ||
growth_rates = ModelType(GrowthRates, required=True) | ||
# fleet_characteristics = ModelType(FleetCharacters, required=True) | ||
|
||
|
||
def load_config(model, file): | ||
return model(json.load(file)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import copy | ||
import os | ||
import re | ||
import time | ||
import unittest | ||
import glob | ||
import warnings | ||
from os.path import join, dirname | ||
|
||
from roads_cba_py.config import ScenarioGrowthRates, GrowthRates | ||
|
||
|
||
class TestConfig(unittest.TestCase): | ||
EXAMPLE_DATA_DIR = join(dirname(__file__), "example_data") | ||
|
||
def test_simple(self): | ||
json = { | ||
"motorcycle": 1.0, | ||
"small_car": 1.0, | ||
"medium_car": 1.0, | ||
"delivery": 1.0, | ||
"four_wheel_drive": 1.0, | ||
"light_truck": 1.0, | ||
"medium_truck": 1.0, | ||
"heavy_truck": 1.0, | ||
"articulated_truck": 1.0, | ||
"small_bus": 1.0, | ||
"medium_bus": 1.0, | ||
"large_bus": 2.0, | ||
} | ||
json2 = copy.deepcopy(json) | ||
json3 = copy.deepcopy(json) | ||
json4 = copy.deepcopy(json) | ||
json5 = copy.deepcopy(json) | ||
json5["large_bus"] = 3.0 | ||
|
||
scenario_rates = ScenarioGrowthRates(json) | ||
self.assertEqual(scenario_rates.medium_bus, 1.0) | ||
self.assertEqual(scenario_rates.large_bus, 2.0) | ||
|
||
rates = GrowthRates({"very_low": json, "low": json2, "medium": json3, "high": json4, "very_high": json5}) | ||
self.assertEqual(rates.very_low.large_bus, 2.0) | ||
self.assertEqual(rates.very_high.large_bus, 3.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters