Skip to content

Commit

Permalink
Sort keys in arguments.json
Browse files Browse the repository at this point in the history
  • Loading branch information
invisibleroads committed Oct 28, 2016
1 parent 748774a commit 05694ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions estimate_electricity_cost_by_technology_from_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from infrastructure_planning.electricity.report import (
save_total_lines, save_total_map, save_total_points,
save_total_report_by_location, save_total_summary_by_grid_mv_line,
save_total_summary_by_location, save_total_summary_by_technology)
save_total_summary_by_location, save_total_summary_by_technology,
FULL_KEYS)

from estimate_grid_mv_line_budget_in_meters import (
add_arguments_for_estimate_population)
Expand Down Expand Up @@ -296,4 +297,4 @@
save_total_map,
# save_total_graph,
wash_total_folder,
], x)
], x.parse_args().__dict__, FULL_KEYS)
20 changes: 12 additions & 8 deletions infrastructure_planning/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from invisibleroads_macros.disk import (
make_enumerated_folder_for, make_folder, remove_safely)
from invisibleroads_macros.geometry import flip_geometry_coordinates
from invisibleroads_macros.iterable import merge_dictionaries
from invisibleroads_macros.iterable import merge_dictionaries, sort_dictionary
from invisibleroads_macros.math import divide_safely
from invisibleroads_macros.table import normalize_column_name
from networkx import Graph, write_gpickle
Expand Down Expand Up @@ -46,10 +46,10 @@ def cycle_edges(self):
yield node1_id, node2_id, edge_d


def load_and_run(normalization_functions, main_functions, argument_parser):
args = argument_parser.parse_args()
g = load_arguments(args.__dict__)
save_arguments(g, __file__)
def load_and_run(
normalization_functions, main_functions, arguments, keys):
g = load_arguments(arguments)
save_arguments(g, __file__, keys)
try:
g = load_files(g)
g = normalize_arguments(normalization_functions, g)
Expand All @@ -75,7 +75,7 @@ def load_arguments(value_by_key):
return g


def save_arguments(g, script_path):
def save_arguments(g, script_path, keys):
d = g.copy()
target_folder = d.pop('target_folder')
if not target_folder:
Expand All @@ -89,10 +89,14 @@ def save_arguments(g, script_path):
shutil.copy(v, join(arguments_folder, file_name))
# Make the reference point to the local copy
d[k] = file_name
# Sort arguments using keys
d = sort_dictionary(d, keys)
# Save global arguments as JSON
json.dump(d, open(join(arguments_folder, 'arguments.json'), 'w'))
target_file = open(join(arguments_folder, 'arguments.json'), 'w')
json.dump(d, target_file, indent=4, separators=(',', ': '))
# Save global arguments as CSV
csv_writer = csv.writer(open(join(arguments_folder, 'arguments.csv'), 'w'))
target_file = open(join(arguments_folder, 'arguments.csv'), 'w')
csv_writer = csv.writer(target_file)
for x in d.items():
csv_writer.writerow(x)

Expand Down

0 comments on commit 05694ec

Please sign in to comment.