diff --git a/cove_ofds/process.py b/cove_ofds/process.py index 1ab69fa..9b67dac 100644 --- a/cove_ofds/process.py +++ b/cove_ofds/process.py @@ -292,15 +292,18 @@ def __init__(self, supplied_data): self.csvs_zip_filename = os.path.join( self.supplied_data.data_dir(), "flatten", "flattened.csvs.zip" ) + self.output_dir = os.path.join( + self.supplied_data.data_dir(), "flatten", "flattened" + ) def process(self, process_data: dict) -> dict: # TODO don't run if already done - output_dir = os.path.join(self.supplied_data.data_dir(), "flatten", "flattened") - os.makedirs(output_dir, exist_ok=True) + + os.makedirs(self.output_dir, exist_ok=True) flatten_kwargs = { - "output_name": output_dir, + "output_name": self.output_dir, "root_list_path": "networks", } @@ -308,12 +311,21 @@ def process(self, process_data: dict) -> dict: # Make Zip file of all CSV files with zipfile.ZipFile(self.csvs_zip_filename, "w") as out_zip: - for f in os.listdir(output_dir): - if os.path.isfile(os.path.join(output_dir, f)) and f.endswith(".csv"): - out_zip.write(os.path.join(output_dir, f), arcname=f) + for f in self._get_list_csv_filenames(): + out_zip.write(os.path.join(self.output_dir, f), arcname=f) return process_data + def _get_list_csv_filenames(self): + return sorted( + [ + f + for f in os.listdir(self.output_dir) + if os.path.isfile(os.path.join(self.output_dir, f)) + and f.endswith(".csv") + ] + ) + def get_context(self): context = {} # XLSX @@ -342,13 +354,24 @@ def get_context(self): context["can_download_ods"] = False # CSVs if os.path.exists(self.csvs_zip_filename): - context["can_download_csvs_zip"] = True + context["can_download_csvs"] = True context["download_csvs_zip_url"] = os.path.join( self.supplied_data.data_url(), "flatten", "flattened.csvs.zip" ) context["download_csvs_zip_size"] = os.stat(ods_filename).st_size + context["download_csv_individual_files"] = [ + { + "name": f, + "size": os.stat(os.path.join(self.output_dir, f)).st_size, + "url": os.path.join( + self.supplied_data.data_url(), "flatten", "flattened", f + ), + } + for f in self._get_list_csv_filenames() + ] + else: - context["can_download_csvs_zip"] = False + context["can_download_csvs"] = False # done! return context diff --git a/cove_ofds/templates/cove_ofds/explore.html b/cove_ofds/templates/cove_ofds/explore.html index 82d2206..3f9cf05 100644 --- a/cove_ofds/templates/cove_ofds/explore.html +++ b/cove_ofds/templates/cove_ofds/explore.html @@ -144,13 +144,23 @@
Compressed:
+Uncompressed:
+