3 کامیت‌ها 272b8aa331 ... 9743c5933c

نویسنده SHA1 پیام تاریخ
  Adam 9743c5933c undo debug 2 ماه پیش
  Adam Evyčędo 94cf709308 adapt to new URLs in Poznan 2 ماه پیش
  Adam aa1d0e9069 convert stops with less RAM 2 ماه پیش
3فایلهای تغییر یافته به همراه22 افزوده شده و 15 حذف شده
  1. 3 3
      traffic/convert.go
  2. 14 7
      traffic/convert_departures.go
  3. 5 5
      traffic/poznan_ztm.go

+ 3 - 3
traffic/convert.go

@@ -270,14 +270,14 @@ func getGtfsFiles(input ...interface{}) (interface{}, error) {
 	names := []string{}
 	for i, version := range args.missingVersions {
 		name := fmt.Sprintf("%s_%d.zip", version.String(), i)
-		//zipPath := filepath.Join(args.tmpFeedPath, name)
+		zipPath := filepath.Join(args.tmpFeedPath, name)
 		url := version.Link
 		request, err := http.NewRequest("GET", url, nil)
 		if err != nil {
 			return gott.Tuple{args}, fmt.Errorf("while creating request for %s: %w", url, err)
 		}
 		request.Header.Add("If-None-Match", args.etags[url])
-		/*client := http.Client{} // todo timeout
+		client := http.Client{} // todo timeout
 		response, err := client.Do(request)
 		if err != nil {
 			return gott.Tuple{args}, fmt.Errorf("while downloading gtfs %s %w", name, err)
@@ -299,7 +299,7 @@ func getGtfsFiles(input ...interface{}) (interface{}, error) {
 		_, err = io.Copy(file, response.Body)
 		if err != nil {
 			return gott.Tuple{args}, fmt.Errorf("while copying gtfs %s %w", name, err)
-		}*/
+		}
 		names = append(names, name)
 	}
 	args.gtfsFilenames = names

+ 14 - 7
traffic/convert_departures.go

@@ -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)

+ 5 - 5
traffic/poznan_ztm.go

@@ -37,7 +37,7 @@ func (PoznanZtm) getTimezone() *time.Location {
 func (z PoznanZtm) ConvertVehicles() ([]Vehicle, error) {
 	vehicles := []Vehicle{}
 
-	url := "https://ztm.poznan.pl/en/dla-deweloperow/getGtfsRtFile/?file=vehicle_dictionary.csv"
+	url := "https://ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?file=vehicle_dictionary.csv"
 	response, err := z.client.Get(url)
 	if err != nil {
 		return vehicles, fmt.Errorf("ConvertVehicles: cannot GET ‘%s’: %w", url, err)
@@ -104,7 +104,7 @@ func (z PoznanZtm) ConvertVehicles() ([]Vehicle, error) {
 }
 
 func (z PoznanZtm) GetVersions(date time.Time, timezone *time.Location) ([]Version, error) {
-	url := "https://ztm.poznan.pl/en/dla-deweloperow/gtfsFiles"
+	url := "https://www.ztm.poznan.pl/otwarte-dane/gtfsfiles/"
 	response, err := z.client.Get(url)
 	if err != nil {
 		return []Version{}, fmt.Errorf("GetVersions: cannot GET ‘%s’: %w", url, err)
@@ -128,7 +128,7 @@ func (z PoznanZtm) GetVersions(date time.Time, timezone *time.Location) ([]Versi
 		if err != nil {
 			return nil, err
 		}
-		version.Link = "https://ztm.poznan.pl/en/dla-deweloperow/getGTFSFile/?file=" + v
+		version.Link = "https://ztm.poznan.pl/pl/dla-deweloperow/getGTFSFile/?file=" + v
 		versions = append(versions, version)
 	}
 	return versions, nil
@@ -140,8 +140,8 @@ func (PoznanZtm) String() string {
 
 func (PoznanZtm) RealtimeFeeds() map[RealtimeFeedType]string {
 	return map[RealtimeFeedType]string{
-		TRIP_UPDATES:      "https://ztm.poznan.pl/en/dla-deweloperow/getGtfsRtFile/?file=feeds.pb",
-		VEHICLE_POSITIONS: "https://ztm.poznan.pl/en/dla-deweloperow/getGtfsRtFile/?file=feeds.pb",
+		TRIP_UPDATES:      "https://ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?file=feeds.pb",
+		VEHICLE_POSITIONS: "https://ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?file=feeds.pb",
 	}
 }