2 Commits 1cfd8a5beb ... 66952da263

Author SHA1 Message Date
  Adam 66952da263 serve vehicle information with departure 2 months ago
  Adam 1cfd8a5beb serve vehicle information with departure 2 months ago
3 changed files with 9 additions and 3 deletions
  1. 4 0
      api/structs/structs.go
  2. 3 1
      traffic/access.go
  3. 2 2
      traffic/structs/access.go

+ 4 - 0
api/structs/structs.go

@@ -9,13 +9,17 @@ const (
 	VEHICLE_AT_STOP
 	VEHICLE_IN_TRANSIT
 	VEHICLE_DEPARTED
+)
 
+const (
 	CONGESTION_UNKNOWN CongestionLevel = iota
 	CONGESTION_SMOOTH
 	CONGESTION_STOP_AND_GO
 	CONGESTION
 	CONGESTION_SEVERE
+)
 
+const (
 	OCCUPANCY_EMPTY OccupancyStatus = iota
 	OCCUPANCY_MANY_AVAILABLE
 	OCCUPANCY_FEW_AVAILABLE

+ 3 - 1
traffic/access.go

@@ -25,6 +25,7 @@ type getDeparturesResult struct {
 	TimetableHome  string
 	Calendar       []traffic_structs.Schedule
 	DeparturesType traffic_structs.DeparturesType
+	Vehicles       traffic_structs.Vehicles
 
 	Location          *time.Location
 	Datetime          time.Time
@@ -279,7 +280,7 @@ func readDeparture(trafficDeparture traffic_structs.Departure, date time.Time,
 			}
 			vehicle := api_structs.Vehicle{
 				Position: olc.Encode(float64(update.Latitude), float64(update.Longitude), 11),
-				// todo Capabilities:
+				Capabilities: result.Vehicles[traffic_structs.ID(update.VehicleID)].Capabilities,
 				Speed: update.Speed,
 				CongestionLevel: update.CongestionLevel,
 				OccupancyStatus: update.OccupancyStatus,
@@ -345,6 +346,7 @@ func GetDepartures(stopCode traffic_structs.ID, dataHome, feedName string,
 		TimetableHome:  filepath.Join(dataHome, feedName, string(versionCode)),
 		Calendar:       calendar,
 		DeparturesType: departuresType,
+		Vehicles:       vehicles,
 	}
 
 	r, e := gott.NewResult(result).

+ 2 - 2
traffic/structs/access.go

@@ -44,12 +44,12 @@ func ReadCodeIndex(dataHome, feedName string, validity Validity) CodeIndex {
 
 func ReadVehicles(dataHome, feedName string, validity Validity) Vehicles {
 	timetableHome := filepath.Join(dataHome, feedName, string(validity))
-	vehiclesFile, _ := os.Open(filepath.Join(timetableHome, "ix_stop_codes.bare"))
+	vehiclesFile, _ := os.Open(filepath.Join(timetableHome, "vehicles.bare"))
 	defer vehiclesFile.Close()
 
 	vehicles := Vehicles{}
 	var err error = nil
-	for err != nil {
+	for err == nil {
 		vehicle := Vehicle{}
 		err = bare.UnmarshalReader(vehiclesFile, &vehicle)
 		if err == nil {