From b7e6d0ca698496c6fa10c6713d35614debcdfb3d Mon Sep 17 00:00:00 2001 From: Lewis Chambers Date: Wed, 19 Jun 2024 17:46:21 +0100 Subject: [PATCH] allowing database building script to read and output in alternate locations --- .../__assets__/data/build_database.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/iotswarm/__assets__/data/build_database.py b/src/iotswarm/__assets__/data/build_database.py index 1634584..96c5838 100644 --- a/src/iotswarm/__assets__/data/build_database.py +++ b/src/iotswarm/__assets__/data/build_database.py @@ -17,17 +17,24 @@ from iotswarm.queries import CosmosTable -def main(): - data_dir = Path(__file__).parent - csv_files = glob("*.csv", root_dir=data_dir) +def main( + csv_dir: str | Path = Path(__file__).parent, + database_output: str | Path = Path(Path(__file__).parent, "cosmos.db"), +): + """Reads exported cosmos DB files from CSV format. Assumes that the files + look like: LEVEL_1_SOILMET_30MIN_DATA_TABLE.csv + + Args: + csv_dir: Directory where the csv files are stored. + database_output: Output destination of the csv_data. + """ + csv_files = glob("*.csv", root_dir=csv_dir) tables = [CosmosTable[x.removesuffix("_DATA_TABLE.csv")] for x in csv_files] - database_file = Path(data_dir, "cosmos.db") - for table, file in zip(tables, csv_files): - file = Path(data_dir, file) - build_database_from_csv(file, database_file, table.value, sort_by="DATE_TIME") + file = Path(csv_dir, file) + build_database_from_csv(file, database_output, table.value, sort_by="DATE_TIME") if __name__ == "__main__":