359 lines
16 KiB
Python
359 lines
16 KiB
Python
"""
|
|
Constants useful to quickly look up often used references to models and their fields.
|
|
"""
|
|
|
|
# This file is part of transport-accessibility.
|
|
# Copyright (C) 2024 Janek Kiljanski, Johannes Randerath
|
|
#
|
|
# transport-accessibility is free software: you can redistribute it and/or modify it under the terms of the
|
|
# GNU General Public License as published by the Free Software Foundation, either version 3
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# transport-accessibility is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
# See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along with transport-accessibility.
|
|
# If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import pt_map.models
|
|
import datetime
|
|
|
|
time_delta = int(datetime.datetime(2024,1,1).timestamp())
|
|
|
|
class_names = [
|
|
{
|
|
"Agency": pt_map.models.Agency,
|
|
"Stop": pt_map.models.Stop,
|
|
"Route": pt_map.models.Route,
|
|
"Trip": pt_map.models.Trip,
|
|
"StopTime": pt_map.models.StopTime,
|
|
"Calendar": pt_map.models.Calendar,
|
|
"CalendarDate": pt_map.models.CalendarDate,
|
|
"FareAttribute": pt_map.models.FareAttribute,
|
|
"FareRule": pt_map.models.FareRule,
|
|
"Timeframe": pt_map.models.Timeframe,
|
|
"FareMedium": pt_map.models.FareMedium,
|
|
"FareProduct": pt_map.models.FareProduct,
|
|
"FareLegRule": pt_map.models.FareLegRule,
|
|
"FareTransferRule": pt_map.models.FareTransferRule,
|
|
"Area": pt_map.models.Area,
|
|
"StopArea": pt_map.models.StopArea,
|
|
"Network": pt_map.models.Network,
|
|
"RouteNetwork": pt_map.models.RouteNetwork,
|
|
"Shape": pt_map.models.Shape,
|
|
"Frequency": pt_map.models.Frequency,
|
|
"Transfer": pt_map.models.Transfer,
|
|
"Pathway": pt_map.models.Pathway,
|
|
"Level": pt_map.models.Level,
|
|
"LocationGroup": pt_map.models.LocationGroup,
|
|
"LocationGroupStop": pt_map.models.LocationGroupStop,
|
|
"Location": pt_map.models.Location,
|
|
"BookingRule": pt_map.models.BookingRule,
|
|
"Translation": pt_map.models.Translation,
|
|
"FeedInfo": pt_map.models.FeedInfo,
|
|
"Attribution": pt_map.models.Attribution,
|
|
},
|
|
{
|
|
"agencies": pt_map.models.Agency,
|
|
"stops": pt_map.models.Stop,
|
|
"routes": pt_map.models.Route,
|
|
"trips": pt_map.models.Trip,
|
|
"stop_times": pt_map.models.StopTime,
|
|
"calendars": pt_map.models.Calendar,
|
|
"calendar_dates": pt_map.models.CalendarDate,
|
|
"fare_attributes": pt_map.models.FareAttribute,
|
|
"fare_rules": pt_map.models.FareRule,
|
|
"timeframes": pt_map.models.Timeframe,
|
|
"fare_mediums": pt_map.models.FareMedium,
|
|
"fare_products": pt_map.models.FareProduct,
|
|
"fare_leg_rules": pt_map.models.FareLegRule,
|
|
"fare_transfer_rules": pt_map.models.FareTransferRule,
|
|
"areas": pt_map.models.Area,
|
|
"stop_areas": pt_map.models.StopArea,
|
|
"networks": pt_map.models.Network,
|
|
"route_networks": pt_map.models.RouteNetwork,
|
|
"shapes": pt_map.models.Shape,
|
|
"frequencies": pt_map.models.Frequency,
|
|
"transfers": pt_map.models.Transfer,
|
|
"pathways": pt_map.models.Pathway,
|
|
"levels": pt_map.models.Level,
|
|
"location_groups": pt_map.models.LocationGroup,
|
|
"location_group_stops": pt_map.models.LocationGroupStop,
|
|
"locations": pt_map.models.Location,
|
|
"booking_rules": pt_map.models.BookingRule,
|
|
"translations": pt_map.models.Translation,
|
|
"feed_info": pt_map.models.FeedInfo,
|
|
"attributions": pt_map.models.Attribution,
|
|
},
|
|
{
|
|
pt_map.models.Agency: "Agency",
|
|
pt_map.models.Stop: "Stop",
|
|
pt_map.models.Route: "Route",
|
|
pt_map.models.Trip: "Trip",
|
|
pt_map.models.StopTime: "StopTime",
|
|
pt_map.models.Calendar: "Calendar",
|
|
pt_map.models.CalendarDate: "CalendarDate",
|
|
pt_map.models.FareAttribute: "FareAttribute",
|
|
pt_map.models.FareRule: "FareRule",
|
|
pt_map.models.Timeframe: "Timeframe",
|
|
pt_map.models.FareMedium: "FareMedium",
|
|
pt_map.models.FareProduct: "FareProduct",
|
|
pt_map.models.FareLegRule: "FareLegRule",
|
|
pt_map.models.FareTransferRule: "FareTransferRule",
|
|
pt_map.models.Area: "Area",
|
|
pt_map.models.StopArea: "StopArea",
|
|
pt_map.models.Network: "Network",
|
|
pt_map.models.RouteNetwork: "RouteNetwork",
|
|
pt_map.models.Shape: "Shape",
|
|
pt_map.models.Frequency: "Frequency",
|
|
pt_map.models.Transfer: "Transfer",
|
|
pt_map.models.Pathway: "Pathway",
|
|
pt_map.models.Level: "Level",
|
|
pt_map.models.LocationGroup: "LocationGroup",
|
|
pt_map.models.LocationGroupStop: "LocationGroupStop",
|
|
pt_map.models.Location: "Location",
|
|
pt_map.models.BookingRule: "BookingRule",
|
|
pt_map.models.Translation: "Translation",
|
|
pt_map.models.FeedInfo: "FeedInfo",
|
|
pt_map.models.Attribution: "Attribution",
|
|
},
|
|
{
|
|
pt_map.models.Agency: "agencies",
|
|
pt_map.models.Stop: "stops",
|
|
pt_map.models.Route: "routes",
|
|
pt_map.models.Trip: "trips",
|
|
pt_map.models.StopTime: "stop_times",
|
|
pt_map.models.Calendar: "calendars",
|
|
pt_map.models.CalendarDate: "calendar_dates",
|
|
pt_map.models.FareAttribute: "fare_attributes",
|
|
pt_map.models.FareRule: "fare_rules",
|
|
pt_map.models.Timeframe: "timeframes",
|
|
pt_map.models.FareMedium: "fare_mediums",
|
|
pt_map.models.FareProduct: "fare_products",
|
|
pt_map.models.FareLegRule: "fare_leg_rules",
|
|
pt_map.models.FareTransferRule: "fare_transfer_rules",
|
|
pt_map.models.Area: "areas",
|
|
pt_map.models.StopArea: "stop_areas",
|
|
pt_map.models.Network: "networks",
|
|
pt_map.models.RouteNetwork: "route_networks",
|
|
pt_map.models.Shape: "shapes",
|
|
pt_map.models.Frequency: "frequencies",
|
|
pt_map.models.Transfer: "transfers",
|
|
pt_map.models.Pathway: "pathways",
|
|
pt_map.models.Level: "levels",
|
|
pt_map.models.LocationGroup: "location_groups",
|
|
pt_map.models.LocationGroupStop: "location_group_stops",
|
|
pt_map.models.Location: "locations",
|
|
pt_map.models.BookingRule: "booking_rules",
|
|
pt_map.models.Translation: "translations",
|
|
pt_map.models.FeedInfo: "feed_info",
|
|
pt_map.models.Attribution: "attributions",
|
|
},
|
|
]
|
|
|
|
|
|
|
|
file_names = {
|
|
pt_map.models.Agency: "agency.txt",
|
|
pt_map.models.Stop: "stops.txt",
|
|
pt_map.models.Route: "routes.txt",
|
|
pt_map.models.Trip: "trips.txt",
|
|
pt_map.models.StopTime: "stop_times.txt",
|
|
pt_map.models.Calendar: "calendar.txt",
|
|
pt_map.models.CalendarDate: "calendar_dates.txt",
|
|
pt_map.models.FareAttribute: "fare_attributes.txt",
|
|
pt_map.models.FareRule: "fare_rules.txt",
|
|
pt_map.models.Timeframe: "timeframes.txt",
|
|
pt_map.models.FareMedium: "fare_media.txt",
|
|
pt_map.models.FareProduct: "fare_products.txt",
|
|
pt_map.models.FareLegRule: "fare_leg_rules.txt",
|
|
pt_map.models.FareTransferRule: "fare_transfer_rules.txt",
|
|
pt_map.models.Area: "areas.txt",
|
|
pt_map.models.StopArea: "stop_areas.txt",
|
|
pt_map.models.Network: "networks.txt",
|
|
pt_map.models.RouteNetwork: "route_networks.txt",
|
|
pt_map.models.Shape: "shapes.txt",
|
|
pt_map.models.Frequency: "frequencies.txt",
|
|
pt_map.models.Transfer: "transfers.txt",
|
|
pt_map.models.Pathway: "pathways.txt",
|
|
pt_map.models.Level: "levels.txt",
|
|
pt_map.models.LocationGroup: "location_groups.txt",
|
|
pt_map.models.LocationGroupStop: "location_group_stops.txt",
|
|
pt_map.models.Location: "locations.geojson",
|
|
pt_map.models.BookingRule: "booking_rules.txt",
|
|
pt_map.models.Translation: "translations.txt",
|
|
pt_map.models.FeedInfo: "feed_info.txt",
|
|
pt_map.models.Attribution: "attributions.txt",
|
|
}
|
|
|
|
reversed_file_mapping = {
|
|
"Agency": "agency",
|
|
"Stop": "stops",
|
|
"Route": "routes",
|
|
"Trip": "trips",
|
|
"StopTime": "stop_times",
|
|
"Calendar": "calendar",
|
|
"CalendarDate": "calendar_dates",
|
|
"FareAttribute": "fare_attributes",
|
|
"FareRule": "fare_rules",
|
|
"Timeframe": "timeframes",
|
|
"FareMedium": "fare_media",
|
|
"FareProduct": "fare_products",
|
|
"FareLegRule": "fare_leg_rules",
|
|
"FareTransferRule": "fare_transfer_rules",
|
|
"Area": "areas",
|
|
"StopArea": "stop_areas",
|
|
"Network": "networks",
|
|
"RouteNetwork": "route_networks",
|
|
"Shape": "shapes",
|
|
"Frequency": "frequencies",
|
|
"Transfer": "transfers",
|
|
"Pathway": "pathways",
|
|
"Level": "levels",
|
|
"LocationGroup": "location_groups",
|
|
"LocationGroupStop": "location_group_stops",
|
|
"Location": "locations_geojson",
|
|
"BookingRule": "booking_rules",
|
|
"Translation": "translations",
|
|
"FeedInfo": "feed_info",
|
|
"Attribution": "attributions"
|
|
}
|
|
|
|
|
|
case_swap = {'Agency': 'agency', 'Stop': 'stops', 'Route': 'routes', 'Trip': 'trips', 'StopTime': 'stop_times', 'Calendar': 'calendar', 'CalendarDate': 'calendar_dates', 'FareAttribute': 'fare_attributes', 'FareRule': 'fare_rules', 'Timeframe': 'timeframes', 'FareMedium': 'fare_media', 'FareProduct': 'fare_products', 'FareLegRule': 'fare_leg_rules', 'FareTransferRule': 'fare_transfer_rules', 'Area': 'areas', 'StopArea': 'stop_areas', 'Network': 'networks', 'RouteNetwork': 'route_networks', 'Shape': 'shapes', 'Frequency': 'frequencies', 'Transfer': 'transfers', 'Pathway': 'pathways', 'Level': 'levels', 'LocationGroup': 'location_groups', 'LocationGroupStop': 'location_group_stops', 'Location': 'locations_geojson', 'BookingRule': 'booking_rules', 'Translation': 'translations', 'FeedInfo': 'feed_info', 'Attribution': 'attributions'}
|
|
|
|
|
|
primary_keys = {
|
|
pt_map.models.FeedInfo: "feed_id",
|
|
pt_map.models.Agency: "agency_id",
|
|
pt_map.models.Level: "level_id",
|
|
pt_map.models.Stop: "stop_id",
|
|
pt_map.models.Route: "route_id",
|
|
pt_map.models.Shape: "shape_pk",
|
|
pt_map.models.Calendar: "service_id",
|
|
pt_map.models.CalendarDate: "calendar_date_id",
|
|
pt_map.models.Trip: "trip_id",
|
|
pt_map.models.LocationGroup: "location_group_id",
|
|
pt_map.models.Location: "location_id",
|
|
pt_map.models.StopTime: "stop_time_id",
|
|
pt_map.models.FareAttribute: "fare_id",
|
|
pt_map.models.FareRule: "fare_rule_id",
|
|
pt_map.models.Frequency: "frequency_id",
|
|
pt_map.models.Transfer: "transfer_id",
|
|
pt_map.models.Pathway: "pathway_id",
|
|
pt_map.models.BookingRule: "booking_rule_id",
|
|
pt_map.models.Translation: "translation_id",
|
|
pt_map.models.Attribution: "attribution_id",
|
|
pt_map.models.LocationGroupStop: "location_group_stop_id",
|
|
pt_map.models.Network: "network_id",
|
|
pt_map.models.RouteNetwork: "route_network_id",
|
|
pt_map.models.Area: "area_id",
|
|
pt_map.models.StopArea: "stop_area_id",
|
|
pt_map.models.FareMedium: "fare_media_id",
|
|
pt_map.models.FareProduct: "fare_product_id",
|
|
pt_map.models.Timeframe: "timeframe_group_id",
|
|
pt_map.models.FareLegRule: "fare_leg_rule_id",
|
|
pt_map.models.FareTransferRule: "fare_transfer_rule_id",
|
|
}
|
|
|
|
|
|
classes_by_primary_keys = {
|
|
'feed_id': pt_map.models.FeedInfo,
|
|
'agency_id': pt_map.models.Agency,
|
|
'level_id': pt_map.models.Level,
|
|
'stop_id': pt_map.models.Stop,
|
|
'route_id': pt_map.models.Route,
|
|
'shape_pk': pt_map.models.Shape,
|
|
'service_id': pt_map.models.Calendar,
|
|
'calendar_date_id': pt_map.models.CalendarDate,
|
|
'trip_id': pt_map.models.Trip,
|
|
'location_group_id': pt_map.models.LocationGroup,
|
|
'location_id': pt_map.models.Location,
|
|
'stop_time_id': pt_map.models.StopTime,
|
|
'fare_id': pt_map.models.FareAttribute,
|
|
'fare_rule_id': pt_map.models.FareRule,
|
|
'frequency_id': pt_map.models.Frequency,
|
|
'transfer_id': pt_map.models.Transfer,
|
|
'pathway_id': pt_map.models.Pathway,
|
|
'booking_rule_id': pt_map.models.BookingRule,
|
|
'translation_id': pt_map.models.Translation,
|
|
'attribution_id': pt_map.models.Attribution,
|
|
'location_group_stop_id': pt_map.models.LocationGroupStop,
|
|
'network_id': pt_map.models.Network,
|
|
'route_network_id': pt_map.models.RouteNetwork,
|
|
'area_id': pt_map.models.Area,
|
|
'stop_area_id': pt_map.models.StopArea,
|
|
'fare_media_id': pt_map.models.FareMedium,
|
|
'fare_product_id': pt_map.models.FareProduct,
|
|
'timeframe_group_id': pt_map.models.Timeframe,
|
|
'fare_leg_rule_id': pt_map.models.FareLegRule,
|
|
'fare_transfer_rule_id': pt_map.models.FareTransferRule,
|
|
}
|
|
|
|
foreign_keys = [
|
|
(pt_map.models.FeedInfo, []),
|
|
(pt_map.models.Agency, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Level, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Stop, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Stop, 'parent_station'), (pt_map.models.Level, 'level_id'), ]),
|
|
(pt_map.models.Route, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Agency, 'agency_id'), ]),
|
|
(pt_map.models.Shape, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Calendar, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.CalendarDate, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Trip, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Route, 'route_id'), (pt_map.models.Shape, 'shape_id'), ]),
|
|
(pt_map.models.LocationGroup, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Location, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.StopTime, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Trip, 'trip_id'), (pt_map.models.Stop, 'stop_id'), (pt_map.models.LocationGroup, 'location_group_id'), (pt_map.models.Location, 'location_id'), ]),
|
|
(pt_map.models.FareAttribute, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Agency, 'agency_id'), ]),
|
|
(pt_map.models.FareRule, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.FareAttribute, 'fare_id'), (pt_map.models.Route, 'route_id'), ]),
|
|
(pt_map.models.Frequency, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Trip, 'trip_id'), ]),
|
|
(pt_map.models.Transfer, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Stop, 'from_stop_id'), (pt_map.models.Stop, 'to_stop_id'), (pt_map.models.Route, 'from_route_id'), (pt_map.models.Route, 'to_route_id'), (pt_map.models.Trip, 'from_trip_id'), (pt_map.models.Trip, 'to_trip_id'), ]),
|
|
(pt_map.models.Pathway, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Stop, 'from_stop_id'), (pt_map.models.Stop, 'to_stop_id'), ]),
|
|
(pt_map.models.BookingRule, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Trip, 'trip_id'), ]),
|
|
(pt_map.models.Translation, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Attribution, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Agency, 'agency_id'), (pt_map.models.Route, 'route_id'), (pt_map.models.Trip, 'trip_id'), ]),
|
|
(pt_map.models.LocationGroupStop, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.LocationGroup, 'location_group_id'), (pt_map.models.Stop, 'stop_id'), ]),
|
|
(pt_map.models.Network, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.RouteNetwork, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Network, 'network_id'), (pt_map.models.Route, 'route_id'), ]),
|
|
(pt_map.models.Area, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.StopArea, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Area, 'area_id'), (pt_map.models.Stop, 'stop_id'), ]),
|
|
(pt_map.models.FareMedium, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.FareProduct, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.Timeframe, [(pt_map.models.FeedInfo, 'feed_info_id'),]),
|
|
(pt_map.models.FareLegRule, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.Network, 'network_id'), (pt_map.models.Area, 'from_area_id'), (pt_map.models.Area, 'to_area_id'), (pt_map.models.Timeframe, 'from_timeframe_group_id'), (pt_map.models.Timeframe, 'to_timeframe_group_id'), (pt_map.models.FareProduct, 'fare_product_id'), ]),
|
|
(pt_map.models.FareTransferRule, [(pt_map.models.FeedInfo, 'feed_info_id'),(pt_map.models.FareProduct, 'fare_product_id'), ]),
|
|
]
|
|
|
|
mtm = {
|
|
'shape_id': pt_map.models.Shape,
|
|
'from_timeframe_group_id': pt_map.models.Timeframe,
|
|
'to_timeframe_group_id': pt_map.models.Timeframe,
|
|
}
|
|
|
|
fks = {
|
|
'feed_info_id_id': pt_map.models.FeedInfo,
|
|
'parent_station': pt_map.models.Stop,
|
|
'level_id': pt_map.models.Level,
|
|
'agency_id': pt_map.models.Agency,
|
|
'route_id': pt_map.models.Route,
|
|
'trip_id': pt_map.models.Trip,
|
|
'stop_id': pt_map.models.Stop,
|
|
'location_group_id': pt_map.models.LocationGroup,
|
|
'location_id': pt_map.models.Location,
|
|
'fare_id': pt_map.models.FareAttribute,
|
|
'from_stop_id': pt_map.models.Stop,
|
|
'to_stop_id': pt_map.models.Stop,
|
|
'from_route_id': pt_map.models.Route,
|
|
'to_route_id': pt_map.models.Route,
|
|
'from_trip_id': pt_map.models.Trip,
|
|
'to_trip_id': pt_map.models.Trip,
|
|
'network_id': pt_map.models.Network,
|
|
'area_id': pt_map.models.Area,
|
|
'from_area_id': pt_map.models.Area,
|
|
'to_area_id': pt_map.models.Area,
|
|
'fare_product_id': pt_map.models.FareProduct,
|
|
}
|
|
|
|
|
|
fk_dict = {fk[0]: fk[1] for fk in foreign_keys}
|