From cff84639f8f7da9b59c76bdde7e87e062eaf8591 Mon Sep 17 00:00:00 2001 From: Roy Hyunjin Han Date: Mon, 24 Oct 2016 14:45:51 -0400 Subject: [PATCH] Use BasicArgumentParser --- cc.ini | 2 -- ...tricity_cost_by_technology_from_population.py | 16 ++-------------- estimate_grid_mv_line_budget_in_meters.py | 6 ++---- infrastructure_planning/macros.py | 14 +++++++++++--- missions/ProductionCountdown-20160711.md | 6 ++++++ setup.py | 2 +- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cc.ini b/cc.ini index f66fc06..c74b20f 100644 --- a/cc.ini +++ b/cc.ini @@ -273,7 +273,6 @@ command_template = python estimate_grid_mv_line_budget_in_meters.py --target_folder {target_folder} --financing_year {financing_year} --time_horizon_in_years {time_horizon_in_years} - --discount_rate_as_percent_of_cash_flow_per_year {discount_rate_as_percent_of_cash_flow_per_year} --demand_point_table_path {demand_point_table_path} --population_year {population_year} @@ -281,7 +280,6 @@ command_template = python estimate_grid_mv_line_budget_in_meters.py financing_year = 2016 time_horizon_in_years = 10 -discount_rate_as_percent_of_cash_flow_per_year = 10 demand_point_table_path = datasets/leona-selected-demand-points.csv population_year = 2016 diff --git a/estimate_electricity_cost_by_technology_from_population.py b/estimate_electricity_cost_by_technology_from_population.py index cb939d5..4623bd9 100644 --- a/estimate_electricity_cost_by_technology_from_population.py +++ b/estimate_electricity_cost_by_technology_from_population.py @@ -1,7 +1,5 @@ -from invisibleroads_macros.configuration import TerseArgumentParser -from invisibleroads_macros.disk import make_folder -from infrastructure_planning.macros import load_and_run +from infrastructure_planning.macros import BasicArgumentParser, load_and_run from infrastructure_planning.preprocessors import ( normalize_demand_point_table, normalize_connection_type_table, @@ -37,19 +35,9 @@ if __name__ == '__main__': - x = TerseArgumentParser() + x = BasicArgumentParser() add_arguments_for_estimate_population(x) - x.add_argument( - 'configuration_path', - metavar='CONFIGURATION_PATH', nargs='?') - x.add_argument( - '-w', '--source_folder', - metavar='FOLDER') - x.add_argument( - '-o', '--target_folder', - metavar='FOLDER', type=make_folder) - x.add_argument( '--selected_technologies_text_path', metavar='PATH') diff --git a/estimate_grid_mv_line_budget_in_meters.py b/estimate_grid_mv_line_budget_in_meters.py index 691b85f..4c4652e 100644 --- a/estimate_grid_mv_line_budget_in_meters.py +++ b/estimate_grid_mv_line_budget_in_meters.py @@ -1,6 +1,4 @@ -from invisibleroads_macros.configuration import TerseArgumentParser - -from infrastructure_planning.macros import load_and_run +from infrastructure_planning.macros import BasicArgumentParser, load_and_run from infrastructure_planning.preprocessors import ( normalize_demand_point_table) @@ -16,7 +14,7 @@ def add_arguments_for_estimate_population(x): if __name__ == '__main__': - x = TerseArgumentParser() + x = BasicArgumentParser() add_arguments_for_estimate_population(x) load_and_run([ normalize_demand_point_table, diff --git a/infrastructure_planning/macros.py b/infrastructure_planning/macros.py index 471a2fd..5bf3c88 100644 --- a/infrastructure_planning/macros.py +++ b/infrastructure_planning/macros.py @@ -3,6 +3,7 @@ import inspect import simplejson as json import shutil +from invisibleroads_macros.configuration import TerseArgumentParser from invisibleroads_macros.disk import make_enumerated_folder_for, make_folder from invisibleroads_macros.geometry import flip_geometry_coordinates from invisibleroads_macros.iterable import merge_dictionaries @@ -18,6 +19,16 @@ from .parsers import load_files +class BasicArgumentParser(TerseArgumentParser): + + def __init__(self, *args, **kw): + super(BasicArgumentParser, self).__init__(*args, **kw) + self.add_argument( + 'configuration_path', metavar='CONFIGURATION_PATH', nargs='?') + self.add_argument('-w', '--source_folder', metavar='FOLDER') + self.add_argument('-o', '--target_folder', metavar='FOLDER') + + class InfrastructureGraph(Graph): def cycle_nodes(self): @@ -226,9 +237,6 @@ def rename_keys(value_by_key, prefix='', suffix=''): def _get_argument_file_name(k, v): file_base = k - file_base = file_base.replace('_geotable_path', 's') - file_base = file_base.replace('_table_path', 's') - file_base = file_base.replace('_text_path', '') file_base = file_base.replace('_path', '') file_extension = splitext(v)[1] return file_base.replace('_', '-') + file_extension diff --git a/missions/ProductionCountdown-20160711.md b/missions/ProductionCountdown-20160711.md index f88f9e1..3deaee5 100644 --- a/missions/ProductionCountdown-20160711.md +++ b/missions/ProductionCountdown-20160711.md @@ -629,6 +629,12 @@ For some reason, I'm getting an error. Ok, it works now. +20161024-1400 - 20161024-1430: 30 minutes + + Add BasicArgumentParser + Check that everything still works + Check tests + # Tasks Generate points.csv diff --git a/setup.py b/setup.py index 15a37d7..2872d02 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ install_requires=[ 'python-dateutil', 'geopy', - 'invisibleroads-macros>=0.7.2', + 'invisibleroads-macros>=0.7.3', 'simplejson', ], tests_require=[