mirror of
https://github.com/knejadshamsi/zele-utils.git
synced 2024-12-22 23:55:53 -05:00
basics setup
This commit is contained in:
parent
bbc34c78c3
commit
87b0db002a
0
.example.env
Normal file
0
.example.env
Normal file
2
.gitignore
vendored
2
.gitignore
vendored
@ -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/*
|
25
README.md
25
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.
|
||||
|
11
functions/__Init__.py
Normal file
11
functions/__Init__.py
Normal file
@ -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'
|
||||
]
|
9
functions/bus.py
Normal file
9
functions/bus.py
Normal file
@ -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)
|
8
functions/metro.py
Normal file
8
functions/metro.py
Normal file
@ -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)
|
9
functions/network.py
Normal file
9
functions/network.py
Normal file
@ -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)
|
9
functions/population.py
Normal file
9
functions/population.py
Normal file
@ -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)
|
77
main.py
Normal file
77
main.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user