Skip to content

Commit

Permalink
ENH: NAV-150 - Enable service feature of v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
munterfi committed Aug 23, 2024
1 parent d6fc06d commit 378c8e8
Show file tree
Hide file tree
Showing 6 changed files with 1,048 additions and 1,053 deletions.
1,980 changes: 990 additions & 990 deletions poetry.lock

Large diffs are not rendered by default.

62 changes: 28 additions & 34 deletions public_transit_viewer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import streamlit as st
from dotenv import dotenv_values
from public_transit_client.client import PublicTransitClient
from public_transit_client.model import ( # # QueryFeatures,; # TransportMode,
Connection, Coordinate, Stop, StopConnection, TimeType)
from public_transit_client.model import (
Connection, Coordinate, Stop, StopConnection, TimeType, RouterInfo, TransportMode, QueryConfig)

LOG = logging.getLogger(__name__)
INFINITY = int(2 ** 31 - 1)
Expand Down Expand Up @@ -37,11 +37,9 @@ def _convert_to_seconds(value: int | None) -> int | None:


@st.cache_data
def get_query_features() -> None: # QueryFeatures:
# TODO: Adjust client
# client = get_client()
# return client.getQueryFeatures()
return None
def get_router_info() -> RouterInfo: # QueryFeatures:
client = get_client()
return client.get_router_info()


@st.cache_data
Expand Down Expand Up @@ -69,25 +67,23 @@ def get_connections(
travel_date_time = datetime.combine(travel_date, travel_time)
client = get_client()

# TODO: Adjust client
# if travelModes is not None:
# travelModeEnums = [TransportMode[mode] for mode in travelModes]
# else:

travel_mode_enums = None
if travel_modes is not None:
travel_mode_enums = [TransportMode[mode] for mode in travel_modes]
else:
travel_mode_enums = None

return client.get_connections(
from_stop,
to_stop,
travel_date_time,
time_type=time_type,
max_walking_duration=_convert_to_seconds(max_walking_duration),
max_transfer_number=max_transfers,
max_travel_time=_convert_to_seconds(max_travel_time),
min_transfer_time=_convert_to_seconds(min_transfer_time),
# wheelchairAccessible=wheelchair_accessible,
# bikesAllowed=bikes_allowed,
# transportModes=travel_mode_enums,
query_config=QueryConfig(max_walking_duration=_convert_to_seconds(max_walking_duration),
max_transfer_number=max_transfers,
max_travel_time=_convert_to_seconds(max_travel_time),
min_transfer_time=_convert_to_seconds(min_transfer_time),
accessibility=wheelchair_accessible,
bikes=bikes_allowed,
travel_modes=travel_mode_enums)
)


Expand Down Expand Up @@ -119,24 +115,22 @@ def get_isolines(
client = get_client()
travel_date_time = datetime.combine(travel_date, travel_time)

# TODO: Adjust client
# if travel_modes is not None:
# travel_mode_enums = [TransportMode[mode] for mode in travel_modes]
# else:
travel_mode_enums = None
if travel_modes is not None:
travel_mode_enums = [TransportMode[mode] for mode in travel_modes]
else:
travel_mode_enums = None

stop_connections = client.get_isolines(
from_stop,
travel_date_time,
time_type=time_type,
max_walking_duration=_convert_to_seconds(max_walking_duration),
max_transfer_number=max_transfers,
max_travel_time=_convert_to_seconds(max_travel_time),
min_transfer_time=_convert_to_seconds(min_transfer_time),
# TODO: Adjust client
# wheelchairAccessible=wheelchair_accessible,
# bikesAllowed=bikes_allowed,
# transportModes=travel_mode_enums,
query_config=QueryConfig(max_walking_duration=_convert_to_seconds(max_walking_duration),
max_transfer_number=max_transfers,
max_travel_time=_convert_to_seconds(max_travel_time),
min_transfer_time=_convert_to_seconds(min_transfer_time),
accessibility=wheelchair_accessible,
bikes=bikes_allowed,
travel_modes=travel_mode_enums)
)

source_stop = client.get_stop(from_stop)
Expand Down Expand Up @@ -256,7 +250,7 @@ def _get_travel_mode_from_leg(stop_connection: StopConnection) -> str:
head_sign = trip.head_sign
description_pieces: list[str] = []
if route.transport_mode:
description_pieces.append(route.transport_mode)
description_pieces.append(route.transport_mode.name)
if route.short_name:
description_pieces.append(route.short_name)
elif route.name:
Expand Down
51 changes: 26 additions & 25 deletions public_transit_viewer/components/form_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import streamlit as st
from dateutil.relativedelta import relativedelta
from public_transit_client.model import TimeType # , TransportMode
from public_transit_client.model import TimeType, TransportMode

from public_transit_viewer.client import get_router_info


def _get_number_value(input_value: Any) -> int | None:
Expand Down Expand Up @@ -87,30 +89,29 @@ def query_config_expandable(
)
)

# TODO: Adjust client
# query_features = get_query_features()
#
# if query_features.supportsAccessibility or query_features.supportsBikes:
# column5, column6 = st.columns(2)
#
# if query_features.supportsAccessibility:
# wheelchair_accessible = column5.toggle(
# label="Wheelchair Accessible", value=wheelchair_accessible
# )
#
# if query_features.supportsBikes:
# bikes_allowed = column6.toggle(label="Bikes Allowed", value=bikes_allowed)
#
# if query_features.supportsTravelModes:
# if travel_modes is None:
# travel_modes = [m.value for m in TransportMode.__members__.values()]
# travel_modes = st.multiselect(
# label="Travel Modes",
# options=travel_modes,
# default=travel_modes,
# )
# else:
# travel_modes = None
router_info = get_router_info()

if router_info.supports_accessibility or router_info.supports_bikes:
column5, column6 = st.columns(2)

if router_info.supports_accessibility:
wheelchair_accessible = column5.toggle(
label="Wheelchair Accessible", value=wheelchair_accessible
)

if router_info.supports_bikes:
bikes_allowed = column6.toggle(label="Bikes Allowed", value=bikes_allowed)

if router_info.supports_travel_modes:
if travel_modes is None:
travel_modes = [m.value for m in TransportMode.__members__.values()]
travel_modes = st.multiselect(
label="Travel Modes",
options=travel_modes,
default=travel_modes,
)
else:
travel_modes = None

return (
max_transfers,
Expand Down
2 changes: 1 addition & 1 deletion public_transit_viewer/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
import subprocess
from pathlib import Path

SERVER_ADDRESS = "0.0.0.0"
SERVER_PORT = 8501
Expand Down
4 changes: 2 additions & 2 deletions public_transit_viewer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
search_function=get_stop_suggestions,
label="From",
key="from_stop_id",
rerun_on_update=True,
rerun_on_update=False,
)

with column2:
to_stop_id: str = st_searchbox(
search_function=get_stop_suggestions,
label="To",
key="to_stop_id",
rerun_on_update=True,
rerun_on_update=False,
)

travel_date, travel_time, time_type = time_form_row()
Expand Down
2 changes: 1 addition & 1 deletion public_transit_viewer/pages/isolines.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
search_function=get_stop_suggestions,
label="From",
key="from_stop_id",
rerun_on_update=True,
rerun_on_update=False,
)

travel_date, travel_time, time_type = time_form_row()
Expand Down

0 comments on commit 378c8e8

Please sign in to comment.