Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions conv/gtfs_convert_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
LanguageUseEnumeration,
Line,
PresentationStructure,
AllVehicleModesOfTransportEnumeration,
AllPublicTransportModesEnumeration,
PrivateCode,
OperationalContext,
ResourceFrame,
Expand Down Expand Up @@ -306,23 +306,23 @@ def getOperators(self, agency_sql: dict[str, str] = {'query': """select * from a
return results

@staticmethod
def gtfsRouteTypeToNeTEx(route_type: int | None) -> AllVehicleModesOfTransportEnumeration | None:
def gtfsRouteTypeToNeTEx(route_type: int | None) -> AllPublicTransportModesEnumeration | None:
if route_type == 0:
return AllVehicleModesOfTransportEnumeration.TRAM
return AllPublicTransportModesEnumeration.TRAM
elif route_type == 1:
return AllVehicleModesOfTransportEnumeration.METRO
return AllPublicTransportModesEnumeration.METRO
elif route_type == 2:
return AllVehicleModesOfTransportEnumeration.RAIL
return AllPublicTransportModesEnumeration.RAIL
elif route_type == 3:
return AllVehicleModesOfTransportEnumeration.BUS
return AllPublicTransportModesEnumeration.BUS
elif route_type == 4:
return AllVehicleModesOfTransportEnumeration.WATER
return AllPublicTransportModesEnumeration.WATER
elif route_type == 5 or route_type == 7:
return AllVehicleModesOfTransportEnumeration.FUNICULAR
return AllPublicTransportModesEnumeration.FUNICULAR
elif route_type == 6:
return AllVehicleModesOfTransportEnumeration.CABLEWAY
return AllPublicTransportModesEnumeration.CABLEWAY
elif route_type == 11:
return AllVehicleModesOfTransportEnumeration.TROLLEY_BUS
return AllPublicTransportModesEnumeration.TROLLEY_BUS

return None

Expand Down
18 changes: 9 additions & 9 deletions conv/trout_convert_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from xsdata.models.datatype import XmlTime, XmlDateTime, XmlDuration

from netex import Operator, MultilingualString, DataSource, DestinationDisplay, PresentationStructure, Line, \
PrivateCode, PrivateCodes, OperatorRef, AllVehicleModesOfTransportEnumeration, StopArea, \
PrivateCode, PrivateCodes, OperatorRef, AllPublicTransportModesEnumeration, StopArea, \
SimplePointVersionStructure, LocationStructure2, TopographicPlaceView, ScheduledStopPoint, PrivateCodeStructure, \
StopAreaRefsRelStructure, StopAreaRefStructure, PointRefsRelStructure, ScheduledStopPointRef, ServiceJourneyPattern, \
RouteView, LineRef, ValidBetween, ValidityConditionsRelStructure, ValidityCondition, ValidDuring, \
Expand Down Expand Up @@ -54,22 +54,22 @@ def get_operators(tt: TYearTimetable) -> Generator[Operator, None, None]:
for operator in tt.operators:
yield Operator(id=tt.stringPool[operator.id], version=str(tt.exportTimestamp), name=MultilingualString(value=tt.stringPool[operator.name]))

def get_transport_mode(mode) -> AllVehicleModesOfTransportEnumeration:
def get_transport_mode(mode) -> AllPublicTransportModesEnumeration:
match mode:
case 0:
return AllVehicleModesOfTransportEnumeration.UNKNOWN
return AllPublicTransportModesEnumeration.UNKNOWN
case 1:
return AllVehicleModesOfTransportEnumeration.TRAM
return AllPublicTransportModesEnumeration.TRAM
case 2:
return AllVehicleModesOfTransportEnumeration.METRO
return AllPublicTransportModesEnumeration.METRO
case 3:
return AllVehicleModesOfTransportEnumeration.RAIL
return AllPublicTransportModesEnumeration.RAIL
case 4:
return AllVehicleModesOfTransportEnumeration.BUS
return AllPublicTransportModesEnumeration.BUS
case 5:
return AllVehicleModesOfTransportEnumeration.WATER
return AllPublicTransportModesEnumeration.WATER

return AllVehicleModesOfTransportEnumeration.UNKNOWN
return AllPublicTransportModesEnumeration.UNKNOWN

def get_lines(tt: TYearTimetable) -> Generator[Line, None, None]:
for line in tt.lines:
Expand Down
29 changes: 17 additions & 12 deletions transformers/gtfsprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from netex import (
Line,
MultilingualString,
AllVehicleModesOfTransportEnumeration,
AllPublicTransportModesEnumeration,
InfoLinksRelStructure,
ScheduledStopPoint,
StopPlace,
Expand Down Expand Up @@ -136,8 +136,13 @@ def getOptionalMultilingualString(multilingual_string: MultilingualString | List
else:
multilingual_string = None

if multilingual_string is not None:
return multilingual_string.value
if multilingual_string is not None and multilingual_string.content:
# content is a list of TextType objects or strings
first_content = multilingual_string.content[0]
if hasattr(first_content, "value"):
return first_content.value
else:
return str(first_content)

return None

Expand All @@ -149,25 +154,25 @@ def getOptionalPrivateCode(private_code: PrivateCodeStructure | PrivateCode | Pu
return None

@staticmethod
def projectVehicleModeToRouteType(vehicle_mode: AllVehicleModesOfTransportEnumeration) -> int:
if vehicle_mode == AllVehicleModesOfTransportEnumeration.TRAM:
def projectVehicleModeToRouteType(vehicle_mode: AllPublicTransportModesEnumeration) -> int:
if vehicle_mode == AllPublicTransportModesEnumeration.TRAM:
return 0
elif vehicle_mode == AllVehicleModesOfTransportEnumeration.METRO:
elif vehicle_mode == AllPublicTransportModesEnumeration.METRO:
return 1
elif vehicle_mode == AllVehicleModesOfTransportEnumeration.RAIL:
elif vehicle_mode == AllPublicTransportModesEnumeration.RAIL:
return 2
elif vehicle_mode == AllVehicleModesOfTransportEnumeration.BUS:
elif vehicle_mode == AllPublicTransportModesEnumeration.BUS:
return 3
elif vehicle_mode in (AllVehicleModesOfTransportEnumeration.WATER, AllVehicleModesOfTransportEnumeration.FERRY):
elif vehicle_mode in (AllPublicTransportModesEnumeration.WATER, AllPublicTransportModesEnumeration.FERRY):
return 4

# We don't have a Cable Tram in NeTEx route_type = 5?

elif vehicle_mode == AllVehicleModesOfTransportEnumeration.CABLEWAY:
elif vehicle_mode == AllPublicTransportModesEnumeration.CABLEWAY:
return 6
elif vehicle_mode == AllVehicleModesOfTransportEnumeration.FUNICULAR:
elif vehicle_mode == AllPublicTransportModesEnumeration.FUNICULAR:
return 7
elif vehicle_mode == AllVehicleModesOfTransportEnumeration.TROLLEY_BUS:
elif vehicle_mode == AllPublicTransportModesEnumeration.TROLLEY_BUS:
return 11

# We don't have a Monorail in NeTEx route_type = 11?
Expand Down