help about section added

This commit is contained in:
Kian 2024-09-15 20:24:29 -04:00
parent c0cbd31283
commit 6d479d8c07

View File

@ -4,30 +4,283 @@ from rich.console import Console
from rich.console import Group from rich.console import Group
from rich.padding import Padding from rich.padding import Padding
from rich.panel import Panel from rich.panel import Panel
from rich.syntax import Syntax
def population_help(): def population_help():
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] file or in [blue bold]PostgreSQL[/blue bold] database with [blue bold]PostGIS[/blue bold] integration." line1 = (
line2 = "It extracts key data such as coordinates, converting them into a format ready for geospatial.\nUse the available [underline bold]options[/underline bold] to modify the behavior, such as [underline bold]cleaning[/underline bold] the data with missing values, or choosing to either [underline bold]replace[/underline bold] or [underline bold]append[/underline bold] data in the target table." "This CLI tool processes [yellow bold]MATSim population XML files[/yellow bold] and prepares "
line3 = "The resulting table structure includes columns such as the following:" "the data for storage in either [green bold].csv[/green bold] files or a [blue bold]PostgreSQL[/blue bold] "
line4 = "[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] exist with the same name in the same directory of file, It will use that to prcoess the file" "database with [blue bold]PostGIS[/blue bold] integration."
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","4","1","1","0","1","4") line2 = (
table.add_row("2","45.89977111012078","-73.26605847316777","0101000020E61000005CED21B32BF3464013451E1A075152C0","08:00:00","4","2","2","0","1","4") "It extracts key data such as coordinates, converting them into a format ready for geospatial analysis.\n"
lines = f"{line1} \n{line2} \n{line3}" "Use the available [underline bold]options[/underline bold] to modify the behavior, such as "
panel = Padding(Panel(Padding(Group(lines,Padding(table, (1,0)),line4), (1,1)), title="About",title_align="left"), (1,0,0,0)) "[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))
return panel return panel
def network_help(): def network_help():
test = Padding("Hello network", (1,1)) line1 = (
return Panel(test, title="About",title_align="left") "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 snippet with syntax highlighting
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
def metro_help(): def metro_help():
test = Padding("Hello network", (1,1)) line1 = (
return Panel(test, title="About",title_align="left") "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"
"Extract the downloaded archive to obtain the two [bold].shp[/bold] files."
)
line4 = "The resulting table structures include columns such as the following:\n"
# Example table for 'metro-stations'
table_stations = Table(
"route_id", "route_name", "headsign", "shape_id", "ct", "service_id", "geometry"
)
table_stations.add_row(
"1", "Ligne 1 - Verte", "Station Angrignon", "11072", "0", "24S", "LINESTRING (302040.087 5050741.446, 301735.98 ...)"
)
# Example table for 'metro-lines'
table_lines = Table(
"id", "name", "geom", "stop_url", "wheelchair", "route_id", "loc_type", "shelter", "service_id"
)
table_lines.add_row(
"10118", "43", "Station Angrignon", "http://www.stm.info/fr/infos/reseaux/metro/ang...", "1", "1", "0", "NaN", "24S"
)
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
def bus_help(): def bus_help():
test = Padding("Hello network", (1,1)) line1 = (
return Panel(test, title="About",title_align="left") "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"
"Extract the downloaded archive to obtain the two [bold].shp[/bold] files."
)
line4 = "The resulting table structures include columns such as the following:\n"
# Example table for 'bus-stations'
table_stations = Table(
"stop_code","stop_id","stop_name","stop_url","wheelchair","route_id","loc_type","shelter","service_id","geometry"
)
table_stations.add_row(
"10282","66-01","Station Cartier - Terminus Cartier (A)","","1","","2","","24S","POINT (290599.75509576086 5046736.8438161155)"
)
# 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
def print_help(): def print_help():
console = Console() console = Console()
@ -36,3 +289,7 @@ def print_help():
console.print(population_help()) console.print(population_help())
elif (sys.argv[1] == "network"): elif (sys.argv[1] == "network"):
console.print(network_help()) console.print(network_help())
elif (sys.argv[1] == "metro"):
console.print(metro_help())
elif (sys.argv[1] == "bus"):
console.print(bus_help())