opnvoyager-sqlmodel 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: opnvoyager-sqlmodel
3
+ Version: 0.1.0
4
+ Summary: A package that contains the SQLModels for the ÖPNVoyager tool
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: fptf-pydantic>=0.1.0
8
+ Requires-Dist: lptf-pydantic>=0.1.0
9
+ Requires-Dist: pycountry>=26.2.16
10
+ Requires-Dist: pydantic-client>=2.0.6
11
+ Requires-Dist: pydantic-extra-types>=2.11.0
12
+ Requires-Dist: sqlmodel>=0.0.31
13
+ Requires-Dist: traewelling-api>=0.1.1
14
+ Requires-Dist: traewelling-pydantic>=0.2.0
15
+
16
+ # ÖPNVoyager-SQLModel
17
+
18
+ A package that contains the SQLModels for the ÖPNVoyager tool.
@@ -0,0 +1,3 @@
1
+ # ÖPNVoyager-SQLModel
2
+
3
+ A package that contains the SQLModels for the ÖPNVoyager tool.
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "opnvoyager-sqlmodel"
3
+ version = "0.1.0"
4
+ description = "A package that contains the SQLModels for the ÖPNVoyager tool"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ dependencies = [
8
+ "fptf-pydantic>=0.1.0",
9
+ "lptf-pydantic>=0.1.0",
10
+ "pycountry>=26.2.16",
11
+ "pydantic-client>=2.0.6",
12
+ "pydantic-extra-types>=2.11.0",
13
+ "sqlmodel>=0.0.31",
14
+ "traewelling-api>=0.1.1",
15
+ "traewelling-pydantic>=0.2.0",
16
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ from .models import (
2
+ Location,
3
+ LocationIdentifierEnum,
4
+ LocationIdentifier,
5
+ Stay,
6
+ Station,
7
+ StationIdentifier,
8
+ Operator,
9
+ TransportProduct,
10
+ Transport,
11
+ TransportIdentifier,
12
+ Stop,
13
+ Tag,
14
+ Event,
15
+ Individual,
16
+ StatusPurposeEnum,
17
+ Status
18
+ )
@@ -0,0 +1,310 @@
1
+ import enum
2
+ from datetime import datetime
3
+ from typing import Optional
4
+ from uuid import UUID, uuid4, uuid5
5
+
6
+ import fptf_pydantic.models as fptf
7
+ import lptf_pydantic as lptf
8
+ import sqlmodel as sql
9
+ import traewelling_pydantic.enums as trwl_enums
10
+ import traewelling_pydantic.models as trwl
11
+ from pydantic_extra_types.coordinate import Latitude, Longitude
12
+
13
+ UUID_NS_TRWL_STATION = UUID("1d9f9301-7efd-4950-9bcc-6409c64d29f6")
14
+ UUID_NS_TRWL_TRANSPORT = UUID("151d0a94-19cd-42a5-bfef-2705f8b1343c")
15
+ UUID_NS_TRWL_OPERATOR = UUID("822b5971-bb51-4de4-8222-828be7b007b8")
16
+ UUID_NS_TRWL_STATUS = UUID("391b0b17-f96d-4452-a714-b3e2527423ec")
17
+ UUID_NS_TRWL_EVENT = UUID("1581be5e-1ae9-4c27-8bad-151933ceaa90")
18
+
19
+
20
+ class Location(sql.SQLModel, table=True):
21
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
22
+ name: Optional[str] = None
23
+ addresses: list["LocationIdentifier"] = sql.Relationship(back_populates="location")
24
+
25
+ lon: Optional[Longitude] = None
26
+ lat: Optional[Latitude] = None
27
+ alt: Optional[int] = None
28
+
29
+
30
+ class LocationIdentifierEnum(enum.IntEnum):
31
+ UNKNOWN = 0
32
+ ID = 1
33
+ ADDRESS = 2
34
+
35
+
36
+ class LocationIdentifier(sql.SQLModel, table=True):
37
+ location_id: UUID = sql.Field(foreign_key="location.uuid", primary_key=True)
38
+ location: "Location" = sql.Relationship(back_populates="addresses")
39
+ type: LocationIdentifierEnum = sql.Field(primary_key=True)
40
+ address: str = sql.Field(primary_key=True)
41
+
42
+
43
+ class Stay(sql.SQLModel, table=True):
44
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
45
+ name: Optional[str] = None
46
+ address: Optional[str] = None
47
+
48
+ location_id: Optional[UUID] = sql.Field(default=None, foreign_key="location.uuid")
49
+ category: lptf.StayCategory
50
+
51
+
52
+ class Station(sql.SQLModel, table=True):
53
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
54
+ traewelling_id: Optional[int] = None
55
+ identifiers: list["StationIdentifier"] = sql.Relationship(back_populates="station")
56
+
57
+ name: str
58
+
59
+ location_id: Optional[UUID] = sql.Field(default=None, foreign_key="location.uuid")
60
+
61
+ @classmethod
62
+ def from_traewelling(cls, obj: trwl.Station):
63
+ return cls(
64
+ uuid=uuid5(namespace=UUID_NS_TRWL_STATION, name=str(obj.id)),
65
+ name=obj.name,
66
+ traewelling_id=obj.id,
67
+ identifiers=[
68
+ StationIdentifier.from_traewelling(
69
+ i,
70
+ uuid5(namespace=UUID_NS_TRWL_STATION, name=str(obj.id)),
71
+ traewelling_id=obj.id,
72
+ )
73
+ for i in obj.identifiers
74
+ ],
75
+ )
76
+
77
+
78
+ class StationIdentifier(sql.SQLModel, table=True):
79
+ station_id: UUID = sql.Field(foreign_key="station.uuid", primary_key=True)
80
+ station: "Station" = sql.Relationship(back_populates="identifiers")
81
+ station_traewelling_id: Optional[int] = sql.Field(default=None)
82
+ id_type: str = sql.Field(primary_key=True)
83
+ identifier: str = sql.Field(primary_key=True)
84
+
85
+ @classmethod
86
+ def from_traewelling(
87
+ cls, obj: trwl.StationIdentifier, uuid: UUID, traewelling_id: Optional[int]
88
+ ):
89
+ return cls(
90
+ station_id=uuid,
91
+ station_traewelling_id=traewelling_id,
92
+ id_type=obj.type,
93
+ identifier=obj.identifier,
94
+ )
95
+
96
+
97
+ class Operator(sql.SQLModel, table=True):
98
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
99
+ traewelling_id: Optional[int] = None
100
+ identifier_str: Optional[str] = None
101
+ name: str
102
+
103
+ @classmethod
104
+ def from_traewelling(cls, obj: trwl.Operator):
105
+ return cls(
106
+ uuid=uuid5(namespace=UUID_NS_TRWL_OPERATOR, name=str(obj.id)),
107
+ traewelling_id=obj.id,
108
+ name=obj.name,
109
+ )
110
+
111
+
112
+ class TransportProduct(sql.SQLModel, table=True):
113
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
114
+ name: str
115
+ mode: Optional[lptf.Mode] = sql.Field(default=None)
116
+ scope: Optional[lptf.ProductScope] = sql.Field(default=None)
117
+ stopping_pattern: Optional[lptf.StoppingPattern] = sql.Field(default=None)
118
+
119
+
120
+ class Transport(sql.SQLModel, table=True):
121
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
122
+ traewelling_id: Optional[int] = None
123
+ identifiers: list["TransportIdentifier"] = sql.Relationship(
124
+ back_populates="transport"
125
+ )
126
+
127
+ origin_id: UUID = sql.Field(foreign_key="station.uuid")
128
+ destination_id: UUID = sql.Field(foreign_key="station.uuid")
129
+
130
+ name: str
131
+ mode: str
132
+
133
+ operator_id: Optional[UUID] = sql.Field(default=None, foreign_key="operator.uuid")
134
+ product_id: Optional[UUID] = sql.Field(
135
+ default=None, foreign_key="transportproduct.uuid"
136
+ )
137
+
138
+ stops: list["Stop"] = sql.Relationship(back_populates="route")
139
+
140
+ @classmethod
141
+ def from_traewelling(cls, obj: trwl.Transport):
142
+ return cls(
143
+ uuid=uuid5(namespace=UUID_NS_TRWL_TRANSPORT, name=str(obj.trip)),
144
+ traewelling_id=obj.trip,
145
+ identifiers=[
146
+ TransportIdentifier(
147
+ transport_id=uuid5(
148
+ namespace=UUID_NS_TRWL_TRANSPORT, name=str(obj.trip)
149
+ ),
150
+ transport_traewelling_id=obj.trip,
151
+ id_type="hafas",
152
+ identifier=obj.hafasId,
153
+ )
154
+ ],
155
+ origin_id=uuid5(namespace=UUID_NS_TRWL_STATION, name=str(obj.origin.id)),
156
+ destination_id=uuid5(
157
+ namespace=UUID_NS_TRWL_STATION, name=str(obj.destination.id)
158
+ ),
159
+ name=obj.lineName,
160
+ mode=obj.category,
161
+ operator_id=uuid5(
162
+ namespace=UUID_NS_TRWL_OPERATOR, name=str(obj.operator.id)
163
+ )
164
+ if obj.operator is not None
165
+ else None,
166
+ )
167
+
168
+
169
+ class TransportIdentifier(sql.SQLModel, table=True):
170
+ transport_id: UUID = sql.Field(foreign_key="transport.uuid", primary_key=True)
171
+ transport: "Transport" = sql.Relationship(back_populates="identifiers")
172
+ transport_traewelling_id: Optional[int] = sql.Field(
173
+ default=None, foreign_key="transport.traewelling_id"
174
+ )
175
+ id_type: str
176
+ identifier: str
177
+
178
+
179
+ class Stop(sql.SQLModel, table=True):
180
+ station_id: UUID = sql.Field(foreign_key="station.uuid", primary_key=True)
181
+
182
+ route_id: UUID = sql.Field(foreign_key="transport.uuid", primary_key=True)
183
+ route: "Transport" = sql.Relationship(back_populates="stops")
184
+
185
+ stop_sequence: int = sql.Field(primary_key=True)
186
+
187
+ arrival_time_planned: Optional[datetime] = None
188
+ arrival_time_real: Optional[datetime] = None
189
+
190
+ departure_time_planned: Optional[datetime] = None
191
+ departure_time_real: Optional[datetime] = None
192
+
193
+ platform: Optional[str] = None
194
+
195
+ cancelled: bool = False
196
+
197
+
198
+ class Tag(sql.SQLModel, table=True):
199
+ status_id: UUID = sql.Field(foreign_key="status.uuid", primary_key=True)
200
+ status: "Status" = sql.Relationship(back_populates="tags")
201
+ key: str = sql.Field(primary_key=True)
202
+ value: str
203
+
204
+ @classmethod
205
+ def from_traewelling(cls, obj: trwl.Tag, status_id: UUID):
206
+ return cls(status_id=status_id, key=obj.key, value=obj.value)
207
+
208
+
209
+ class Event(sql.SQLModel, table=True):
210
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
211
+ traewelling_id: Optional[int] = None
212
+
213
+ name: str
214
+ hashtag: Optional[str] = None
215
+ host: Optional[str] = None
216
+ url: Optional[str] = None
217
+ begin: datetime
218
+ end: datetime
219
+ station_id: Optional[UUID] = sql.Field(default=None, foreign_key="station.uuid")
220
+ location_id: Optional[UUID] = sql.Field(default=None, foreign_key="location.uuid")
221
+ is_pride: bool = False
222
+
223
+ @classmethod
224
+ def from_traewelling(
225
+ cls,
226
+ obj: trwl.Event,
227
+ station_id: Optional[UUID] = None,
228
+ location_id: Optional[UUID] = None,
229
+ ):
230
+ return cls(
231
+ uuid=uuid5(namespace=UUID_NS_TRWL_EVENT, name=str(obj.id)),
232
+ traewelling_id=obj.id,
233
+ name=obj.name,
234
+ hashtag=obj.hashtag,
235
+ host=obj.host,
236
+ url=obj.url,
237
+ begin=obj.begin,
238
+ end=obj.end,
239
+ station_id=station_id,
240
+ location_id=location_id,
241
+ is_pride=obj.isPride,
242
+ )
243
+
244
+
245
+ class Individual(sql.SQLModel, table=True):
246
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
247
+ traewelling_id: Optional[int] = None
248
+
249
+ name: str
250
+ bio: str
251
+
252
+ @classmethod
253
+ def from_traewelling(cls, obj: trwl.User):
254
+ return cls(uuid=obj.uuid, traewelling_id=obj.id, name=obj.username, bio=obj.bio)
255
+
256
+
257
+ class StatusPurposeEnum(enum.IntEnum):
258
+ PRIVATE = 0
259
+ BUSINESS = 1
260
+ COMMUTE = 2
261
+ WORK = 3
262
+
263
+ @classmethod
264
+ def from_traewelling(cls, obj: trwl_enums.Business):
265
+ if obj == trwl_enums.Business.private:
266
+ return cls.PRIVATE
267
+ elif obj == trwl_enums.Business.business:
268
+ return cls.BUSINESS
269
+ elif obj == trwl_enums.Business.commute:
270
+ return cls.COMMUTE
271
+
272
+
273
+ class Status(sql.SQLModel, table=True):
274
+ uuid: UUID = sql.Field(default_factory=uuid4, primary_key=True)
275
+ traewelling_id: Optional[int] = None
276
+
277
+ body: str
278
+ purpose: StatusPurposeEnum
279
+ is_public: Optional[bool] = None
280
+ traveler_id: UUID = sql.Field(foreign_key="individual.uuid")
281
+
282
+ transport_id: UUID = sql.Field(foreign_key="transport.uuid")
283
+ event_id: Optional[UUID] = sql.Field(default=None, foreign_key="event.uuid")
284
+ tags: list["Tag"] = sql.Relationship(back_populates="status")
285
+
286
+ created_at: datetime
287
+
288
+ @classmethod
289
+ def from_traewelling(cls, obj: trwl.Status):
290
+ return cls(
291
+ uuid=uuid5(namespace=UUID_NS_TRWL_STATUS, name=str(obj.id)),
292
+ traewelling_id=obj.id,
293
+ body=obj.body,
294
+ purpose=StatusPurposeEnum.from_traewelling(obj.business),
295
+ is_public=(obj.visibility < 2),
296
+ traveler_id=obj.user.uuid,
297
+ event_id=uuid5(namespace=UUID_NS_TRWL_EVENT, name=str(obj.event.id))
298
+ if obj.event is not None
299
+ else None,
300
+ tags=[
301
+ Tag.from_traewelling(
302
+ i, uuid5(namespace=UUID_NS_TRWL_STATUS, name=str(obj.id))
303
+ )
304
+ for i in obj.tags
305
+ ],
306
+ created_at=obj.createdAt,
307
+ transport_id=uuid5(
308
+ namespace=UUID_NS_TRWL_TRANSPORT, name=str(obj.checkin.trip)
309
+ ),
310
+ )
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: opnvoyager-sqlmodel
3
+ Version: 0.1.0
4
+ Summary: A package that contains the SQLModels for the ÖPNVoyager tool
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: fptf-pydantic>=0.1.0
8
+ Requires-Dist: lptf-pydantic>=0.1.0
9
+ Requires-Dist: pycountry>=26.2.16
10
+ Requires-Dist: pydantic-client>=2.0.6
11
+ Requires-Dist: pydantic-extra-types>=2.11.0
12
+ Requires-Dist: sqlmodel>=0.0.31
13
+ Requires-Dist: traewelling-api>=0.1.1
14
+ Requires-Dist: traewelling-pydantic>=0.2.0
15
+
16
+ # ÖPNVoyager-SQLModel
17
+
18
+ A package that contains the SQLModels for the ÖPNVoyager tool.
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/opnvoyager_sqlmodel/__init__.py
4
+ src/opnvoyager_sqlmodel/models.py
5
+ src/opnvoyager_sqlmodel.egg-info/PKG-INFO
6
+ src/opnvoyager_sqlmodel.egg-info/SOURCES.txt
7
+ src/opnvoyager_sqlmodel.egg-info/dependency_links.txt
8
+ src/opnvoyager_sqlmodel.egg-info/requires.txt
9
+ src/opnvoyager_sqlmodel.egg-info/top_level.txt
@@ -0,0 +1,8 @@
1
+ fptf-pydantic>=0.1.0
2
+ lptf-pydantic>=0.1.0
3
+ pycountry>=26.2.16
4
+ pydantic-client>=2.0.6
5
+ pydantic-extra-types>=2.11.0
6
+ sqlmodel>=0.0.31
7
+ traewelling-api>=0.1.1
8
+ traewelling-pydantic>=0.2.0
@@ -0,0 +1 @@
1
+ opnvoyager_sqlmodel