diff --git a/.example.env b/.example.env new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 68bc17f..a78c4c9 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +data/* \ No newline at end of file diff --git a/README.md b/README.md index 36093db..d1cb25c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ -# zele-utils - A CLI to preprocess and DB push for Zele project. +# Zele-Utils +A CLI tool for preprocessing and pushing data to the database for the Zele project. + +## Installation +1. Install Anaconda or Miniconda. +2. Create the environment and install required packages: + ```bash + conda env create -f environment.yml + ``` +3. Activate the environment: + ```bash + conda activate zele-utils + ``` +4. Set up your `.env` file using `.example.env` as a template. + +## Usage +Place the file you want to process in `/data/` and push to the database in the appropriate directory. Run the corresponding command. For a list of available commands and options, use: + ```bash + python main.py --help + ``` +## Features +1. Processes MATSim's `Population.xml` and `Network.xml` files. +2. Processes data from the Overpass API and `map.osm` file. diff --git a/functions/__Init__.py b/functions/__Init__.py new file mode 100644 index 0000000..5e947c4 --- /dev/null +++ b/functions/__Init__.py @@ -0,0 +1,11 @@ +from .population import process_population, push_population,population_write +from .network import process_network, push_network, network_write +from .metro import process_metro, push_metro, metro_write +from .bus import process_bus, push_bus, bus_write + +__all__ = [ + 'process_population', 'push_population', 'population_write', + 'process_network', 'push_network', 'network_write', + 'process_metro', 'push_metro', 'metro_write', + 'process_bus', 'push_bus', 'bus_write' + ] diff --git a/functions/bus.py b/functions/bus.py new file mode 100644 index 0000000..e93620f --- /dev/null +++ b/functions/bus.py @@ -0,0 +1,9 @@ + +def process_bus(data, cleandata): + print(data, cleandata) + +def push_bus(data,mode): + print(data,mode) + +def bus_write(data): + print(data) \ No newline at end of file diff --git a/functions/metro.py b/functions/metro.py new file mode 100644 index 0000000..c5f4f98 --- /dev/null +++ b/functions/metro.py @@ -0,0 +1,8 @@ +def process_metro(data, cleandata): + print(data, cleandata) + +def push_metro(data,mode): + print(data,mode) + +def metro_write(data): + print(data) \ No newline at end of file diff --git a/functions/network.py b/functions/network.py new file mode 100644 index 0000000..097cdbd --- /dev/null +++ b/functions/network.py @@ -0,0 +1,9 @@ + +def process_network(data, cleandata): + print(data, cleandata) + +def push_network(data,mode): + print(data,mode) + +def network_write(data): + print(data) \ No newline at end of file diff --git a/functions/population.py b/functions/population.py new file mode 100644 index 0000000..13aecb4 --- /dev/null +++ b/functions/population.py @@ -0,0 +1,9 @@ + +def process_population(data, cleandata): + print(data, cleandata) + +def push_population(data,mode): + print(data,mode) + +def population_write(data): + print(data) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..84d4db6 --- /dev/null +++ b/main.py @@ -0,0 +1,77 @@ +import typer, geopandas, requests, shapely +from bs4 import BeautifulSoup +from zipfile import ZipFile + +from typing_extensions import Annotated +from typing import Optional +from pathlib import Path +from enum import Enum + +from functions import process_population, push_population, population_write +from functions import process_network, push_network, network_write +from functions import process_metro, push_metro, metro_write +from functions import process_bus, push_bus, bus_write + +app = typer.Typer() + +class City(str, Enum): + mtl = "mtl" + +class DBMode(str, Enum): + drop = "drop" + amend = "amend" + +class RTMode(str, Enum): + online = "online" + offline = "offline" + +@app.command() +def population( + file: Annotated[Path, typer.Argument(help="Relative path to the file.", show_default=False)], + cleandata: bool = typer.Option(False, "--cleandata", "-cd", help="Clean the data if this flag is used."), + push: bool = typer.Option(False, "--push", "-p", help="Push the data into Database."), + mode: Optional[DBMode] = typer.Option(None, help="Specify either 'amend' or 'drop' when pushing data", show_default=False), + ): + if not file.exists(): + print("File did does not exist!") + raise typer.Exit() + data = process_population(file,cleandata) + if push: + push_population(data, mode) + else: + population_write(data) + +@app.command() +def network( + file: Annotated[Path, typer.Argument(help="Relative path to the file.", show_default=False)], + cleandata: bool = typer.Option(False, "--cleandata", "-cd", help="Clean the data if this flag is used."), + push: bool = typer.Option(False, "--push", "-p", help="Push the data into Database."), + mode: Optional[DBMode] = typer.Option(None, help="Specify either 'amend' or 'drop' when pushing data", show_default=False), + ): + if not file.exists(): + print("File did does not exist!") + raise typer.Exit() + data = process_network(file,cleandata) + if push: + push_network(data, mode) + else: + network_write(data) + +@app.command() +def metro( + city: Annotated[City, typer.Argument(..., help="Choose a city", show_default=False)], + mode: Annotated[RTMode, typer.Argument(..., help="Choose a city", show_default=False)], + address: Annotated[str, typer.Argument(..., help="enter a relative path or URL", show_default=False)], + ): + print(f"Hello {city}") + +@app.command() +def bus( + city: Annotated[City, typer.Argument(..., help="Choose a city", show_default=False)], + mode: Annotated[RTMode, typer.Argument(..., help="Choose a city", show_default=False)], + address: Annotated[str, typer.Argument(..., help="enter a relative path or URL", show_default=False)], +): + print(f"Hello {city}") + +if __name__ == "__main__": + app() \ No newline at end of file