Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ncdes/create_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ def main() -> None:
root_directory = root_directory
)

print("Saving output")
print("Joining ruleset ID to copy of output data for ruleset-specific outputs")
NCDes_with_geogs_and_rulesets = processing_steps.merge_mapped_data_with_ruleset_id(NCDes_with_geogs, root_directory)

print("Saving main output")
outputs.save_NCDes_with_geogs_to_csv(NCDes_with_geogs, root_directory)

print("Saving outputs split by ruleset")
outputs.save_NCDes_by_ruleset_to_csvs(NCDes_with_geogs_and_rulesets, root_directory)

print("Archiving input")
outputs.archive_input_as_csv(ncdes_raw, root_directory)

Expand All @@ -91,3 +97,4 @@ def main() -> None:

if __name__ == "__main__":
main()

13 changes: 12 additions & 1 deletion ncdes/output/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ def save_NCDes_with_geogs_to_csv(NCDes_with_geogs, root_directory):
)


def save_NCDes_by_ruleset_to_csvs(ncdes_with_geogs_and_rulesets, root_directory):
dates_table = get_date_for_name(ncdes_with_geogs_and_rulesets)
file_name = get_file_name(dates_table)
file_folder = get_file_folder(dates_table)
for RULESET_ID in ncdes_with_geogs_and_rulesets['Ruleset ID'].unique():
ncdes_data_ruleset = ncdes_with_geogs_and_rulesets.loc[ncdes_with_geogs_and_rulesets['Ruleset ID'] == RULESET_ID].drop(columns = "Ruleset ID")
ncdes_data_ruleset.to_csv(
f"{root_directory}Output\\" + file_folder + r"\\" + file_name +"_" + RULESET_ID + ".csv",
index=False,
)

def get_date_for_name(NCDes_with_geogs):
"""
Input:
Expand Down Expand Up @@ -65,7 +76,7 @@ def get_file_folder(dates_table):

def archive_input_as_csv(ncdes_raw, root_directory):
today = (datetime.today()).strftime("%Y_%m_%d")
ncdes_raw.to_csv(f"{root_directory}Input\\Archive\\NCDes_" + today + ".csv")
ncdes_raw.to_csv(f"{root_directory}Input\\Archive\\NCDes_" + today + ".csv", index=False)


def remove_files_from_input_folder(path):
Expand Down
11 changes: 10 additions & 1 deletion ncdes/processing/processing_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,13 @@ def get_indexes_to_suppress(

index_to_suppress.extend(list_subset_to_suppress)

return index_to_suppress
return index_to_suppress

def merge_mapped_data_with_ruleset_id(ncdes_with_geogs, root_directory):

# Load in measure dictionary
indicator_dictionary = data_load.load_indicator_and_measure_data_dictionaries(root_directory)[0]
# Join ruleset ID onto data
ncdes_with_geogs_and_rulesets = pd.merge(ncdes_with_geogs, indicator_dictionary, left_on = "IND_CODE", right_on = "Indicator ID", how = "left").drop(columns = ["Indicator Description","Payment or Management Information (MI)","Indicator ID"])

return ncdes_with_geogs_and_rulesets
Loading