Some changes
This commit is contained in:
parent
0a854f708a
commit
259b78ebd3
4 changed files with 193 additions and 9 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -81,13 +82,18 @@ type IDFMSchedule struct {
|
|||
}
|
||||
|
||||
type PGSchedule struct {
|
||||
Destination string `json:"destionation"`
|
||||
Destination string `json:"destination"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func convertLineCode(code string) string {
|
||||
return strings.TrimSuffix(strings.Replace(code, "STIF:Line::", "IDFM:", 1), ":")
|
||||
}
|
||||
|
||||
func declareSchedulesRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/schedules/:type/:code/:station/:way", func(c *gin.Context) {
|
||||
t := string(c.Param("type"))
|
||||
line := string(c.Param("code"))
|
||||
station := convertLineType(string(c.Param("station")))
|
||||
|
||||
rurl, err := url.JoinPath(IDFM_BASEURL, "stop-monitoring")
|
||||
|
|
@ -132,11 +138,25 @@ func declareSchedulesRoutes(router *gin.RouterGroup) {
|
|||
|
||||
pgs := []PGSchedule{}
|
||||
for _, vehicule := range schedules.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit {
|
||||
if len(line) > 0 && vehicule.MonitoredVehicleJourney.LineRef.Value != line {
|
||||
continue
|
||||
}
|
||||
|
||||
msg := vehicule.MonitoredVehicleJourney.MonitoredCall.ExpectedDepartureTime.String()
|
||||
|
||||
if t == "metros" || t == "buses" || t == "tramways" {
|
||||
if t == "metros" || t == "buses" || t == "noctiliens" || t == "tramways" {
|
||||
if vehicule.MonitoredVehicleJourney.MonitoredCall.VehicleAtStop {
|
||||
msg = "À quai"
|
||||
if t == "metros" {
|
||||
msg = "Train à quai"
|
||||
} else {
|
||||
msg = "A l'arret"
|
||||
}
|
||||
} else if time.Until(vehicule.MonitoredVehicleJourney.MonitoredCall.ExpectedDepartureTime) < 0 {
|
||||
if t == "metros" {
|
||||
msg = "Train retardé"
|
||||
} else {
|
||||
msg = "…"
|
||||
}
|
||||
} else {
|
||||
msg = fmt.Sprintf("%d mn", int(math.Floor(time.Until(vehicule.MonitoredVehicleJourney.MonitoredCall.ExpectedDepartureTime).Minutes())))
|
||||
}
|
||||
|
|
@ -148,6 +168,8 @@ func declareSchedulesRoutes(router *gin.RouterGroup) {
|
|||
})
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, pgs)
|
||||
c.JSON(http.StatusOK, APIResult(c, map[string][]PGSchedule{
|
||||
"schedules": pgs,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue