This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
forked from CUTR-at-USF/gtfsrdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
165 lines (121 loc) · 4.69 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# gtfsrdb.py: load gtfs-realtime data to a database
# recommended to have the (static) GTFS data for the agency you are connecting
# to already loaded.
# Copyright 2011 Matt Conway
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Authors:
# Matt Conway: main code
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Boolean, Float
from sqlalchemy.orm import relationship, backref
Base = declarative_base()
# Collapsed types:
# TripUpdate.trip
# TripUpdate.vehicle
# StopTimeUpdate.arrival
# StopTimeUpdate.departure
# Alert.active_period
# Position.latitude
# Position.longitude
# Position.bearing
# Position.speed
# VehicleDescriptor.id
# VehicleDescriptor.label
# VehicleDescriptor.license_plate
# The oid is called oid because several of the GTFSr types have string ids
# TODO: add sequences
class TripUpdate(Base):
__tablename__ = 'trip_updates'
oid = Column(Integer, primary_key=True)
# This replaces the TripDescriptor message
# TODO: figure out the relations
trip_id = Column(String(64))
route_id = Column(String(64))
trip_start_time = Column(String(8))
trip_start_date = Column(String(10))
# Put in the string value not the enum
# TODO: add a domain
schedule_relationship = Column(String(9))
# Collapsed VehicleDescriptor
vehicle_id = Column(String(10))
vehicle_label = Column(String(15))
vehicle_license_plate = Column(String(10))
# moved from the header, and reformatted as datetime
timestamp = Column(DateTime)
StopTimeUpdates = relationship('StopTimeUpdate', backref='TripUpdate')
class StopTimeUpdate(Base):
__tablename__ = 'stop_time_updates'
oid = Column(Integer, primary_key=True)
# TODO: Fill one from the other
stop_sequence = Column(Integer)
stop_id = Column(String(10))
# Collapsed StopTimeEvent
arrival_delay = Column(Integer)
arrival_time = Column(Integer)
arrival_uncertainty = Column(Integer)
# Collapsed StopTimeEvent
departure_delay = Column(Integer)
departure_time = Column(Integer)
departure_uncertainty = Column(Integer)
# TODO: Add domain
schedule_relationship = Column(String(9))
# Link it to the TripUpdate
trip_update_id = Column(Integer, ForeignKey('trip_updates.oid'))
# The .TripUpdate is done by the backref in TripUpdate
class Alert(Base):
__tablename__ = 'alerts'
oid = Column(Integer, primary_key=True)
# Collapsed TimeRange
start = Column(Integer)
end = Column(Integer)
# Add domain
cause = Column(String(20))
effect = Column(String(20))
url = Column(String(300))
header_text = Column(String(80))
description_text = Column(String(4000))
InformedEntities = relationship('EntitySelector', backref='Alert')
class EntitySelector(Base):
__tablename__ = 'entity_selectors'
oid = Column(Integer, primary_key=True)
agency_id = Column(String(15))
route_id = Column(String(64))
route_type = Column(Integer)
stop_id = Column(String(10))
# Collapsed TripDescriptor
trip_id = Column(String(64))
trip_route_id = Column(String(64))
trip_start_time = Column(String(8))
trip_start_date = Column(String(10))
alert_id = Column(Integer, ForeignKey('alerts.oid'))
class VehiclePosition(Base):
__tablename__ = 'vehicle_positions'
oid = Column(Integer, primary_key=True)
# This replaces the TripDescriptor message
# TODO: figure out the relations
trip_id = Column(String(64))
route_id = Column(String(64))
trip_start_time = Column(String(8))
trip_start_date = Column(String(10))
# Collapsed VehicleDescriptor
vehicle_id = Column(String(10))
vehicle_label = Column(String(15))
vehicle_license_plate = Column(String(10))
# Collapsed Position
position_latitude = Column(Float)
position_longitude = Column(Float)
position_bearing = Column(Float)
position_speed = Column(Float)
occupancy_status = Column(String(27))
# moved from the header, and reformatted as datetime
timestamp = Column(DateTime)
# So one can loop over all classes to clear them for a new load (-o option)
AllClasses = (TripUpdate, StopTimeUpdate, Alert, EntitySelector, VehiclePosition)