zele-utils/styles/help.py

296 lines
13 KiB
Python
Raw Permalink Normal View History

2024-09-10 17:40:50 -04:00
import sys
from rich.table import Table
from rich.console import Console
from rich.console import Group
from rich.padding import Padding
from rich.panel import Panel
2024-09-15 20:24:29 -04:00
from rich.syntax import Syntax
2024-09-10 17:40:50 -04:00
def population_help():
2024-09-15 20:24:29 -04:00
line1 = (
"This CLI tool processes [yellow bold]MATSim population XML files[/yellow bold] and prepares "
"the data for storage in either [green bold].csv[/green bold] files or a [blue bold]PostgreSQL[/blue bold] "
"database with [blue bold]PostGIS[/blue bold] integration."
)
line2 = (
"It extracts key data such as coordinates, converting them into a format ready for geospatial analysis.\n"
"Use the available [underline bold]options[/underline bold] to modify the behavior, such as "
"[underline bold]cleaning[/underline bold] the data by removing rows with missing values, or choosing to "
"either [underline bold]replace[/underline bold] or [underline bold]append[/underline bold] data in the target table."
)
line3 = "The expected format of the input MATSim population XML file is as follows:"
code = '''<population>
<!-- ====================================================================== -->
<person id="1">
<attributes>
<attribute name="age" class="java.lang.Integer">30</attribute>
<!-- Additional attributes -->
</attributes>
<plan selected="yes">
<activity type="home" x="322952.87" y="5084462.54" end_time="07:00:00" />
<leg mode="pt" dep_time="07:00:00" trav_time="00:41:00" />
<!-- Additional activities and legs -->
</plan>
</person>
<!-- ====================================================================== -->
<!-- Additional persons -->
</population>'''
syntax = Padding(Syntax(code, "xml", theme="native", line_numbers=True),(1,0))
line4 = "[red bold]NOTE:[/red bold] Make sure the dividers (line [bold]2[/bold] and [bold]14[/bold]) are present in the file; One divider before the first person and one divider after every person there after.\n\nThe resulting table structure includes columns such as the following:"
line5 = (
"[red bold]NOTE:[/red bold] Ensure PostgreSQL connection details are provided via a "
"[underline bold bright_cyan].env[/underline bold bright_cyan] file.\n"
"[red bold]NOTE:[/red bold] By default, if a [underline].log[/underline] file exists with the same name "
"in the same directory as the input file, it will use that to process the file."
)
table = Table(
"id", "lon", "lat", "geom", "time", "age", "sex", "person_id", "economic_sector", "household_id", "household_income"
)
table.add_row(
"1",
"45.89977111012078",
"-73.26605847316777",
"0101000020E61000005CED21B32BF3464013451E1A075152C0",
"07:00:00",
"30",
"1",
"1",
"0",
"1",
"4",
)
lines = f"{line1}\n{line2}\n\n{line3}"
group_content = Group(lines, syntax, line4, Padding(table, (1, 0)), line5)
panel = Padding(Panel(Padding(group_content, (1, 1)), title="About", title_align="left"),(1,0,0,0))
2024-09-10 17:40:50 -04:00
return panel
2024-09-15 20:24:29 -04:00
2024-09-10 17:40:50 -04:00
def network_help():
2024-09-15 20:24:29 -04:00
line1 = (
"This CLI tool processes [yellow bold]MATSim network XML files[/yellow bold] and prepares "
"the data for storage in either [green bold].csv[/green bold] files or a [blue bold]PostgreSQL[/blue bold] "
"database with [blue bold]PostGIS[/blue bold] integration."
)
line2 = (
"It extracts key data such as nodes and links, converting them into a format ready for geospatial analysis.\n"
"Use the available [underline bold]options[/underline bold] to modify the behavior, such as "
"[underline bold]cleaning[/underline bold] the data by removing rows with missing values, or choosing to "
"either [underline bold]replace[/underline bold] or [underline bold]append[/underline bold] data in the target table."
)
line3 = "The expected format of the input MATSim network XML file is as follows:"
code = '''<network>
<!-- ====================================================================== -->
<nodes>
<node id="10001628045" x="346519.0360492079" y="5053098.2183645" ></node>
</node>
<!-- ====================================================================== -->
<links capperiod="01:00:00" effectivecellsize="7.5" effectivelanewidth="3.75">
<link id="pt_VAU8D_pt_VAU1D" from="pt_VAU8D" to="pt_VAU1D" length="3596.5327216680666" freespeed="15.0" capacity="9999.0" permlanes="1.0" oneway="1" modes="artificial,rail" ></link>
</links>
<!-- ====================================================================== -->
</network>'''
syntax = Padding(Syntax(code, "xml", theme="native", line_numbers=True), (1, 0))
line4 = (
"[red bold]NOTE:[/red bold] Make sure the dividers (lines [bold]3[/bold], [bold]9[/bold], and [bold]15[/bold]) are present in the file; "
"One divider before the nodes section and one divider after the nodes and links sections.\n\n"
"The resulting table structures include columns such as the following:"
)
line5 = (
"[red bold]NOTE:[/red bold] Ensure PostgreSQL connection details are provided via a "
"[underline bold bright_cyan].env[/underline bold bright_cyan] file.\n"
"[red bold]NOTE:[/red bold] By default, if a [underline].log[/underline] file exists with the same name "
"in the same directory as the input file, it will use that to process the file."
)
# Table for 'links'
table_links = Table(
"id", "from", "to", "length", "freespeed", "capacity", "permlanes", "oneway", "modes"
)
table_links.add_row(
"1",
"1761723297",
"4407523214",
"506.2083628326979",
"13.88888888888889",
"600.0",
"1.0",
"1",
"car,car_passenger",
)
table_links.add_row(
"10",
"6545227882",
"300061322",
"567.0835225729793",
"19.444444444444443",
"1000.0",
"1.0",
"1",
"car,car_passenger",
)
# Table for 'links_attr'
table_links_attr = Table(
"id", "osm_way_highway", "osm_way_id", "osm_way_lanes", "osm_way_name", "sidewalk", "osm_way_oneway"
)
table_links_attr.add_row(
"1",
"unclassified",
"164553215",
"2",
"Montée Cadot",
"0.0",
"yes",
)
lines = f"{line1}\n{line2}\n\n{line3}"
group_content = Group(
lines,
syntax,
line4,
"[bold]\nlinks:[/bold]",
Padding(table_links, (1, 0)),
"[bold]links_attr:[/bold]",
Padding(table_links_attr, (1, 0)),
line5,
)
panel = Padding(Panel(Padding(group_content, (1, 1)), title="About", title_align="left"), (1, 0, 0, 0))
return panel
2024-09-10 17:40:50 -04:00
def metro_help():
2024-09-15 20:24:29 -04:00
line1 = (
"This CLI tool processes [yellow bold]metro station and line shapefiles[/yellow bold] "
"for a specified city and prepares the data for storage in either [green bold].csv[/green bold] "
"files or a [blue bold]PostgreSQL[/blue bold] database with [blue bold]PostGIS[/blue bold] integration."
)
line2 = (
"It extracts key data such as station locations and metro lines, converting them into a format "
"ready for geospatial analysis.\n"
"Use the available [underline bold]options[/underline bold] to modify the behavior, such as "
"[underline bold]cleaning[/underline bold] the data by removing rows with missing values, or choosing to "
"either [underline bold]replace[/underline bold] or [underline bold]append[/underline bold] data in the target table."
)
line3 = (
"For [bold]Montréal[/bold], To obtain the required shapefiles, please visit the following link:\n"
"[bright_cyan bold link=https://www.stm.info/en/about/developers?utm_campaign=menubas&utm_source=developpeurs]"
"https://www.stm.info/en/about/developers[/bright_cyan bold link]\n"
"Scroll down and find [bold]\"Download the Shapefile\"[/bold] button and download it.\n"
2024-09-16 08:38:38 -04:00
"Extract the downloaded archive to obtain the [bold].shp[/bold] and other files.\n"
"Use the relative path to [bold].shp[/bold] as your [bold]files[/bold] argument."
2024-09-15 20:24:29 -04:00
)
line4 = "The resulting table structures include columns such as the following:\n"
# Example table for 'metro-stations'
table_stations = Table(
2024-09-16 08:38:38 -04:00
"stop_code","stop_id","stop_name","stop_url","wheelchair","route_id","loc_type","shelter","service_id","coordinates"
2024-09-15 20:24:29 -04:00
)
table_stations.add_row(
2024-09-16 08:38:38 -04:00
"10118","43","Station Angrignon","http://www.stm.info/fr/infos/reseaux/metro/angrignon","1","1","0","NaN","24S","POINT (296733.6694496935 5034064.601946615)"
2024-09-15 20:24:29 -04:00
)
# Example table for 'metro-lines'
table_lines = Table(
2024-09-16 08:38:38 -04:00
"route_id","route_name","headsign","shape_id","ct","service_id","geometry"
2024-09-15 20:24:29 -04:00
)
table_lines.add_row(
2024-09-16 08:38:38 -04:00
"1","Ligne 1 - Verte","Station Angrignon","11072","0","24S","LINESTRING (302040.086988879 5050741.446280612...)"
2024-09-15 20:24:29 -04:00
)
line5 = (
"[red bold]NOTE:[/red bold] Ensure PostgreSQL connection details are provided via a "
"[underline bold bright_cyan].env[/underline bold bright_cyan] file.\n"
)
lines = f"{line1}\n{line2}\n\n{line3}\n\n{line4}"
group_content = Group(
lines,
"\n[bold]metro-stations:[/bold]",
Padding(table_stations, (1, 0)),
"[bold]metro-lines:[/bold]",
Padding(table_lines, (1, 0)),
line5,
)
panel = Padding(Panel(Padding(group_content, (1, 1)), title="About", title_align="left"), (1, 0, 0, 0))
return panel
2024-09-10 17:40:50 -04:00
def bus_help():
2024-09-15 20:24:29 -04:00
line1 = (
"This CLI tool processes [yellow bold]bus station and line shapefiles[/yellow bold] "
"for a specified city and prepares the data for storage in either [green bold].csv[/green bold] "
"files or a [blue bold]PostgreSQL[/blue bold] database with [blue bold]PostGIS[/blue bold] integration."
)
line2 = (
"It extracts key data such as station locations and bus lines, converting them into a format "
"ready for geospatial analysis.\n"
"Use the available [underline bold]options[/underline bold] to modify the behavior, such as "
"[underline bold]cleaning[/underline bold] the data by removing rows with missing values, or choosing to "
"either [underline bold]replace[/underline bold] or [underline bold]append[/underline bold] data in the target table."
)
line3 = (
"For [bold]Montréal[/bold], To obtain the required shapefiles, please visit the following link:\n"
"[bright_cyan bold link=https://www.stm.info/en/about/developers?utm_campaign=menubas&utm_source=developpeurs]"
"https://www.stm.info/en/about/developers[/bright_cyan bold link]\n"
"Scroll down and find [bold]\"Download the Shapefile\"[/bold] button and download it.\n"
2024-09-16 08:38:38 -04:00
"Extract the downloaded archive to obtain the [bold].shp[/bold] and related files.\n"
"Use the relative path to [bold].shp[/bold] as your [bold]files[/bold] argument."
2024-09-15 20:24:29 -04:00
)
line4 = "The resulting table structures include columns such as the following:\n"
# Example table for 'bus-stations'
table_stations = Table(
2024-09-16 08:38:38 -04:00
"stop_code","stop_id","stop_name","stop_url","wheelchair","route_id","loc_type","shelter","service_id","coordinates"
2024-09-15 20:24:29 -04:00
)
table_stations.add_row(
2024-09-16 08:38:38 -04:00
"10282","66-01","Station Cartier - Terminus Cartier (A)","NaN","1","NaN","2","NaN","24S","POINT (290599.75509576086 5046736.8438161155)"
2024-09-15 20:24:29 -04:00
)
# Example table for 'bus-lines'
table_lines = Table(
"route_id","route_name","headsign","shape_id","ct","service_id","geometry"
)
table_lines.add_row(
"767","La Ronde / Station Jean-Drapeau","Est","7670032","59","24S","LINESTRING (302272.2175821533 5041335.954894771, 302272.06122515834..."
)
line5 = (
"[red bold]NOTE:[/red bold] Ensure PostgreSQL connection details are provided via a "
"[underline bold bright_cyan].env[/underline bold bright_cyan] file.\n"
)
lines = f"{line1}\n{line2}\n\n{line3}\n\n{line4}"
group_content = Group(
lines,
"\n[bold]bus-stations:[/bold]",
Padding(table_stations, (1, 0)),
"[bold]bus-lines:[/bold]",
Padding(table_lines, (1, 0)),
line5,
)
panel = Padding(Panel(Padding(group_content, (1, 1)), title="About", title_align="left"), (1, 0, 0, 0))
return panel
2024-09-10 17:40:50 -04:00
def print_help():
console = Console()
if "--help" in sys.argv or "-h" in sys.argv:
if (sys.argv[1] == "population"):
console.print(population_help())
elif (sys.argv[1] == "network"):
2024-09-15 20:24:29 -04:00
console.print(network_help())
elif (sys.argv[1] == "metro"):
console.print(metro_help())
elif (sys.argv[1] == "bus"):
console.print(bus_help())