Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronClaydon committed Nov 8, 2024
1 parent bc98f6f commit 9ecba38
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 72 deletions.
44 changes: 23 additions & 21 deletions pkg/dataimporter/formats/gtfs/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,51 +119,53 @@ func (r *Realtime) Import(dataset datasets.DataSet, datasource *ctdf.DataSource)

timeframe := timeFrameDateTime.Format("2006-01-02")

locationEvent := vehicletracker.VehicleLocationEvent{
locationEvent := vehicletracker.VehicleUpdateEvent{
LocalID: fmt.Sprintf("%s-realtime-%s-%s", dataset.Identifier, timeframe, tripID),
IdentifyingInformation: map[string]string{
"TripID": tripID,
"RouteID": trip.GetRouteId(),
"LinkedDataset": dataset.LinkedDataset,
},
SourceType: "GTFS-RT",
Timeframe: timeframe,
VehicleLocationUpdate: &vehicletracker.VehicleLocationUpdate{
Timeframe: timeframe,
},
DataSource: datasource,
RecordedAt: recordedAtTime,
}

if vehiclePosition != nil {
if vehiclePosition.OccupancyPercentage != nil {
locationEvent.Occupancy.OccupancyAvailable = true
locationEvent.Occupancy.ActualValues = true
locationEvent.VehicleLocationUpdate.Occupancy.OccupancyAvailable = true
locationEvent.VehicleLocationUpdate.Occupancy.ActualValues = true

locationEvent.Occupancy.TotalPercentageOccupancy = int(vehiclePosition.GetOccupancyPercentage())
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = int(vehiclePosition.GetOccupancyPercentage())
}

if vehiclePosition.OccupancyStatus != nil {
switch vehiclePosition.GetOccupancyStatus() {
case gtfs.VehiclePosition_EMPTY:
locationEvent.Occupancy.TotalPercentageOccupancy = 0
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 0
case gtfs.VehiclePosition_MANY_SEATS_AVAILABLE:
locationEvent.Occupancy.TotalPercentageOccupancy = 30
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 30
case gtfs.VehiclePosition_FEW_SEATS_AVAILABLE:
locationEvent.Occupancy.TotalPercentageOccupancy = 50
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 50
case gtfs.VehiclePosition_STANDING_ROOM_ONLY:
locationEvent.Occupancy.TotalPercentageOccupancy = 70
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 70
case gtfs.VehiclePosition_CRUSHED_STANDING_ROOM_ONLY:
locationEvent.Occupancy.TotalPercentageOccupancy = 80
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 80
case gtfs.VehiclePosition_FULL:
locationEvent.Occupancy.TotalPercentageOccupancy = 90
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 90
case gtfs.VehiclePosition_NOT_ACCEPTING_PASSENGERS:
locationEvent.Occupancy.TotalPercentageOccupancy = 100
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 100
case gtfs.VehiclePosition_NO_DATA_AVAILABLE:
locationEvent.Occupancy.TotalPercentageOccupancy = 10
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 10
case gtfs.VehiclePosition_NOT_BOARDABLE:
locationEvent.Occupancy.TotalPercentageOccupancy = 100
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 100
}

locationEvent.Occupancy.OccupancyAvailable = true
locationEvent.Occupancy.ActualValues = false
locationEvent.VehicleLocationUpdate.Occupancy.OccupancyAvailable = true
locationEvent.VehicleLocationUpdate.Occupancy.ActualValues = false
}

if vehiclePosition.CongestionLevel != nil {
Expand All @@ -186,23 +188,23 @@ func (r *Realtime) Import(dataset datasets.DataSet, datasource *ctdf.DataSource)
})
}

locationEvent.Location = ctdf.Location{
locationEvent.VehicleLocationUpdate.Location = ctdf.Location{
Type: "Point",
Coordinates: []float64{
float64(vehiclePosition.Position.GetLongitude()),
float64(vehiclePosition.Position.GetLatitude()),
},
}

locationEvent.Bearing = float64(vehiclePosition.Position.GetBearing())
locationEvent.VehicleIdentifier = vehiclePosition.Vehicle.GetId()
locationEvent.VehicleLocationUpdate.Bearing = float64(vehiclePosition.Position.GetBearing())
locationEvent.VehicleLocationUpdate.VehicleIdentifier = vehiclePosition.Vehicle.GetId()

withLocation += 1
}

if tripUpdate != nil {
for _, stopTimeUpdate := range tripUpdate.GetStopTimeUpdate() {
locationEvent.StopUpdates = append(locationEvent.StopUpdates, vehicletracker.VehicleLocationEventStopUpdate{
locationEvent.VehicleLocationUpdate.StopUpdates = append(locationEvent.VehicleLocationUpdate.StopUpdates, vehicletracker.VehicleLocationEventStopUpdate{
StopID: fmt.Sprintf("%s-stop-%s", dataset.LinkedDataset, stopTimeUpdate.GetStopId()),
ArrivalTime: time.Unix(stopTimeUpdate.GetArrival().GetTime(), 0),
DepartureTime: time.Unix(stopTimeUpdate.GetDeparture().GetTime(), 0),
Expand All @@ -211,7 +213,7 @@ func (r *Realtime) Import(dataset datasets.DataSet, datasource *ctdf.DataSource)
})
}

locationEvent.VehicleIdentifier = tripUpdate.Vehicle.GetId()
locationEvent.VehicleLocationUpdate.VehicleIdentifier = tripUpdate.Vehicle.GetId()

withTripUpdate += 1
}
Expand Down
36 changes: 19 additions & 17 deletions pkg/dataimporter/formats/siri_vm/siri_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func SubmitToProcessQueue(queue rmq.Queue, vehicle *VehicleActivity, dataset dat
vehicleJourneyRef,
)

locationEvent := vehicletracker.VehicleLocationEvent{
locationEvent := vehicletracker.VehicleUpdateEvent{
LocalID: localJourneyID,
IdentifyingInformation: map[string]string{
"ServiceNameRef": vehicle.MonitoredVehicleJourney.LineRef,
Expand All @@ -91,26 +91,28 @@ func SubmitToProcessQueue(queue rmq.Queue, vehicle *VehicleActivity, dataset dat
"LinkedDataset": dataset.LinkedDataset,
},
SourceType: "siri-vm",
Location: ctdf.Location{
Type: "Point",
Coordinates: []float64{
vehicle.MonitoredVehicleJourney.VehicleLocation.Longitude,
vehicle.MonitoredVehicleJourney.VehicleLocation.Latitude,
VehicleLocationUpdate: &vehicletracker.VehicleLocationUpdate{
Location: ctdf.Location{
Type: "Point",
Coordinates: []float64{
vehicle.MonitoredVehicleJourney.VehicleLocation.Longitude,
vehicle.MonitoredVehicleJourney.VehicleLocation.Latitude,
},
},
Bearing: vehicle.MonitoredVehicleJourney.Bearing,
VehicleIdentifier: vehicleRef,
Timeframe: timeframe,
},
Bearing: vehicle.MonitoredVehicleJourney.Bearing,
VehicleIdentifier: vehicleRef,
Timeframe: timeframe,
DataSource: datasource,
RecordedAt: recordedAtTime,
DataSource: datasource,
RecordedAt: recordedAtTime,
}

// Calculate occupancy
if vehicle.Extensions.VehicleJourney.SeatedOccupancy != 0 {
totalCapacity := vehicle.Extensions.VehicleJourney.SeatedCapacity + vehicle.Extensions.VehicleJourney.WheelchairCapacity
totalOccupancy := vehicle.Extensions.VehicleJourney.SeatedOccupancy + vehicle.Extensions.VehicleJourney.WheelchairOccupancy

locationEvent.Occupancy = ctdf.RealtimeJourneyOccupancy{
locationEvent.VehicleLocationUpdate.Occupancy = ctdf.RealtimeJourneyOccupancy{
OccupancyAvailable: true,
ActualValues: true,

Expand All @@ -127,21 +129,21 @@ func SubmitToProcessQueue(queue rmq.Queue, vehicle *VehicleActivity, dataset dat
}

if totalCapacity > 0 && totalOccupancy > 0 {
locationEvent.Occupancy.TotalPercentageOccupancy = int((float64(totalOccupancy) / float64(totalCapacity)) * 100)
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = int((float64(totalOccupancy) / float64(totalCapacity)) * 100)
}
} else if vehicle.MonitoredVehicleJourney.Occupancy != "" {
locationEvent.Occupancy = ctdf.RealtimeJourneyOccupancy{
locationEvent.VehicleLocationUpdate.Occupancy = ctdf.RealtimeJourneyOccupancy{
OccupancyAvailable: true,
ActualValues: false,
}

switch vehicle.MonitoredVehicleJourney.Occupancy {
case "full":
locationEvent.Occupancy.TotalPercentageOccupancy = 100
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 100
case "standingAvailable":
locationEvent.Occupancy.TotalPercentageOccupancy = 75
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 75
case "seatsAvailable":
locationEvent.Occupancy.TotalPercentageOccupancy = 40
locationEvent.VehicleLocationUpdate.Occupancy.TotalPercentageOccupancy = 40
}
}

Expand Down
Loading

0 comments on commit 9ecba38

Please sign in to comment.