当前位置: 首页>>代码示例>>Golang>>正文


Golang logger.GetLogger函数代码示例

本文整理汇总了Golang中github.com/karl-chan/logger.GetLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang GetLogger函数的具体用法?Golang GetLogger怎么用?Golang GetLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SelectIntermediateStops

/* Returns intermediate stops between (end points inclusive) fromId and toId of line and direction*/
func SelectIntermediateStops(line, bound, fromId, toId string) []string {
	var stopPoints []StopPoint

	dbconn.AcquireLock()
	err := db.Select(&stopPoints,
		"SELECT naptan_id FROM line_stop_points "+
			"WHERE line_id=$1 AND bound=$2 AND stop_seq >="+
			"(SELECT stop_seq FROM line_stop_points WHERE "+
			"line_id=$1 AND bound=$2 AND naptan_id=$3 "+
			"ORDER BY stop_seq LIMIT 1) "+
			"AND stop_seq <= "+
			"(SELECT stop_seq FROM line_stop_points WHERE "+
			"line_id=$1 AND bound=$2 AND naptan_id=$4 "+
			"ORDER BY stop_seq DESC LIMIT 1) "+
			"ORDER BY stop_seq ASC",
		line, bound, fromId, toId)
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Panic(err)
	}

	if len(stopPoints) <= 1 {
		logger.GetLogger().Panicf("No intermediate stops between %v and %v for line %v (%v)",
			fromId, toId, line, bound)
	}

	result := make([]string, len(stopPoints))
	for i, v := range stopPoints {
		result[i] = v.NaptanId
	}
	logger.GetLogger().Info("Get intermediate stops (inclusive) from line_stop_points returned: %v", result)
	return result
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:35,代码来源:selectlinestoppoints.go

示例2: mapToPerformanceTestSeries2

func mapToPerformanceTestSeries2(name string, predictedJourneyTimes, actualJourneyTimes map[time.Time]time.Duration) PerformanceTestSeries2 {

	departureTimes := make([]time.Time, len(predictedJourneyTimes))
	durations := make([]time.Duration, len(predictedJourneyTimes))
	i := 0

	/* For calculating the root mean squared error, and mean absolute error */
	diffInSeconds := make([]float64, 0)
	absDiffInSeconds := make([]float64, 0)

	for departureTime, duration := range predictedJourneyTimes {
		departureTimes[i] = departureTime
		durations[i] = duration

		actualJourneyTime := actualJourneyTimes[departureTime]
		diffInSeconds = append(diffInSeconds, (duration - actualJourneyTime).Seconds())
		absDiffInSeconds = append(absDiffInSeconds, math.Abs((duration - actualJourneyTime).Seconds()))

		i++
	}

	rmse, err := statistics.RootMeanSquare(absDiffInSeconds)
	if err != nil {
		/* If lack of data points simply assume 0 */
		logger.GetLogger().Error(err.Error())
		rmse = 0
	}

	mae, err := statistics.Mean(absDiffInSeconds)
	if err != nil {
		/* If lack of data points simply assume 0 */
		logger.GetLogger().Error(err.Error())
		mae = 0
	}

	mad, err := statistics.Median(absDiffInSeconds)
	if err != nil {
		/* If lack of data points simply assume 0 */
		logger.GetLogger().Error(err.Error())
		mad = 0
	}

	variance, err := statistics.Variance(diffInSeconds)
	if err != nil {
		/* If lack of data points simply assume 0 */
		logger.GetLogger().Error(err.Error())
		variance = 0
	}

	return PerformanceTestSeries2{
		SeriesName: name,
		X:          departureTimes,
		Y:          durations,
		Count:      len(durations),
		RMSE:       time.Duration(rmse) * time.Second,
		MAE:        time.Duration(mae) * time.Second,
		MAD:        time.Duration(mad) * time.Second,
		Variance:   time.Duration(variance) * time.Second,
	}
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:60,代码来源:performanceplot2.go

示例3: parseAllTerminusDeparturesFromBody

/* Inserts into channel arrivalsBundle once data is received from tfl and parsed
  map (vehicleId =>
	("line" => line,
	 "bound" => bound,
	 "naptanId" => naptanId of terminus,
	 "expectedDeparture" => expectedDeparture in TfL format,
	))
*/
func parseAllTerminusDeparturesFromBody(body []byte, numPredictionsPerStop *int) {

	type Arrivals struct {
		LineId            string `json:"lineId"`
		VehicleId         string `json:"vehicleId"`
		Bound             string `json:"direction"`
		NaptanId          string `json:"naptanId"`
		TimeStamp         string `json:"timeStamp"`
		ExpectedDeparture string `json:"expectedArrival"`
	}

	var arrivals []Arrivals

	err := json.Unmarshal(body, &arrivals)

	/* Sometimes Tfl returns "Technical error".
	   In such case we skip and return gracefully */
	if err != nil {
		logger.GetLogger().Error("Tfl failed to give proper arrivals response: %v", string(body))
		return
	}

	/* Select all departing terminuses of all lines
	   map (line => (bound => naptanId)) */
	interestedTerminuses := selectdb.SelectAllOrigins()

	result := make(map[string]map[string]string)
	for _, bus := range arrivals {

		/* Check that incoming prediction is not in the past, just in case
		   (n.b. allow 3 min as buffer due to heavy cpu usage causing delay in processing data)  */
		if timeStampHasPassedBy(bus.ExpectedDeparture, 5*time.Minute) {
			// Temporary fix -- sometimes webconn stops unexpectedly, works on restart of program
			// Change (to a new) numPredictionsPerStop to hopefully remedy the issue
			logger.GetLogger().Error("Expected arrival %v of bus %v: %v (%v) is in the past, skipped.",
				bus.ExpectedDeparture, bus.VehicleId, bus.LineId, bus.Bound)
			for {
				newNumPredictionsPerStop := getNumPredictionsPerStop()
				if *numPredictionsPerStop != newNumPredictionsPerStop {
					logger.GetLogger().Info("Changed numPredictionsPerStop from %v to %v", *numPredictionsPerStop, newNumPredictionsPerStop)
					*numPredictionsPerStop = newNumPredictionsPerStop
					break
				}
			}
			logger.UseNewLogFile()
			return
		}

		/* Check if prediction refers to a departing terminus */
		if bus.NaptanId == interestedTerminuses[bus.LineId][bus.Bound] {
			result[bus.VehicleId] = map[string]string{
				"line":              bus.LineId,
				"bound":             bus.Bound,
				"naptanId":          bus.NaptanId,
				"expectedDeparture": bus.ExpectedDeparture,
			}
		}
	}
	insertExpectedDeparturesIntoDB(result)
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:68,代码来源:monitorterminusdepartures.go

示例4: SelectNextBuses

/* Returns the next buses that are approaching a stop given a line and bound after a certain time */
func SelectNextBuses(lineBoundCombination map[string]string, naptanId string, arrivingAfter time.Time) []NextBus {
	var nextBuses []NextBus

	innerQueries := make([]string, 0)

	for line, bound := range lineBoundCombination {
		innerQueries = append(innerQueries,
			fmt.Sprintf("SELECT line, bound, naptan_id, vehicle_id, expected_arrival_time, already_departed "+
				"FROM next_buses "+
				"WHERE naptan_id='%v' AND line='%v' AND bound='%v' AND expected_arrival_time>=TIMESTAMP '%v'",
				naptanId, line, bound, toPsqlTimeStamp(arrivingAfter)))
	}

	sql := fmt.Sprintf("SELECT line, bound, naptan_id, vehicle_id, expected_arrival_time, already_departed "+
		"FROM (%v) AS all_next_buses ORDER BY expected_arrival_time",
		strings.Join(innerQueries, " UNION ALL "))

	logger.GetLogger().Info(sql)
	dbconn.AcquireLock()
	err := db.Select(&nextBuses, sql)
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Panic(err)
	}

	/* Set time zone to UTC */
	for i, v := range nextBuses {
		nextBuses[i].ExpectedArrivalTime = v.ExpectedArrivalTime.In(timezone.Get())
	}
	return nextBuses
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:33,代码来源:selectnextbus.go

示例5: SelectAllLineStopPoints

/* Returns sequences of all naptanIds, grouped by line and bound
   map (line => (bound => []naptanIds)) */
func SelectAllLineStopPoints() map[string]map[string][]string {
	var stopPoints []StopPoint

	dbconn.AcquireLock()
	err := db.Select(&stopPoints,
		"SELECT line_id, bound, stop_seq, naptan_id "+
			"FROM line_stop_points "+
			"ORDER BY line_id, bound, stop_seq")
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Panic(err)
	}

	result := make(map[string]map[string][]string)
	for _, v := range stopPoints {
		lineDetails, exists := result[v.LineId]
		if !exists {
			lineDetails = make(map[string][]string)
		}

		orderedStopPoints, exists := lineDetails[v.Bound]
		if !exists {
			orderedStopPoints = make([]string, 0)
		}

		orderedStopPoints = append(orderedStopPoints, v.NaptanId)
		lineDetails[v.Bound] = orderedStopPoints
		result[v.LineId] = lineDetails
	}
	logger.GetLogger().Info("Get existing line stop points returned: %v", result)
	return result
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:35,代码来源:selectlinestoppoints.go

示例6: SelectStopSeq

/* Returns the stop sequence number, given the line, direction and naptanId of the stop
   Should there be ties, an error is returned */
func SelectStopSeq(line, bound, naptanId string) (int, error) {
	var stopPoints []StopPoint

	dbconn.AcquireLock()
	err := db.Select(&stopPoints,
		"SELECT stop_seq FROM line_stop_points WHERE line_id=$1 AND bound=$2 AND naptan_id=$3",
		line, bound, naptanId)
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Panic(err)
	}

	if len(stopPoints) == 0 {
		logger.GetLogger().Error("Failed to find stop sequence number for stop %v of line %v (%v)",
			naptanId, line, bound)
		return -1, errors.New(
			fmt.Sprintf("Failed to find stop sequence number for stop %v of line %v (%v)",
				naptanId, line, bound))
	}

	if len(stopPoints) > 1 {
		logger.GetLogger().Error("Expected unique stop sequence number for stop %v of line %v (%v), but got: %v",
			naptanId, line, bound, stopPoints)
		return -1, errors.New(
			fmt.Sprintf("Expected unique stop sequence number for stop %v of line %v (%v), but got: %v",
				naptanId, line, bound, stopPoints))
	}

	result := stopPoints[0].StopSeq
	return result, nil
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:34,代码来源:selectlinestoppoints.go

示例7: writePerformanceChart

/* Writes to .html file for resulting performance graph */
func writePerformanceChart(wr io.Writer, charts []PerformanceChart, templatePath string) {

	funcMap := template.FuncMap{
		// Prettifies x and y axes into js format
		"formatXAxis": func(slice []time.Time) string {
			str := "['x'"
			for i := 0; i < len(slice); i++ {
				str += ", " + fmt.Sprintf("new Date(Date.UTC(%v, %v, %v, %v, %v, %v))",
					slice[i].Year(), int(slice[i].Month())-1, slice[i].Day(),
					slice[i].Hour(), slice[i].Minute(), slice[i].Second())
			}
			str += "]"
			return str
		},
		"formatYAxis": func(seriesName string, slice []time.Duration) string {
			str := fmt.Sprintf("['%v'", seriesName)
			for i := 0; i < len(slice); i++ {
				str += ", " + strconv.Itoa(int(slice[i].Minutes()))
			}
			str += "]"
			return str
		},
	}

	t, err := template.New(path.Base(templatePath)).Funcs(funcMap).ParseFiles(templatePath)
	if err != nil {
		logger.GetLogger().Panic(err)
	}

	err = t.Execute(wr, charts)
	if err != nil {
		logger.GetLogger().Panic(err)
	}
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:35,代码来源:performanceplot.go

示例8: parseLinesFromBody

func parseLinesFromBody(body []byte) []interface{} {
	type Line struct {
		Id       string `json:"id"`
		ModeName string `json:"modeName"`
	}

	var lines []Line

	err := json.Unmarshal(body, &lines)

	/* Sometimes Tfl returns "Technical error".
	   In such case we skip and return gracefully */
	if err != nil {
		logger.GetLogger().Panic("Tfl failed to give proper arrivals response: %v", string(body))
	}

	var result []interface{}
	for _, line := range lines {
		if line.ModeName == "bus" {
			result = append(result, line.Id)
		}
	}

	logger.GetLogger().Info("Parsed lines from tfl: %v", result)
	return result
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:26,代码来源:updatelines.go

示例9: blockUntilBusDeparts

/* Blocks here until a bus departs from a station,
   and returns the vehicleId of the bus that departed */
func blockUntilBusDeparts(line, bound, naptanId string) (string, time.Time, error) {
	tflPollInterval := 50 * time.Second

	departureSchedule := make(map[string]string)

	site := fmt.Sprintf("https://api.tfl.gov.uk/Line/%v/Arrivals/%v?direction=%v",
		line, naptanId, bound)

	for _ = range time.Tick(tflPollInterval) {
		var departed bool
		var vehicleId string
		var departureTime time.Time
		var err error

		departed, vehicleId, departureSchedule, departureTime, err = monitorForDeparture(site, departureSchedule, line, bound)
		if err != nil {
			return "", time.Time{}, err
		}
		if departed {
			logger.GetLogger().Info("Vehicle %v of line %v (%v) departed origin %v",
				vehicleId, line, bound, naptanId)
			return vehicleId, departureTime, nil
		}
	}
	logger.GetLogger().Panic("Expected indefinite blocking until departure, but failed for line %v (%v)",
		line, bound)
	return "", time.Time{}, nil
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:30,代码来源:performanceevaluation.go

示例10: createMedian

func createMedian() {
	createFinalMedianSql := "CREATE OR REPLACE FUNCTION _final_median(NUMERIC[]) " +
		"RETURNS NUMERIC AS " +
		"$$ " +
		"SELECT AVG(val) " +
		"FROM ( " +
		"SELECT val " +
		"FROM unnest($1) val " +
		"ORDER BY 1 " +
		"LIMIT  2 - MOD(array_upper($1, 1), 2) " +
		"OFFSET CEIL(array_upper($1, 1) / 2.0) - 1 " +
		") sub; " +
		"$$ " +
		"LANGUAGE 'sql' IMMUTABLE"
	createMedianSql := "CREATE AGGREGATE median(NUMERIC) ( " +
		"SFUNC=array_append, " +
		"STYPE=NUMERIC[], " +
		"FINALFUNC=_final_median, " +
		"INITCOND='{}' " +
		")"

	dbconn.AcquireLock()
	tx, err := db.Begin()
	tx.Exec(createFinalMedianSql)
	tx.Exec(createMedianSql)
	err = tx.Commit()
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Warning(err.Error())
		return
	}
	logger.GetLogger().Info("Function 'median' created successfully")
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:34,代码来源:createfunctions.go

示例11: replaceTimetable

func replaceTimetable(line, bound, origin string, newTimetable map[time.Weekday]map[selectdb.LocalTime]bool) {
	values := make([]string, 0)
	for weekday, departureTimes := range newTimetable {
		for departureTime, _ := range departureTimes {
			values = append(values, fmt.Sprintf("('%v', '%v', '%v', %v, TIME '%02d:%02d:00')",
				line, bound, origin, int(weekday), departureTime.Hour, departureTime.Minute))
		}
	}

	dbconn.AcquireLock()
	tx := db.MustBegin()
	tx.MustExec(fmt.Sprintf("DELETE FROM timetable WHERE line_id='%v' AND bound='%v' AND naptan_id='%v'", line, bound, origin))

	logger.GetLogger().Info(fmt.Sprintf("INSERT INTO timetable (line_id, bound, naptan_id, weekday, departure_time) VALUES %s",
		strings.Join(values, ",")))
	tx.MustExec(
		fmt.Sprintf("INSERT INTO timetable (line_id, bound, naptan_id, weekday, departure_time) VALUES %s",
			strings.Join(values, ",")))
	err := tx.Commit()
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Error(err.Error())
	}
	logger.GetLogger().Info("Replaced timetable for line %v (%v), stop %v", line, bound, origin)
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:26,代码来源:updatetimetable.go

示例12: getRoutePaths

func getRoutePaths(linesToPlot map[string]map[string]map[string]string) map[string][]LatLng {
	routePaths := make(map[string][]LatLng)
	bound := "outbound"

	for line, lineDetails := range linesToPlot {
		fromStop := lineDetails[bound]["fromStop"]
		toStop := lineDetails[bound]["toStop"]
		intermediateStops := selectdb.SelectIntermediateStops(line, bound, fromStop, toStop)

		path := make([]LatLng, len(intermediateStops))

		intermediateStopDetails := selectdb.SelectMultipleStops(intermediateStops)
		for i, stop := range intermediateStops {
			lat, err := strconv.ParseFloat(intermediateStopDetails[stop]["latitude"], 64)
			if err != nil {
				logger.GetLogger().Panic(err)
			}

			lng, err := strconv.ParseFloat(intermediateStopDetails[stop]["longitude"], 64)
			if err != nil {
				logger.GetLogger().Panic(err)
			}

			path[i] = LatLng{
				Lat: lat,
				Lng: lng,
			}
		}
		routePaths[line] = path
	}
	return routePaths
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:32,代码来源:busmapplot.go

示例13: SelectTimetable

/* Returns timetable for specified line, bound and stop in the form of a map
   map (weekday => []("hour" => hour
                    "minute" => minute)) */
func SelectTimetable(line, bound, naptanId string) map[time.Weekday]map[LocalTime]bool {
	var timetable []TimetableEntry

	dbconn.AcquireLock()
	err := db.Select(&timetable,
		"SELECT weekday, departure_time FROM timetable WHERE line_id=$1 AND bound=$2 AND naptan_id=$3 ORDER BY weekday,departure_time",
		line, bound, naptanId)
	dbconn.ReleaseLock()

	if err != nil {
		logger.GetLogger().Panic(err)
	}

	result := make(map[time.Weekday]map[LocalTime]bool)
	for _, entry := range timetable {
		weekday := time.Weekday(entry.Weekday)
		weekdayMap, exists := result[weekday]
		if !exists {
			weekdayMap = make(map[LocalTime]bool, 0)
			result[weekday] = weekdayMap
		}
		weekdayMap[LocalTime{Hour: entry.DepartureTime.Hour(), Minute: entry.DepartureTime.Minute()}] = true
	}
	logger.GetLogger().Info("Get timetable for line %v (%v), stop %v returned: %v", line, bound, naptanId, result)
	return result
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:29,代码来源:selecttimetable.go

示例14: interpolateStops

/* To handle the situation when stops logged from Tfl are not consecutive,
   i.e. fromStop and toStop are > 1 stop apart
   Applies interpolation to estimate neighbouring journey times, and
   updates the values for insertion into database

   @See interpolateTimes for implementation details */
func interpolateStops(line, bound, vehicleId, fromStop, toStop, oldTimeStamp, newTimeStamp, oldTflTimeStamp, newTflTimeStamp string,
	values, skippedStopsValues, rawArrivalTimes *[]string, cachedEntry map[string]string) {

	// Discard if interpolating too many stops (>= 10 stops)
	interpolationThreshold := 10

	// Find intermediate stops
	intermediateStops := selectdb.SelectIntermediateStops(line, bound, fromStop, toStop)
	intermediateStopsLength := len(intermediateStops)
	if intermediateStopsLength <= 2 {
		logger.GetLogger().Panicf("Expected at least one intermediate stop for line %v (%v), between %v and %v. But got none.",
			line, bound, fromStop, toStop)
	}

	if intermediateStopsLength >= interpolationThreshold {
		logger.GetLogger().Error("Bus %v of line %v (%v) skipped too many stops (%v stops), between %v and %v. Aborting interpolation.",
			vehicleId, line, bound, intermediateStopsLength, fromStop, toStop)
		return
	}

	/* Find out interpolated times */
	interpolatedTimes, err := interpolateTimes(line, bound, vehicleId, intermediateStops, oldTimeStamp, newTimeStamp, cachedEntry, rawArrivalTimes)

	if err != nil {
		logger.GetLogger().Error(err.Error())
		return
	}

	for i := 0; i < intermediateStopsLength-1; i++ {
		if interpolatedTimes[i].IsZero() || interpolatedTimes[i+1].IsZero() {
			// Check that record is not invalidated
			continue
		}
		timeDiff := int(interpolatedTimes[i+1].Sub(interpolatedTimes[i]).Seconds())

		*values = append(*values, fmt.Sprintf("('%v', '%v', '%v', '%v', TIMESTAMP '%v', TIMESTAMP '%v', "+
			"'%v', TIMESTAMP '%v', TIMESTAMP '%v', INTERVAL '%v seconds', TRUE)",
			line, bound, vehicleId,
			intermediateStops[i], timeToPsqlTimeStamp(interpolatedTimes[i]), toPsqlTimeStamp(oldTflTimeStamp),
			intermediateStops[i+1], timeToPsqlTimeStamp(interpolatedTimes[i+1]), toPsqlTimeStamp(newTflTimeStamp),
			timeDiff))
	}

	// Strip end points away from intermediate points before inserting into skipped_stops_history
	intermediateStopsEndPointsExclusive := intermediateStops[1 : intermediateStopsLength-1]
	for i, v := range intermediateStopsEndPointsExclusive {
		intermediateStopsEndPointsExclusive[i] = "'" + v + "'"
	}

	*skippedStopsValues = append(*skippedStopsValues,
		fmt.Sprintf("('%v', '%v', '%v', '%v', TIMESTAMP '%v', TIMESTAMP '%v', '%v', TIMESTAMP '%v', TIMESTAMP '%v', ARRAY[%v], %v)",
			line, bound, vehicleId,
			intermediateStops[0], timeToPsqlTimeStamp(interpolatedTimes[0]), toPsqlTimeStamp(oldTflTimeStamp),
			intermediateStops[intermediateStopsLength-1], timeToPsqlTimeStamp(interpolatedTimes[intermediateStopsLength-1]), toPsqlTimeStamp(newTflTimeStamp),
			strings.Join(intermediateStopsEndPointsExclusive, ","), len(intermediateStopsEndPointsExclusive)))
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:62,代码来源:monitorline.go

示例15: parseLineStopPointsFromBody

func parseLineStopPointsFromBody(body []byte) ([]string, map[string]map[string]string) {

	type StopPoint struct {
		Id        string  `json:"id"`
		IcsId     string  `json:"icsId"`
		StationId string  `json:"stationId"`
		Name      string  `json:"name"`
		Latitude  float64 `json:"lat"`
		Longitude float64 `json:"lon"`
	}
	type StopPointSequences struct {
		StopPt []StopPoint `json:"stopPoint"`
	}
	type Line struct {
		IsOutboundOnly bool                 `json:"isOutboundOnly"`
		LineId         string               `json:"lineId"`
		Direction      string               `json:"direction"`
		StopSequence   []StopPointSequences `json:"stopPointSequences"`
	}

	var line Line
	err := json.Unmarshal(body, &line)
	if err != nil {
		logger.GetLogger().Panicf("Tfl failed to give proper body: %v", string(body))
	}

	if line.IsOutboundOnly && line.Direction == "inbound" {
		logger.GetLogger().Info("Line %v is outbound only", line.LineId)
		return nil, nil
	}

	if len(line.StopSequence) == 0 {
		logger.GetLogger().Error("Failed to parse stop sequence for line %v (%v)", line.LineId, line.Direction)
		return nil, nil
	}

	stopPoints := line.StopSequence[0].StopPt

	result := make([]string, len(stopPoints))
	/* Get also stop info including name, icscode, lat, lng */
	stopInfos := make(map[string]map[string]string)
	for i, stopPoint := range stopPoints {
		result[i] = stopPoint.Id
		stopInfos[stopPoint.Id] = map[string]string{
			"name":          stopPoint.Name,
			"icscode":       stopPoint.IcsId,
			"latitude":      strconv.FormatFloat(stopPoint.Latitude, 'f', -1, 64),
			"longitude":     strconv.FormatFloat(stopPoint.Longitude, 'f', -1, 64),
			"stationNaptan": stopPoint.StationId,
		}
	}
	logger.GetLogger().Info("Parsed line %v (%v) for stops: %v", line.LineId, line.Direction, result)

	return result, stopInfos
}
开发者ID:karl-chan,项目名称:Active_Delay_Warning_Transport_App,代码行数:55,代码来源:updatelinestoppoints.go


注:本文中的github.com/karl-chan/logger.GetLogger函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。