forked from artonge/go-gtfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
71 lines (60 loc) · 1.58 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gtfs
import (
"errors"
)
func (g *GTFS) GetRoute(routeId string) Route {
for _, r := range g.Routes {
if r.ID == routeId {
return r
}
}
return Route{}
}
func (g *GTFS) GetTrip(tripId string) Trip {
for _, t := range g.Trips {
if t.ID == tripId {
return t
}
}
return Trip{}
}
func (g *GTFS) GetStop(stopID string) Stop {
for _, s := range g.Stops {
if s.ID == stopID {
return s
}
}
return Stop{}
}
func (g *GTFS) GetHeadSign(tripId string, stopId string) string {
trip := g.GetTrip(tripId)
if trip.Headsign != "" {
return trip.Headsign
}
for _, stopTime := range g.StopsTimes {
if stopTime.TripID == tripId && stopTime.StopID == stopId {
return stopTime.StopHeadSign
}
}
return ""
}
func (g *GTFS) GetFareAttribute(fareId string) (FareAttribute, error) {
for _, v := range g.FareAttributes {
if v.FareId == fareId {
return v, nil
}
}
return FareAttribute{}, errors.New("muched fare_attribute not found.")
}
func (g *GTFS) GetFareAttributeFromOD(originId string, destinationId string, routeId string) (FareAttribute, error) {
for _, v := range g.FareRules {
// 条件に一致するか判定
isOriginOk := (originId == v.OriginId) || ("*" == v.OriginId) || ("" == v.OriginId)
isDestinationOk := (destinationId == v.DestinationId) || ("*" == v.DestinationId) || ("" == v.DestinationId)
isRouteIdOk := (v.RouteId == routeId) || (v.RouteId == "*") || (v.RouteId == "")
if isOriginOk && isDestinationOk && isRouteIdOk {
return g.GetFareAttribute(v.FareId)
}
}
return FareAttribute{}, errors.New("muched fare_rule not found.")
}