Commit a17b8664 authored by Janne Koschinski's avatar Janne Koschinski

Merge realtime and plan data

parent e646a549
......@@ -133,33 +133,19 @@ func main() {
log.Fatal(err)
return
}
if err = returnJson(w, timetable); err != nil {
var realtime bahn.Timetable
if realtime, err = apiClient.RealtimeAll(evaId, date); err != nil {
log.Fatal(err)
return
}
})
http.HandleFunc("/realtime/", func(w http.ResponseWriter, r *http.Request) {
var err error
_, rawEvaId := path.Split(r.URL.Path)
rawEvaId = strings.TrimSpace(rawEvaId)
var evaId int64
if evaId, err = strconv.ParseInt(rawEvaId, 10, 64); err != nil {
log.Fatal(err)
return
}
var date time.Time
if date, err = time.Parse(time.RFC3339, strings.TrimSpace(r.FormValue("time"))); err != nil {
date = time.Now()
realtimeData := make(map[string]*bahn.TimetableStop)
for i := range realtime.Stops {
stop := realtime.Stops[i]
realtimeData[stop.StopId] = &stop
}
var timetable bahn.Timetable
if timetable, err = apiClient.RealtimeAll(evaId, date); err != nil {
log.Fatal(err)
return
for i := range timetable.Stops {
stop := &timetable.Stops[i]
MergeTimetableStop(stop, realtimeData[stop.StopId])
}
if err = returnJson(w, timetable); err != nil {
......
package main
import (
"git.kuschku.de/justjanne/bahn-api"
)
func MergeTimetableStop(data *bahn.TimetableStop, realtime *bahn.TimetableStop) {
if data == nil || realtime == nil {
return
}
data.Messages = realtime.Messages
MergeTripLabel(&data.TripLabel, &realtime.TripLabel)
MergeTimetableStop(data.Ref, realtime.Ref)
MergeEvent(data.Arrival, realtime.Arrival)
MergeEvent(data.Departure, realtime.Departure)
data.HistoricDelays = realtime.HistoricDelays
data.HistoricPlatformChanges = realtime.HistoricPlatformChanges
data.Connections = realtime.Connections
}
func MergeTripLabel(data *bahn.TripLabel, realtime *bahn.TripLabel) {
if data == nil || realtime == nil {
return
}
data.Messages = realtime.Messages
}
func MergeEvent(data *bahn.Event, realtime *bahn.Event) {
if data == nil || realtime == nil {
return
}
data.Messages = realtime.Messages
data.ChangedPlatform = realtime.ChangedPlatform
data.ChangedTime = realtime.ChangedTime
data.ChangedPath = realtime.ChangedPath
data.ChangedDestination = realtime.ChangedDestination
data.ChangedStatus = realtime.ChangedStatus
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment