|
@@ -134,6 +134,7 @@ func convertDepartures(c feedConverter) (feedConverter, error) { // O(n:stop_tim
|
|
|
return c, fmt.Errorf("while creating changeOptions file: %w", err)
|
|
|
}
|
|
|
defer changeOptionsFile.Close()
|
|
|
+ defer changeOptionsFile.Sync()
|
|
|
changeOptions := csv.NewWriter(changeOptionsFile)
|
|
|
defer changeOptions.Flush()
|
|
|
headerWritten := false
|
|
@@ -143,6 +144,7 @@ func convertDepartures(c feedConverter) (feedConverter, error) { // O(n:stop_tim
|
|
|
return c, fmt.Errorf("while creating tripsThroughStop file: %w", err)
|
|
|
}
|
|
|
defer tripsThroughStopFile.Close()
|
|
|
+ defer tripsThroughStopFile.Sync()
|
|
|
tripsThroughStop := csv.NewWriter(tripsThroughStopFile)
|
|
|
defer tripsThroughStop.Flush()
|
|
|
err = tripsThroughStop.Write([]string{"stop_id", "trip_id", "sequence"})
|
|
@@ -164,8 +166,9 @@ func convertDepartures(c feedConverter) (feedConverter, error) { // O(n:stop_tim
|
|
|
trip.Id = tripID
|
|
|
switch c.Feed.Flags().Headsign {
|
|
|
case HeadsignTripHeadsing:
|
|
|
- trip.Headsign = record[fields["trip_headsign"]]
|
|
|
+ trip.Headsign = tripRecord[tripsFields["trip_headsign"]]
|
|
|
case HeadsignTripLastStop:
|
|
|
+ // TODO test this case
|
|
|
stopRecord, err := readCsvLine(stopsFile, c.stopsInputIndex[stopID], len(stopsHeader))
|
|
|
if err != nil && err != io.EOF {
|
|
|
return fmt.Errorf("while reading a stops record: %w", err)
|
|
@@ -176,7 +179,7 @@ func convertDepartures(c feedConverter) (feedConverter, error) { // O(n:stop_tim
|
|
|
// TODO translated headsign(-s)
|
|
|
|
|
|
trip.ScheduleID = tripRecord[tripsFields["service_id"]]
|
|
|
- trip.LineID = record[fields["route_id"]]
|
|
|
+ trip.LineID = tripRecord[tripsFields["route_id"]]
|
|
|
fmt.Sscanf(tripRecord[tripsFields["direction_id"]], "%d", &trip.Direction)
|
|
|
|
|
|
bytes, err := bare.Marshal(&trip)
|
|
@@ -199,24 +202,26 @@ func convertDepartures(c feedConverter) (feedConverter, error) { // O(n:stop_tim
|
|
|
for _, template := range []string{"route_short_name", "route_long_name"} {
|
|
|
lineName = strings.Replace(lineName, "{{"+template+"}}", routeRecord[routesFields[template]], -1)
|
|
|
}
|
|
|
- headsign := translateFieldDefault(trip.Headsign, c.feedInfo.Language, c.defaultLanguage, c.translations)
|
|
|
+ /*headsign := translateFieldDefault(trip.Headsign, c.feedInfo.Language, c.defaultLanguage, c.translations)
|
|
|
translatedHeadsigns := translateField(trip.Headsign, c.feedInfo.Language, c.defaultLanguage, c.translations)
|
|
|
- changeOptionsRecord := []string{stopID, routeRecord[routesFields["route_id"]], lineName, headsign}
|
|
|
for _, translatedHeadsign := range translatedHeadsigns {
|
|
|
changeOptionsRecord = append(changeOptionsRecord, translatedHeadsign.Language)
|
|
|
changeOptionsRecord = append(changeOptionsRecord, translatedHeadsign.Value)
|
|
|
- }
|
|
|
+ }*/
|
|
|
if !headerWritten {
|
|
|
changeOptionsHeaderRecord := []string{"stop_id", "route_id", "line_name", "headsign"}
|
|
|
- for i := range translatedHeadsigns {
|
|
|
+ /*for i := range translatedHeadsigns {
|
|
|
changeOptionsHeaderRecord = append(changeOptionsRecord, fmt.Sprintf("language_tag_%d", i))
|
|
|
changeOptionsHeaderRecord = append(changeOptionsRecord, fmt.Sprintf("headsign_%d", i))
|
|
|
- }
|
|
|
+ }*/
|
|
|
err = changeOptions.Write(changeOptionsHeaderRecord)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("while writing changeOptions header: %w", err)
|
|
|
}
|
|
|
+ headerWritten = true
|
|
|
}
|
|
|
+ changeOptionsRecord := []string{stopID, trip.LineID, lineName, trip.Headsign}
|
|
|
+ // FIXME writes garbage
|
|
|
err = changeOptions.Write(changeOptionsRecord)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("while writing changeOptions record: %w", err)
|
|
@@ -292,7 +297,9 @@ func sortOutIndex(fileName string) error {
|
|
|
return fmt.Errorf("while sorting: %w", err)
|
|
|
}
|
|
|
|
|
|
+ result.Sync()
|
|
|
result.Close()
|
|
|
+ os.Rename(fileName, fileName+"_xxx")
|
|
|
err = os.Rename(fileName+"2", fileName)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("while replacing file: %w", err)
|