Skip to content

Commit

Permalink
#9 PoC implementation for loading flights from GTFS / skyalps
Browse files Browse the repository at this point in the history
  • Loading branch information
clezag committed Dec 16, 2024
1 parent 47934db commit 9dcc8e4
Show file tree
Hide file tree
Showing 22 changed files with 82,074 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
paths:
- "src/**"
- "infrastructure/**"
- "test/**"
- "testdata/**"
- ".github/workflows/main.yml"

env:
Expand Down
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SPDX-PackageSupplier = "NOI Techpark <[email protected]>"
SPDX-PackageDownloadLocation = "https://github.com/noi-techpark/transmodel-api"

[[annotations]]
path = [".github/**", "infrastructure/**", ".gitignore", ".gitmodules", ".pre-commit-config.yaml", "LICENSE.md", ".env.example", "mvnw", "mvnw.cmd", ".mvn/**", "**.properties", "src/main/resources/db/migration/**", "src/go.mod", "src/go.sum", "calls.http", "src/resources/**.csv", "**/test/**.json"]
path = [".github/**", "infrastructure/**", ".gitignore", ".gitmodules", ".pre-commit-config.yaml", "LICENSE.md", ".env.example", "mvnw", "mvnw.cmd", ".mvn/**", "**.properties", "src/main/resources/db/migration/**", "src/go.mod", "src/go.sum", "calls.http", "src/resources/**.csv", "**/testdata/**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "(c) NOI Techpark <[email protected]>"
SPDX-License-Identifier = "CC0-1.0"
2 changes: 2 additions & 0 deletions calls.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ GET {{host}}/health
GET {{host}}/netex/parking
### static NeTEx mobility sharing data
GET {{host}}/netex/sharing
### static NeTEx flight data
GET {{host}}/netex/flights
### SIRI-FM real time parking availability. Station ID as a parameter
GET {{host}}/siri/fm/115

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
volumes:
- ./src:/code
- pkg:/go/pkg/mod
- ./src/provider/testdata/skyalps.xml:/shared/skyalps.xml
working_dir: /code
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CMD ["go", "test", "./..."]
FROM alpine:3.20 as build
# again, libc6 missing on host. Remove this once we are on newer hosts (read: kubernetes)
RUN apk add gcompat
WORKDIR app
WORKDIR /app
EXPOSE 8080
COPY src/main main
COPY src/config/ config/
Expand Down
8 changes: 6 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {
r.GET("/netex", netexEndpoint(netexAll))
r.GET("/netex/parking", netexEndpoint(netexParking))
r.GET("/netex/sharing", netexEndpoint(netexSharing))
r.GET("/netex/flights", netexEndpoint(netexFlights))
r.GET("/siri-lite/facility-monitoring", siriLite(siriFM))
r.GET("/siri-lite/facility-monitoring/parking", siriLite(siriFMParking))
r.GET("/siri-lite/facility-monitoring/sharing", siriLite(siriFMSharing))
Expand Down Expand Up @@ -91,14 +92,14 @@ func netexEndpoint(fn netexFn) func(*gin.Context) {
c.AbortWithError(http.StatusInternalServerError, err)
}
n := netex.NewNetexFrame()
n.DataObjects.Frames = append(n.DataObjects.Frames, comp...)
n.DataObjects = append(n.DataObjects, comp...)
prettyXML(c, http.StatusOK, n)
}
}

func netexAll() ([]netex.CompositeFrame, error) {
ret := []netex.CompositeFrame{}
for _, s := range []netexFn{netexParking, netexSharing} {
for _, s := range []netexFn{netexParking, netexSharing, netexFlights} {
sr, err := s()
if err != nil {
return ret, err
Expand All @@ -114,6 +115,9 @@ func netexParking() ([]netex.CompositeFrame, error) {
func netexSharing() ([]netex.CompositeFrame, error) {
return netex.GetSharing(provider.SharingBikesStatic, provider.SharingCarsStatic)
}
func netexFlights() ([]netex.CompositeFrame, error) {
return netex.GetFlights(provider.FlightsStatic)
}

type siriFn func(siri.Query) (siri.Siri, error)

Expand Down
94 changes: 94 additions & 0 deletions src/netex/flights.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: NOI Techpark <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

package netex

type StFlightData struct {
Operators []Operator
StopPlaces []StopPlace
ServiceCalendars []ServiceCalendar
Routes []Route
Lines []Line
ScheduledStopPoints []ScheduledStopPoint
ServiceLinks []ServiceLink
StopAssignments []PassengerStopAssignment
JourneyPatterns []ServiceJourneyPattern
VehicleJourneys []ServiceJourney
}

type StFlights interface {
StFlights() (StFlightData, error)
}

func GetFlights(ps []StFlights) ([]CompositeFrame, error) {
ret := []CompositeFrame{}

apd := StFlightData{}

for _, p := range ps {
pd, err := p.StFlights()
if err != nil {
return ret, err
}
apd.Operators = append(apd.Operators, pd.Operators...)
apd.StopPlaces = append(apd.StopPlaces, pd.StopPlaces...)
apd.ServiceCalendars = append(apd.ServiceCalendars, pd.ServiceCalendars...)
apd.Routes = append(apd.Routes, pd.Routes...)
apd.Lines = append(apd.Lines, pd.Lines...)
apd.ScheduledStopPoints = append(apd.ScheduledStopPoints, pd.ScheduledStopPoints...)
apd.ServiceLinks = append(apd.ServiceLinks, pd.ServiceLinks...)
apd.StopAssignments = append(apd.StopAssignments, pd.StopAssignments...)
apd.JourneyPatterns = append(apd.JourneyPatterns, pd.JourneyPatterns...)
apd.VehicleJourneys = append(apd.VehicleJourneys, pd.VehicleJourneys...)
}

ret = append(ret, compFlights(apd))

return ret, nil
}

func compFlights(pd StFlightData) CompositeFrame {
var ret CompositeFrame
ret.Defaults()
ret.Id = CreateFrameId("CompositeFrame_EU_PI_STOP_OFFER", "FLIGHTS", "ita")
ret.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_LINE_OFFER")

site := siteFrame()
site.StopPlaces = pd.StopPlaces
ret.Frames.Frames = append(ret.Frames.Frames, &site)

res := ResourceFrame{}
res.Id = CreateFrameId("ResourceFrame_EU_PI_MOBILITY", "ita")
res.Version = "1"
res.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_COMMON")
res.Operators = &pd.Operators
ret.Frames.Frames = append(ret.Frames.Frames, &res)

ser := ServiceFrame{}
ser.Id = CreateFrameId("ServiceFrame_EU_PI_NETWORK", "ita")
ser.Version = "1"
ser.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_NETWORK")
ser.JourneyPatterns = append(ser.JourneyPatterns, pd.JourneyPatterns...)
ser.Lines = append(ser.Lines, pd.Lines...)
ser.Routes = append(ser.Routes, pd.Routes...)
ser.ScheduledStopPoints = append(ser.ScheduledStopPoints, pd.ScheduledStopPoints...)
ser.ServiceLinks = append(ser.ServiceLinks, pd.ServiceLinks...)
ser.StopAssignments = append(ser.StopAssignments, pd.StopAssignments...)
ret.Frames.Frames = append(ret.Frames.Frames, ser)

cal := ServiceCalendarFrame{}
cal.Id = CreateFrameId("ServiceCalendarFrame_EU_PI_CALENDAR", "ita")
cal.Version = "1"
cal.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_CALENDAR")
cal.ServiceCalendar = append(cal.ServiceCalendar, pd.ServiceCalendars...)
ret.Frames.Frames = append(ret.Frames.Frames, cal)

tim := TimetableFrame{}
tim.Id = CreateFrameId("TimetableFrame_EU_PI_TIMETABLE", "ita")
tim.Version = "1"
tim.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_TIMETABLE")
tim.VehicleJourneys = append(tim.VehicleJourneys, pd.VehicleJourneys...)
ret.Frames.Frames = append(ret.Frames.Frames, tim)

return ret
}
Loading

0 comments on commit 9dcc8e4

Please sign in to comment.