diff --git a/modules/data_processing/file_paths.py b/modules/data_processing/file_paths.py index 8e9d2b8..6c4d7a7 100644 --- a/modules/data_processing/file_paths.py +++ b/modules/data_processing/file_paths.py @@ -9,6 +9,8 @@ class file_paths: methods do. """ + config_file = Path("~/.NGIAB_data_preprocess").expanduser() + def __init__(self, wb_id: str): """ Initialize the file_paths class with a water body ID. @@ -21,17 +23,15 @@ def __init__(self, wb_id: str): @staticmethod def get_working_dir() -> Path: - # check for the .NGIAB_data_preprocessor file in ~ and read the working directory from it - # if it doesn't exist, return the current directory try: - with open(file_paths.dev_file(), "r") as f: - return Path(f.readline().strip()) + with open(file_paths.config_file, "r") as f: + return Path(f.readline().strip()).expanduser() except FileNotFoundError: return None @staticmethod - def set_working_dir(self, working_dir: Path) -> None: - with open(file_paths.dev_file(), "w") as f: + def set_working_dir(working_dir: Path) -> None: + with open(file_paths.config_file, "w") as f: f.write(str(working_dir)) @staticmethod diff --git a/modules/map_app/__main__.py b/modules/map_app/__main__.py index e466dea..1a66389 100644 --- a/modules/map_app/__main__.py +++ b/modules/map_app/__main__.py @@ -11,18 +11,27 @@ import requests import webbrowser + def download_file(url, save_path): response = requests.get(url, stream=True) - total_size = int(response.headers.get('content-length', 0)) + total_size = int(response.headers.get("content-length", 0)) bytes_downloaded = 0 chunk_size = 1048576 with open(save_path, "wb") as f: - for data in tqdm(response.iter_content(chunk_size=chunk_size), total=total_size/chunk_size, unit='MB', unit_scale=True): + for data in tqdm( + response.iter_content(chunk_size=chunk_size), + total=total_size / chunk_size, + unit="MB", + unit_scale=True, + ): bytes_downloaded += len(data) f.write(data) + hydrofabric_url = "https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v20.1/conus.gpkg" -model_attributes_url = "https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v20.1/model_attributes.parquet" +model_attributes_url = ( + "https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v20.1/model_attributes.parquet" +) if not file_paths.conus_hydrofabric().is_file(): @@ -44,7 +53,19 @@ def download_file(url, save_path): else: print("Exiting...") exit() - + +if not file_paths.config_file.is_file(): + # prompt the user to set the working directory + print( + "Output directory is not set. Would you like to set it now? Defaults to ~/ngiab_preprocess_output/ (y/N)" + ) + response = input() + if response.lower() == "y": + response = input("Enter the path to the working directory: ") + if response == "" or response.lower() == "n": + response = "~/ngiab_preprocess_output/" + file_paths.set_working_dir(response) + with open("app.log", "w") as f: f.write("") @@ -72,12 +93,13 @@ def download_file(url, save_path): console_handler.setFormatter(formatter) logging.getLogger("").addHandler(console_handler) + def open_browser(): webbrowser.open("http://localhost:5000") if __name__ == "__main__": - + if file_paths.dev_file().is_file(): with open("app.log", "a") as f: f.write("Running in debug mode\n") diff --git a/modules/map_app/static/css/main.css b/modules/map_app/static/css/main.css index 7def0e9..e4ef77a 100644 --- a/modules/map_app/static/css/main.css +++ b/modules/map_app/static/css/main.css @@ -83,6 +83,15 @@ button:hover { width: fit-content; } +#output-info { + margin: 20px; + padding: 15px; + background: #ebffaf; + border-left: 5px solid #fdf05c; + border-radius: 8px; + width: fit-content; +} + /* Form input styling */ input[type=datetime-local] { padding: 10px; diff --git a/modules/map_app/templates/index.html b/modules/map_app/templates/index.html index 251418e..89a3528 100644 --- a/modules/map_app/templates/index.html +++ b/modules/map_app/templates/index.html @@ -37,6 +37,9 @@