Compare commits

..

No commits in common. "8d2ffe30141196e5ecb2655e1e0096b5d6624487" and "f2b6557cb7ff2104ea075ea3b62f1cd989dec054" have entirely different histories.

10 changed files with 144 additions and 298 deletions

View File

@ -79,7 +79,7 @@ function TrainsTableBody({stop, date, time, tableType}) {
const nullRef = useRef(null) const nullRef = useRef(null)
let table_rows = trains.map((train) => <CSSTransition key={train.id} timeout={500} classNames="shrink" nodeRef={nullRef}> let table_rows = trains.map((train) => <CSSTransition key={train.id} timeout={500} classNames="shrink" nodeRef={nullRef}>
<TrainRow train={train} tableType={tableType} date={date} time={time} /> <TrainRow train={train} tableType={tableType} />
</CSSTransition>) </CSSTransition>)
return <> return <>
@ -91,7 +91,7 @@ function TrainsTableBody({stop, date, time, tableType}) {
</> </>
} }
function TrainRow({train, tableType, date, time}) { function TrainRow({train, tableType}) {
const tripQuery = useQuery({ const tripQuery = useQuery({
queryKey: ['trip', train.trip], queryKey: ['trip', train.trip],
queryFn: () => fetch(`/api/gtfs/trip/${train.trip}/`) queryFn: () => fetch(`/api/gtfs/trip/${train.trip}/`)
@ -131,32 +131,8 @@ function TrainRow({train, tableType, date, time}) {
let headline = stops[tableType === "departures" ? stops.length - 1 : 0]?.stop ?? {name: "Chargement…"} let headline = stops[tableType === "departures" ? stops.length - 1 : 0]?.stop ?? {name: "Chargement…"}
const realtimeTripQuery = useQuery({
queryKey: ['realtimeTrip', trip.id, date, time],
queryFn: () => fetch(`/api/gtfs-rt/trip_update/${trip.id}/`)
.then(response => response.json()),
enabled: !!trip.id,
})
const realtimeTripData = realtimeTripQuery.data ?? {}
const scheduleRelationship = realtimeTripData.schedule_relationship ?? 0
const realtimeQuery = useQuery({
queryKey: ['realtime', train.id, date, time],
queryFn: () => fetch(`/api/gtfs-rt/stop_time_update/${train.id}/`)
.then(response => response.json()),
enabled: !!train.id,
})
const realtimeData = realtimeQuery.data ?? {}
const delay = tableType === "departures" ? realtimeData.departure_delay : realtimeData.arrival_delay
const prettyDelay = delay && scheduleRelationship !== 3 ? getPrettyDelay(delay) : ""
const [prettyScheduleRelationship, scheduleRelationshipColor] = getPrettyScheduleRelationship(scheduleRelationship)
console.log(realtimeTripData)
let stopsFilter let stopsFilter
if (scheduleRelationship === 3) if (tableType === "departures")
stopsFilter = (stop_time) => true
else if (tableType === "departures")
stopsFilter = (stop_time) => stop_time.stop_sequence > train.stop_sequence && stop_time.drop_off_type === 0 stopsFilter = (stop_time) => stop_time.stop_sequence > train.stop_sequence && stop_time.drop_off_type === 0
else else
stopsFilter = (stop_time) => stop_time.stop_sequence < train.stop_sequence && stop_time.pickup_type === 0 stopsFilter = (stop_time) => stop_time.stop_sequence < train.stop_sequence && stop_time.pickup_type === 0
@ -189,18 +165,8 @@ function TrainRow({train, tableType, date, time}) {
</Box> </Box>
</TableCell> </TableCell>
<TableCell> <TableCell>
<Box display="flex" alignItems="center" justifyContent="center"> <Box display="flex" alignItems="center" justifyContent="center" fontWeight="bold" color="#FFED02" fontSize={24}>
<Box> {getDisplayTime(train, tableType)}
<Box fontWeight="bold" color="#FFED02" fontSize={24}>
{getDisplayTime(train, tableType)}
</Box>
<Box color={delay && delay !== "00:00:00" ? "#e86d2b" : "white"} fontWeight={delay && delay !== "00:00:00" ? "bold" : ""}>
{prettyDelay}
</Box>
<Box color={scheduleRelationshipColor} fontWeight="bold">
{prettyScheduleRelationship}
</Box>
</Box>
</Box> </Box>
</TableCell> </TableCell>
<TableCell> <TableCell>
@ -261,23 +227,4 @@ function getDisplayTime(train, tableType) {
return day_split[day_split.length - 1].substring(0, 5) return day_split[day_split.length - 1].substring(0, 5)
} }
function getPrettyDelay(delay) {
let delay_split = delay.split(':')
let hours = parseInt(delay_split[0])
let minutes = parseInt(delay_split[1])
let full_minutes = hours * 60 + minutes
return full_minutes ? `+${full_minutes} min` : "À l'heure"
}
function getPrettyScheduleRelationship(scheduledRelationship) {
switch (scheduledRelationship) {
case 1:
return ["Ajouté", "#3ebb18"]
case 3:
return ["Supprimé", "#ff8701"]
default:
return ["", ""]
}
}
export default TrainsTable; export default TrainsTable;

View File

@ -1,7 +1,7 @@
from rest_framework import serializers from rest_framework import serializers
from sncfgtfs.models import Agency, Stop, Route, Trip, StopTime, Calendar, CalendarDate, \ from sncfgtfs.models import Agency, Stop, Route, Trip, StopTime, Calendar, CalendarDate, \
Transfer, FeedInfo, TripUpdate, StopTimeUpdate Transfer, FeedInfo
class AgencySerializer(serializers.ModelSerializer): class AgencySerializer(serializers.ModelSerializer):
@ -61,15 +61,3 @@ class FeedInfoSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = FeedInfo model = FeedInfo
fields = '__all__' fields = '__all__'
class TripUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = TripUpdate
fields = '__all__'
class StopTimeUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = StopTimeUpdate
fields = '__all__'

View File

@ -10,9 +10,10 @@ from rest_framework.filters import OrderingFilter, SearchFilter
from sncf.api.serializers import AgencySerializer, StopSerializer, RouteSerializer, TripSerializer, \ from sncf.api.serializers import AgencySerializer, StopSerializer, RouteSerializer, TripSerializer, \
StopTimeSerializer, CalendarSerializer, CalendarDateSerializer, TransferSerializer, \ StopTimeSerializer, CalendarSerializer, CalendarDateSerializer, TransferSerializer, \
FeedInfoSerializer, TripUpdateSerializer, StopTimeUpdateSerializer FeedInfoSerializer
from sncfgtfs.models import Agency, Stop, Route, Trip, StopTime, Calendar, CalendarDate, \ from sncfgtfs.models import Agency, Stop, Route, Trip, StopTime, Calendar, CalendarDate, \
Transfer, FeedInfo, TripUpdate, StopTimeUpdate Transfer, FeedInfo
CACHE_CONTROL = cache_control(max_age=7200) CACHE_CONTROL = cache_control(max_age=7200)
LAST_MODIFIED = last_modified(lambda *args, **kwargs: datetime.fromisoformat(FeedInfo.objects.get().version)) LAST_MODIFIED = last_modified(lambda *args, **kwargs: datetime.fromisoformat(FeedInfo.objects.get().version))
@ -101,20 +102,6 @@ class FeedInfoViewSet(viewsets.ReadOnlyModelViewSet):
filterset_fields = '__all__' filterset_fields = '__all__'
class TripUpdateViewSet(viewsets.ReadOnlyModelViewSet):
queryset = TripUpdate.objects.all()
serializer_class = TripUpdateSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = '__all__'
class StopTimeUpdateViewSet(viewsets.ReadOnlyModelViewSet):
queryset = StopTimeUpdate.objects.all()
serializer_class = StopTimeUpdateSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = '__all__'
class NextDeparturesViewSet(viewsets.ReadOnlyModelViewSet): class NextDeparturesViewSet(viewsets.ReadOnlyModelViewSet):
queryset = StopTime.objects.none() queryset = StopTime.objects.none()
serializer_class = StopTimeSerializer serializer_class = StopTimeSerializer

View File

@ -19,8 +19,7 @@ from django.urls import path, include
from rest_framework import routers from rest_framework import routers
from sncf.api.views import AgencyViewSet, StopViewSet, RouteViewSet, TripViewSet, StopTimeViewSet, \ from sncf.api.views import AgencyViewSet, StopViewSet, RouteViewSet, TripViewSet, StopTimeViewSet, \
CalendarViewSet, CalendarDateViewSet, TransferViewSet, FeedInfoViewSet, NextDeparturesViewSet, NextArrivalsViewSet, \ CalendarViewSet, CalendarDateViewSet, TransferViewSet, FeedInfoViewSet, NextDeparturesViewSet, NextArrivalsViewSet
TripUpdateViewSet, StopTimeUpdateViewSet
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register("gtfs/agency", AgencyViewSet) router.register("gtfs/agency", AgencyViewSet)
@ -32,8 +31,6 @@ router.register("gtfs/calendar", CalendarViewSet)
router.register("gtfs/calendar_date", CalendarDateViewSet) router.register("gtfs/calendar_date", CalendarDateViewSet)
router.register("gtfs/transfer", TransferViewSet) router.register("gtfs/transfer", TransferViewSet)
router.register("gtfs/feed_info", FeedInfoViewSet) router.register("gtfs/feed_info", FeedInfoViewSet)
router.register("gtfs-rt/trip_update", TripUpdateViewSet)
router.register("gtfs-rt/stop_time_update", StopTimeUpdateViewSet)
router.register("station/next_departures", NextDeparturesViewSet, basename="next_departures") router.register("station/next_departures", NextDeparturesViewSet, basename="next_departures")
router.register("station/next_arrivals", NextArrivalsViewSet, basename="next_arrivals") router.register("station/next_arrivals", NextArrivalsViewSet, basename="next_arrivals")

View File

@ -86,14 +86,13 @@ class StopTimeUpdateAdmin(admin.ModelAdmin):
list_display = ('trip_update', 'stop_time', 'arrival_delay', 'arrival_time', list_display = ('trip_update', 'stop_time', 'arrival_delay', 'arrival_time',
'departure_delay', 'departure_time', 'schedule_relationship',) 'departure_delay', 'departure_time', 'schedule_relationship',)
list_filter = ('schedule_relationship',) list_filter = ('schedule_relationship',)
search_fields = ('trip_update__trip__id', 'stop_time__stop__name', 'arrival_time', 'departure_time',) search_fields = ('trip_update__trip_id', 'stop_time__stop__name', 'arrival_time', 'departure_time',)
ordering = ('trip_update', 'stop_time',) ordering = ('trip_update', 'stop_time',)
@admin.register(TripUpdate) @admin.register(TripUpdate)
class TripUpdateAdmin(admin.ModelAdmin): class TripUpdateAdmin(admin.ModelAdmin):
list_display = ('trip_id', 'start_date', 'start_time',) list_display = ('trip_id', 'start_date', 'start_time',)
list_filter = ('start_date', 'schedule_relationship',) search_fields = ('trip_id', 'start_date', 'start_time',)
search_fields = ('trip__id', 'start_date', 'start_time',)
ordering = ('trip_id', 'start_date', 'start_time',) ordering = ('trip_id', 'start_date', 'start_time',)
autocomplete_fields = ('trip',) autocomplete_fields = ('trip',)

View File

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 1.0\n" "Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-06 08:00+0100\n" "POT-Creation-Date: 2024-02-04 22:16+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Emmy D'Anello <ynerant@emy.lu>\n" "Last-Translator: Emmy D'Anello <ynerant@emy.lu>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -128,7 +128,7 @@ msgstr "Correspondance programmée"
msgid "Minimum time" msgid "Minimum time"
msgstr "Temps de correspondance minimum requis" msgstr "Temps de correspondance minimum requis"
#: sncfgtfs/models.py:57 sncfgtfs/models.py:63 #: sncfgtfs/models.py:57
msgid "Added" msgid "Added"
msgstr "Ajouté" msgstr "Ajouté"
@ -136,411 +136,395 @@ msgstr "Ajouté"
msgid "Removed" msgid "Removed"
msgstr "Supprimé" msgstr "Supprimé"
#: sncfgtfs/models.py:62 sncfgtfs/models.py:72 #: sncfgtfs/models.py:62
msgid "Scheduled" msgid "Scheduled"
msgstr "Planifié" msgstr "Planifié"
#: sncfgtfs/models.py:64 sncfgtfs/models.py:75 #: sncfgtfs/models.py:63
msgid "Unscheduled"
msgstr "Non planifié"
#: sncfgtfs/models.py:65
msgid "Canceled"
msgstr "Annulé"
#: sncfgtfs/models.py:66
msgid "Replacement"
msgstr "Remplacé"
#: sncfgtfs/models.py:67
msgid "Duplicated"
msgstr "Dupliqué"
#: sncfgtfs/models.py:68
msgid "Deleted"
msgstr "Supprimé"
#: sncfgtfs/models.py:73
msgid "Skipped" msgid "Skipped"
msgstr "Sauté" msgstr "Sauté"
#: sncfgtfs/models.py:74 #: sncfgtfs/models.py:64
msgid "No data" msgid "No data"
msgstr "Pas de données" msgstr "Pas de données"
#: sncfgtfs/models.py:82 sncfgtfs/models.py:233 #: sncfgtfs/models.py:65
msgid "Unscheduled"
msgstr "Non planifié"
#: sncfgtfs/models.py:72 sncfgtfs/models.py:229
msgid "Agency ID" msgid "Agency ID"
msgstr "ID de l'agence" msgstr "ID de l'agence"
#: sncfgtfs/models.py:88 #: sncfgtfs/models.py:78
msgid "Agency name" msgid "Agency name"
msgstr "Nom de l'agence" msgstr "Nom de l'agence"
#: sncfgtfs/models.py:92 #: sncfgtfs/models.py:82
msgid "Agency URL" msgid "Agency URL"
msgstr "URL de l'agence" msgstr "URL de l'agence"
#: sncfgtfs/models.py:97 #: sncfgtfs/models.py:87
msgid "Agency timezone" msgid "Agency timezone"
msgstr "Fuseau horaire de l'agence" msgstr "Fuseau horaire de l'agence"
#: sncfgtfs/models.py:102 #: sncfgtfs/models.py:92
msgid "Agency language" msgid "Agency language"
msgstr "Langue de l'agence" msgstr "Langue de l'agence"
#: sncfgtfs/models.py:108 #: sncfgtfs/models.py:98
msgid "Agency phone" msgid "Agency phone"
msgstr "Téléphone de l'agence" msgstr "Téléphone de l'agence"
#: sncfgtfs/models.py:113 #: sncfgtfs/models.py:103
msgid "Agency email" msgid "Agency email"
msgstr "Adresse email de l'agence" msgstr "Adresse email de l'agence"
#: sncfgtfs/models.py:121 #: sncfgtfs/models.py:111
msgid "Agency" msgid "Agency"
msgstr "Agence" msgstr "Agence"
#: sncfgtfs/models.py:122 #: sncfgtfs/models.py:112
msgid "Agencies" msgid "Agencies"
msgstr "Agences" msgstr "Agences"
#: sncfgtfs/models.py:130 sncfgtfs/models.py:424 #: sncfgtfs/models.py:120 sncfgtfs/models.py:420
msgid "Stop ID" msgid "Stop ID"
msgstr "ID de l'arrêt" msgstr "ID de l'arrêt"
#: sncfgtfs/models.py:135 #: sncfgtfs/models.py:125
msgid "Stop code" msgid "Stop code"
msgstr "Code de l'arrêt" msgstr "Code de l'arrêt"
#: sncfgtfs/models.py:141 #: sncfgtfs/models.py:131
msgid "Stop name" msgid "Stop name"
msgstr "Nom de l'arrêt" msgstr "Nom de l'arrêt"
#: sncfgtfs/models.py:146 #: sncfgtfs/models.py:136
msgid "Stop description" msgid "Stop description"
msgstr "Description de l'arrêt" msgstr "Description de l'arrêt"
#: sncfgtfs/models.py:151 #: sncfgtfs/models.py:141
msgid "Stop longitude" msgid "Stop longitude"
msgstr "Longitude de l'arrêt" msgstr "Longitude de l'arrêt"
#: sncfgtfs/models.py:155 #: sncfgtfs/models.py:145
msgid "Stop latitude" msgid "Stop latitude"
msgstr "Latitude de l'arrêt" msgstr "Latitude de l'arrêt"
#: sncfgtfs/models.py:160 #: sncfgtfs/models.py:150
msgid "Zone ID" msgid "Zone ID"
msgstr "ID de la zone" msgstr "ID de la zone"
#: sncfgtfs/models.py:164 #: sncfgtfs/models.py:154
msgid "Stop URL" msgid "Stop URL"
msgstr "URL de l'arrêt" msgstr "URL de l'arrêt"
#: sncfgtfs/models.py:169 #: sncfgtfs/models.py:159
msgid "Location type" msgid "Location type"
msgstr "Type de localisation" msgstr "Type de localisation"
#: sncfgtfs/models.py:178 #: sncfgtfs/models.py:168
msgid "Parent station" msgid "Parent station"
msgstr "Gare parente" msgstr "Gare parente"
#: sncfgtfs/models.py:186 #: sncfgtfs/models.py:176
msgid "Stop timezone" msgid "Stop timezone"
msgstr "Fuseau horaire de l'arrêt" msgstr "Fuseau horaire de l'arrêt"
#: sncfgtfs/models.py:192 #: sncfgtfs/models.py:182
msgid "Level ID" msgid "Level ID"
msgstr "ID du niveau" msgstr "ID du niveau"
#: sncfgtfs/models.py:197 #: sncfgtfs/models.py:187
msgid "Wheelchair boarding" msgid "Wheelchair boarding"
msgstr "Embarquement en fauteuil roulant" msgstr "Embarquement en fauteuil roulant"
#: sncfgtfs/models.py:205 #: sncfgtfs/models.py:195
msgid "Platform code" msgid "Platform code"
msgstr "Code du quai" msgstr "Code du quai"
#: sncfgtfs/models.py:218 #: sncfgtfs/models.py:214
msgid "Stop" msgid "Stop"
msgstr "Arrêt" msgstr "Arrêt"
#: sncfgtfs/models.py:219 #: sncfgtfs/models.py:215
msgid "Stops" msgid "Stops"
msgstr "Arrêts" msgstr "Arrêts"
#: sncfgtfs/models.py:227 sncfgtfs/models.py:403 sncfgtfs/models.py:542 #: sncfgtfs/models.py:223 sncfgtfs/models.py:399 sncfgtfs/models.py:538
#: sncfgtfs/models.py:580 #: sncfgtfs/models.py:576
msgid "ID" msgid "ID"
msgstr "Identifiant" msgstr "Identifiant"
#: sncfgtfs/models.py:239 #: sncfgtfs/models.py:235
msgid "Route short name" msgid "Route short name"
msgstr "Nom court de la ligne" msgstr "Nom court de la ligne"
#: sncfgtfs/models.py:244 #: sncfgtfs/models.py:240
msgid "Route long name" msgid "Route long name"
msgstr "Nom long de la ligne" msgstr "Nom long de la ligne"
#: sncfgtfs/models.py:249 #: sncfgtfs/models.py:245
msgid "Route description" msgid "Route description"
msgstr "Description de la ligne" msgstr "Description de la ligne"
#: sncfgtfs/models.py:254 #: sncfgtfs/models.py:250
msgid "Route type" msgid "Route type"
msgstr "Type de ligne" msgstr "Type de ligne"
#: sncfgtfs/models.py:259 #: sncfgtfs/models.py:255
msgid "Route URL" msgid "Route URL"
msgstr "URL de la ligne" msgstr "URL de la ligne"
#: sncfgtfs/models.py:265 #: sncfgtfs/models.py:261
msgid "Route color" msgid "Route color"
msgstr "Couleur de la ligne" msgstr "Couleur de la ligne"
#: sncfgtfs/models.py:271 #: sncfgtfs/models.py:267
msgid "Route text color" msgid "Route text color"
msgstr "Couleur du texte de la ligne" msgstr "Couleur du texte de la ligne"
#: sncfgtfs/models.py:279 sncfgtfs/models.py:294 #: sncfgtfs/models.py:275 sncfgtfs/models.py:290
msgid "Route" msgid "Route"
msgstr "Ligne" msgstr "Ligne"
#: sncfgtfs/models.py:280 #: sncfgtfs/models.py:276
msgid "Routes" msgid "Routes"
msgstr "Lignes" msgstr "Lignes"
#: sncfgtfs/models.py:288 #: sncfgtfs/models.py:284
msgid "Trip ID" msgid "Trip ID"
msgstr "ID du trajet" msgstr "ID du trajet"
#: sncfgtfs/models.py:301 sncfgtfs/models.py:548 #: sncfgtfs/models.py:297 sncfgtfs/models.py:544
msgid "Service" msgid "Service"
msgstr "Service" msgstr "Service"
#: sncfgtfs/models.py:307 #: sncfgtfs/models.py:303
msgid "Trip headsign" msgid "Trip headsign"
msgstr "Destination du trajet" msgstr "Destination du trajet"
#: sncfgtfs/models.py:313 #: sncfgtfs/models.py:309
msgid "Trip short name" msgid "Trip short name"
msgstr "Nom court du trajet" msgstr "Nom court du trajet"
#: sncfgtfs/models.py:318 #: sncfgtfs/models.py:314
msgid "Direction" msgid "Direction"
msgstr "Direction" msgstr "Direction"
#: sncfgtfs/models.py:325 #: sncfgtfs/models.py:321
msgid "Block ID" msgid "Block ID"
msgstr "ID du bloc" msgstr "ID du bloc"
#: sncfgtfs/models.py:331 #: sncfgtfs/models.py:327
msgid "Shape ID" msgid "Shape ID"
msgstr "ID de la forme" msgstr "ID de la forme"
#: sncfgtfs/models.py:336 #: sncfgtfs/models.py:332
msgid "Wheelchair accessible" msgid "Wheelchair accessible"
msgstr "Accessible en fauteuil roulant" msgstr "Accessible en fauteuil roulant"
#: sncfgtfs/models.py:343 #: sncfgtfs/models.py:339
msgid "Bikes allowed" msgid "Bikes allowed"
msgstr "Vélos autorisés" msgstr "Vélos autorisés"
#: sncfgtfs/models.py:395 sncfgtfs/models.py:409 sncfgtfs/models.py:652 #: sncfgtfs/models.py:391 sncfgtfs/models.py:405 sncfgtfs/models.py:648
msgid "Trip" msgid "Trip"
msgstr "Trajet" msgstr "Trajet"
#: sncfgtfs/models.py:396 #: sncfgtfs/models.py:392
msgid "Trips" msgid "Trips"
msgstr "Trajets" msgstr "Trajets"
#: sncfgtfs/models.py:414 sncfgtfs/models.py:702 #: sncfgtfs/models.py:410 sncfgtfs/models.py:698
msgid "Arrival time" msgid "Arrival time"
msgstr "Heure d'arrivée" msgstr "Heure d'arrivée"
#: sncfgtfs/models.py:418 sncfgtfs/models.py:710 #: sncfgtfs/models.py:414 sncfgtfs/models.py:706
msgid "Departure time" msgid "Departure time"
msgstr "Heure de départ" msgstr "Heure de départ"
#: sncfgtfs/models.py:429 #: sncfgtfs/models.py:425
msgid "Stop sequence" msgid "Stop sequence"
msgstr "Séquence de l'arrêt" msgstr "Séquence de l'arrêt"
#: sncfgtfs/models.py:434 #: sncfgtfs/models.py:430
msgid "Stop headsign" msgid "Stop headsign"
msgstr "Destination de l'arrêt" msgstr "Destination de l'arrêt"
#: sncfgtfs/models.py:439 #: sncfgtfs/models.py:435
msgid "Pickup type" msgid "Pickup type"
msgstr "Type de prise en charge" msgstr "Type de prise en charge"
#: sncfgtfs/models.py:446 #: sncfgtfs/models.py:442
msgid "Drop off type" msgid "Drop off type"
msgstr "Type de dépose" msgstr "Type de dépose"
#: sncfgtfs/models.py:453 #: sncfgtfs/models.py:449
msgid "Timepoint" msgid "Timepoint"
msgstr "Ponctualité" msgstr "Ponctualité"
#: sncfgtfs/models.py:476 sncfgtfs/models.py:692 #: sncfgtfs/models.py:472 sncfgtfs/models.py:688
msgid "Stop time" msgid "Stop time"
msgstr "Heure d'arrêt" msgstr "Heure d'arrêt"
#: sncfgtfs/models.py:477 #: sncfgtfs/models.py:473
msgid "Stop times" msgid "Stop times"
msgstr "Heures d'arrêt" msgstr "Heures d'arrêt"
#: sncfgtfs/models.py:484 #: sncfgtfs/models.py:480
msgid "Service ID" msgid "Service ID"
msgstr "ID du service" msgstr "ID du service"
#: sncfgtfs/models.py:488 #: sncfgtfs/models.py:484
msgid "Monday" msgid "Monday"
msgstr "Lundi" msgstr "Lundi"
#: sncfgtfs/models.py:492 #: sncfgtfs/models.py:488
msgid "Tuesday" msgid "Tuesday"
msgstr "Mardi" msgstr "Mardi"
#: sncfgtfs/models.py:496 #: sncfgtfs/models.py:492
msgid "Wednesday" msgid "Wednesday"
msgstr "Mercredi" msgstr "Mercredi"
#: sncfgtfs/models.py:500 #: sncfgtfs/models.py:496
msgid "Thursday" msgid "Thursday"
msgstr "Jeudi" msgstr "Jeudi"
#: sncfgtfs/models.py:504 #: sncfgtfs/models.py:500
msgid "Friday" msgid "Friday"
msgstr "Vendredi" msgstr "Vendredi"
#: sncfgtfs/models.py:508 #: sncfgtfs/models.py:504
msgid "Saturday" msgid "Saturday"
msgstr "Samedi" msgstr "Samedi"
#: sncfgtfs/models.py:512 #: sncfgtfs/models.py:508
msgid "Sunday" msgid "Sunday"
msgstr "Dimanche" msgstr "Dimanche"
#: sncfgtfs/models.py:516 sncfgtfs/models.py:658 #: sncfgtfs/models.py:512 sncfgtfs/models.py:654
msgid "Start date" msgid "Start date"
msgstr "Date de début" msgstr "Date de début"
#: sncfgtfs/models.py:520 #: sncfgtfs/models.py:516
msgid "End date" msgid "End date"
msgstr "Date de fin" msgstr "Date de fin"
#: sncfgtfs/models.py:525 sncfgtfs/models.py:563 #: sncfgtfs/models.py:521 sncfgtfs/models.py:559
msgid "Transport type" msgid "Transport type"
msgstr "Type de transport" msgstr "Type de transport"
#: sncfgtfs/models.py:533 #: sncfgtfs/models.py:529
msgid "Calendar" msgid "Calendar"
msgstr "Calendrier" msgstr "Calendrier"
#: sncfgtfs/models.py:534 #: sncfgtfs/models.py:530
msgid "Calendars" msgid "Calendars"
msgstr "Calendriers" msgstr "Calendriers"
#: sncfgtfs/models.py:553 #: sncfgtfs/models.py:549
msgid "Date" msgid "Date"
msgstr "Date" msgstr "Date"
#: sncfgtfs/models.py:557 #: sncfgtfs/models.py:553
msgid "Exception type" msgid "Exception type"
msgstr "Type d'exception" msgstr "Type d'exception"
#: sncfgtfs/models.py:571 #: sncfgtfs/models.py:567
msgid "Calendar date" msgid "Calendar date"
msgstr "Date du calendrier" msgstr "Date du calendrier"
#: sncfgtfs/models.py:572 #: sncfgtfs/models.py:568
msgid "Calendar dates" msgid "Calendar dates"
msgstr "Dates du calendrier" msgstr "Dates du calendrier"
#: sncfgtfs/models.py:586 #: sncfgtfs/models.py:582
msgid "From stop" msgid "From stop"
msgstr "Depuis l'arrêt" msgstr "Depuis l'arrêt"
#: sncfgtfs/models.py:593 #: sncfgtfs/models.py:589
msgid "To stop" msgid "To stop"
msgstr "Jusqu'à l'arrêt" msgstr "Jusqu'à l'arrêt"
#: sncfgtfs/models.py:598 #: sncfgtfs/models.py:594
msgid "Transfer type" msgid "Transfer type"
msgstr "Type de correspondance" msgstr "Type de correspondance"
#: sncfgtfs/models.py:604 #: sncfgtfs/models.py:600
msgid "Minimum transfer time" msgid "Minimum transfer time"
msgstr "Temps de correspondance minimum" msgstr "Temps de correspondance minimum"
#: sncfgtfs/models.py:609 #: sncfgtfs/models.py:605
msgid "Transfer" msgid "Transfer"
msgstr "Correspondance" msgstr "Correspondance"
#: sncfgtfs/models.py:610 #: sncfgtfs/models.py:606
msgid "Transfers" msgid "Transfers"
msgstr "Correspondances" msgstr "Correspondances"
#: sncfgtfs/models.py:617 #: sncfgtfs/models.py:613
msgid "Feed publisher name" msgid "Feed publisher name"
msgstr "Nom de l'éditeur du flux" msgstr "Nom de l'éditeur du flux"
#: sncfgtfs/models.py:621 #: sncfgtfs/models.py:617
msgid "Feed publisher URL" msgid "Feed publisher URL"
msgstr "URL de l'éditeur du flux" msgstr "URL de l'éditeur du flux"
#: sncfgtfs/models.py:626 #: sncfgtfs/models.py:622
msgid "Feed language" msgid "Feed language"
msgstr "Langue du flux" msgstr "Langue du flux"
#: sncfgtfs/models.py:630 #: sncfgtfs/models.py:626
msgid "Feed start date" msgid "Feed start date"
msgstr "Date de début du flux" msgstr "Date de début du flux"
#: sncfgtfs/models.py:634 #: sncfgtfs/models.py:630
msgid "Feed end date" msgid "Feed end date"
msgstr "Date de fin du flux" msgstr "Date de fin du flux"
#: sncfgtfs/models.py:639 #: sncfgtfs/models.py:635
msgid "Feed version" msgid "Feed version"
msgstr "Version du flux" msgstr "Version du flux"
#: sncfgtfs/models.py:643 #: sncfgtfs/models.py:639
msgid "Feed info" msgid "Feed info"
msgstr "Information du flux" msgstr "Information du flux"
#: sncfgtfs/models.py:644 #: sncfgtfs/models.py:640
msgid "Feed infos" msgid "Feed infos"
msgstr "Informations du flux" msgstr "Informations du flux"
#: sncfgtfs/models.py:662 #: sncfgtfs/models.py:658
msgid "Start time" msgid "Start time"
msgstr "Heure de début" msgstr "Heure de début"
#: sncfgtfs/models.py:666 sncfgtfs/models.py:714 #: sncfgtfs/models.py:662 sncfgtfs/models.py:710
msgid "Schedule relationship" msgid "Schedule relationship"
msgstr "Relation de la planification" msgstr "Relation de la planification"
#: sncfgtfs/models.py:675 sncfgtfs/models.py:685 #: sncfgtfs/models.py:671 sncfgtfs/models.py:681
msgid "Trip update" msgid "Trip update"
msgstr "Mise à jour du trajet" msgstr "Mise à jour du trajet"
#: sncfgtfs/models.py:676 #: sncfgtfs/models.py:672
msgid "Trip updates" msgid "Trip updates"
msgstr "Mises à jour des trajets" msgstr "Mises à jour des trajets"
#: sncfgtfs/models.py:698 #: sncfgtfs/models.py:694
msgid "Arrival delay" msgid "Arrival delay"
msgstr "Retard à l'arrivée" msgstr "Retard à l'arrivée"
#: sncfgtfs/models.py:706 #: sncfgtfs/models.py:702
msgid "Departure delay" msgid "Departure delay"
msgstr "Retard au départ" msgstr "Retard au départ"
#: sncfgtfs/models.py:723 #: sncfgtfs/models.py:719
msgid "Stop time update" msgid "Stop time update"
msgstr "Mise à jour du temps d'arrêt" msgstr "Mise à jour du temps d'arrêt"
#: sncfgtfs/models.py:724 #: sncfgtfs/models.py:720
msgid "Stop time updates" msgid "Stop time updates"
msgstr "Mises à jour des temps d'arrêt" msgstr "Mises à jour des temps d'arrêt"

View File

@ -265,7 +265,7 @@ class Command(BaseCommand):
dep_time = stop_time_dict['departure_time'] dep_time = stop_time_dict['departure_time']
dep_time = int(dep_time[:2]) * 3600 + int(dep_time[3:5]) * 60 + int(dep_time[6:]) dep_time = int(dep_time[:2]) * 3600 + int(dep_time[3:5]) * 60 + int(dep_time[6:])
st = StopTime( st = StopTime(
id=f"{stop_time_dict['trip_id']}-{stop_time_dict['stop_id']}", id=f"{stop_time_dict['trip_id']}-{stop_time_dict['stop_sequence']}",
trip_id=stop_time_dict['trip_id'], trip_id=stop_time_dict['trip_id'],
arrival_time=timedelta(seconds=arr_time), arrival_time=timedelta(seconds=arr_time),
departure_time=timedelta(seconds=dep_time), departure_time=timedelta(seconds=dep_time),

View File

@ -3,7 +3,6 @@ from zoneinfo import ZoneInfo
import requests import requests
from django.core.management import BaseCommand from django.core.management import BaseCommand
from django.db.models import Q, Max
from sncfgtfs.gtfs_realtime_pb2 import FeedMessage from sncfgtfs.gtfs_realtime_pb2 import FeedMessage
from sncfgtfs.models import Calendar, CalendarDate, StopTime, StopTimeUpdate, Trip, TripUpdate, Stop from sncfgtfs.models import Calendar, CalendarDate, StopTime, StopTimeUpdate, Trip, TripUpdate, Stop
@ -42,11 +41,6 @@ class Command(BaseCommand):
headsign = trip_id[5:-1] headsign = trip_id[5:-1]
trip_qs = Trip.objects.all() trip_qs = Trip.objects.all()
trip_ids = trip_qs.values_list('id', flat=True) trip_ids = trip_qs.values_list('id', flat=True)
last_stop_queryset = StopTime.objects.filter(
stop__parent_station_id=trip_update.stop_time_update[-1].stop_id,
).values('trip_id')
trip_ids = trip_ids.intersection(last_stop_queryset)
for stop_sequence, stop_time_update in enumerate(trip_update.stop_time_update): for stop_sequence, stop_time_update in enumerate(trip_update.stop_time_update):
stop_id = stop_time_update.stop_id stop_id = stop_time_update.stop_id
st_queryset = StopTime.objects.filter(stop__parent_station_id=stop_id) st_queryset = StopTime.objects.filter(stop__parent_station_id=stop_id)
@ -55,19 +49,14 @@ class Command(BaseCommand):
trip_ids_restrict = trip_ids.intersection(st_queryset.values('trip_id')) trip_ids_restrict = trip_ids.intersection(st_queryset.values('trip_id'))
if trip_ids_restrict: if trip_ids_restrict:
trip_ids = trip_ids_restrict trip_ids = trip_ids_restrict
else:
stop = Stop.objects.get(id=stop_id)
self.stdout.write(self.style.WARNING(f"Warning: No trip is found passing by stop "
f"{stop.name} ({stop_id})"))
trip_ids = set(trip_ids)
route_ids = set(Trip.objects.filter(id__in=trip_ids).values_list('route_id', flat=True)) route_ids = set(Trip.objects.filter(id__in=trip_ids).values_list('route_id', flat=True))
self.stdout.write(f"{len(route_ids)} routes found on trip for new train {headsign}") self.stdout.write(f"{len(route_ids)} routes found on trip for train {headsign}")
if not route_ids: if not route_ids:
self.stdout.write(f"Route not found for trip {trip_id}.") self.stdout.write(f"Route not found for trip {trip_id}.")
continue continue
elif len(route_ids) > 1: elif len(route_ids) > 1:
self.stdout.write(f"Multiple routes found for trip {trip_id}.") self.stdout.write(f"Multiple routes found for trip {trip_id}.")
self.stderr.write(", ".join(route_ids)) continue
route_id = route_ids.pop() route_id = route_ids.pop()
Calendar.objects.update_or_create( Calendar.objects.update_or_create(
@ -109,19 +98,15 @@ class Command(BaseCommand):
stop_id = stop_time_update.stop_id stop_id = stop_time_update.stop_id
stop = Stop.objects.get(id=stop_id) stop = Stop.objects.get(id=stop_id)
if stop.location_type == 1: if stop.location_type == 1:
if not StopTime.objects.filter(trip_id=trip_id).exists(): if stop_sequence == 0:
stop = StopTime.objects.get(trip_id=sample_trip.id, stop = sample_trip.stop_times.get(stop_sequence=0).stop
stop__parent_station_id=stop_id).stop
elif StopTime.objects.filter(trip_id=trip_id, stop__parent_station_id=stop_id).exists():
stop = StopTime.objects.get(trip_id=trip_id, stop__parent_station_id=stop_id).stop
else: else:
stop = next(s for s in Stop.objects.filter(parent_station_id=stop_id).all() previous_stop = sample_trip.stop_times.get(stop_sequence=stop_sequence - 1).stop
for s2 in StopTime.objects.filter(trip_id=trip_id).all() stop = next(s for s in stop.children.all() \
if s.stop_type in s2.stop.stop_type if s.location_type == 0 and s.stop_type == previous_stop.stop_type)
or s2.stop.stop_type in s.stop_type)
stop_id = stop.id stop_id = stop.id
StopTime.objects.update_or_create( StopTime.objects.update_or_create(
id=f"{trip_id}-{stop_id}", id=f"{trip_id}-{stop_sequence}",
trip_id=trip_id, trip_id=trip_id,
defaults={ defaults={
"stop_id": stop_id, "stop_id": stop_id,
@ -145,46 +130,12 @@ class Command(BaseCommand):
start_time=trip_update.trip.start_time, start_time=trip_update.trip.start_time,
schedule_relationship=trip_update.trip.schedule_relationship, schedule_relationship=trip_update.trip.schedule_relationship,
) )
for stop_sequence, stop_time_update in enumerate(trip_update.stop_time_update): for stop_sequence, stop_time_update in enumerate(trip_update.stop_time_update):
stop_id = stop_time_update.stop_id if not StopTime.objects.filter(trip_id=trip_id, stop_sequence=stop_sequence).exists():
if stop_id.startswith('StopArea:'): self.stdout.write(f"Stop {stop_sequence} does not exist in GTFS feed for trip {trip_id}.")
if StopTime.objects.filter(trip_id=trip_id, stop__parent_station_id=stop_id).exists(): continue
stop = StopTime.objects.get(trip_id=trip_id, stop__parent_station_id=stop_id).stop
else:
stop = next(s for s in Stop.objects.filter(parent_station_id=stop_id).all()
for s2 in StopTime.objects.filter(trip_id=trip_id).all()
if s.stop_type in s2.stop.stop_type
or s2.stop.stop_type in s.stop_type)
st, _created = StopTime.objects.update_or_create(
id=f"{trip_id}-{stop.id}",
trip_id=trip_id,
stop_id=stop.id,
defaults={
"stop_sequence": stop_sequence,
"arrival_time": datetime.fromtimestamp(stop_time_update.arrival.time,
tz=ZoneInfo("Europe/Paris")) - start_dt,
"departure_time": datetime.fromtimestamp(stop_time_update.departure.time,
tz=ZoneInfo("Europe/Paris")) - start_dt,
"pickup_type": 0 if stop_time_update.departure.time else 1,
"drop_off_type": 0 if stop_time_update.arrival.time else 1,
}
)
elif stop_time_update.schedule_relationship == 1:
st = StopTime.objects.get(Q(stop=stop_id) | Q(stop__parent_station_id=stop_id),
trip_id=trip_id)
if st.pickup_type != 0 or st.drop_off_type != 0:
st.pickup_type = 0
st.drop_off_type = 0
st.save()
else:
st = StopTime.objects.get(Q(stop=stop_id) | Q(stop__parent_station_id=stop_id),
trip_id=trip_id)
if st.stop_sequence != stop_sequence:
st.stop_sequence = stop_sequence
st.save()
st = StopTime.objects.get(trip_id=trip_id, stop_sequence=stop_sequence)
st_update = StopTimeUpdate( st_update = StopTimeUpdate(
trip_update=tu, trip_update=tu,
stop_time=st, stop_time=st,

View File

@ -1,4 +1,4 @@
# Generated by Django 5.0.1 on 2024-02-06 06:59 # Generated by Django 5.0.1 on 2024-02-04 19:58
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models from django.db import migrations, models
@ -35,12 +35,9 @@ class Migration(migrations.Migration):
models.IntegerField( models.IntegerField(
choices=[ choices=[
(0, "Scheduled"), (0, "Scheduled"),
(1, "Added"), (1, "Skipped"),
(2, "Unscheduled"), (2, "No data"),
(3, "Canceled"), (3, "Unscheduled"),
(5, "Replacement"),
(6, "Duplicated"),
(7, "Deleted"),
], ],
default=0, default=0,
verbose_name="Schedule relationship", verbose_name="Schedule relationship",

View File

@ -58,17 +58,7 @@ class ExceptionType(models.IntegerChoices):
REMOVED = 2, _("Removed") REMOVED = 2, _("Removed")
class TripScheduleRelationship(models.IntegerChoices): class ScheduleRelationship(models.IntegerChoices):
SCHEDULED = 0, _("Scheduled")
ADDED = 1, _("Added")
UNSCHEDULED = 2, _("Unscheduled")
CANCELED = 3, _("Canceled")
REPLACEMENT = 5, _("Replacement")
DUPLICATED = 6, _("Duplicated")
DELETED = 7, _("Deleted")
class StopScheduleRelationship(models.IntegerChoices):
SCHEDULED = 0, _("Scheduled") SCHEDULED = 0, _("Scheduled")
SKIPPED = 1, _("Skipped") SKIPPED = 1, _("Skipped")
NO_DATA = 2, _("No data") NO_DATA = 2, _("No data")
@ -209,6 +199,12 @@ class Stop(models.Model):
@property @property
def stop_type(self): def stop_type(self):
train_type = self.id.split('StopPoint:OCE')[1].split('-')[0] train_type = self.id.split('StopPoint:OCE')[1].split('-')[0]
if train_type == "Train TER":
train_type = "TER"
elif train_type == "INTERCITES":
train_type = "INTER-CITÉS"
elif train_type == "INTERCITES de nuit":
train_type = "INTER-CITÉS de nuit"
return train_type return train_type
def __str__(self): def __str__(self):
@ -664,8 +660,8 @@ class TripUpdate(models.Model):
schedule_relationship = models.IntegerField( schedule_relationship = models.IntegerField(
verbose_name=_("Schedule relationship"), verbose_name=_("Schedule relationship"),
choices=TripScheduleRelationship, choices=ScheduleRelationship,
default=TripScheduleRelationship.SCHEDULED, default=ScheduleRelationship.SCHEDULED,
) )
def __str__(self): def __str__(self):
@ -712,8 +708,8 @@ class StopTimeUpdate(models.Model):
schedule_relationship = models.IntegerField( schedule_relationship = models.IntegerField(
verbose_name=_("Schedule relationship"), verbose_name=_("Schedule relationship"),
choices=StopScheduleRelationship, choices=ScheduleRelationship,
default=StopScheduleRelationship.SCHEDULED, default=ScheduleRelationship.SCHEDULED,
) )
def __str__(self): def __str__(self):