func updateDelayedRoutesEstimates() { delays := selectdb.SelectDelays() /* Find out affected lines and bounds */ affectedLineBounds := extractAffectedLinesBoundsFromDelays(delays) logger.GetLogger().Info("Affected line bounds: %v", affectedLineBounds) /* Find out TfL estimates */ tflEstimates := getTflEstimates(affectedLineBounds) logger.GetLogger().Info("Tfl estimates: %v", tflEstimates) routeDurations := getRouteDurations(affectedLineBounds) logger.GetLogger().Info("Route durations: %v", routeDurations) insertRouteDurationsIntoDB(routeDurations, tflEstimates) }
func getDelayedSections() []DelayedSection { delayedSections := make([]DelayedSection, 0) /* Batch select everything from database */ delays := selectdb.SelectDelays() allStopDetails := extractAllStopDetailsFromDelays(delays) allAffectedLines, allAffectedLineBounds := extractAllAffectedLineBounds(delays) for fromStop, fromStopDetails := range delays { for toStop, toStopDetails := range fromStopDetails { historicAverage := toStopDetails["historicEstimate"] realTimeAverage := toStopDetails["realTimeEstimate"] numBuses := toStopDetails["delayCount"] lastUpdated := time.Unix(toStopDetails["lastUpdated"], 0) fromName := allStopDetails[fromStop]["name"] fromLat := allStopDetails[fromStop]["latitude"] fromLng := allStopDetails[fromStop]["longitude"] toName := allStopDetails[toStop]["name"] toLat := allStopDetails[toStop]["latitude"] toLng := allStopDetails[toStop]["longitude"] affectedLines := allAffectedLines[fromStop][toStop] affectedLineBounds := allAffectedLineBounds[fromStop][toStop] delayedSections = append(delayedSections, DelayedSection{ AffectedLines: affectedLines, AffectedLineBounds: affectedLineBounds, FromName: fromName, FromLat: fromLat, FromLng: fromLng, FromNaptan: fromStop, ToName: toName, ToLat: toLat, ToLng: toLng, ToNaptan: toStop, HistoricAverage: historicAverage, RealTimeAverage: realTimeAverage, NumBuses: numBuses, LastUpdated: lastUpdated, }) } } return delayedSections }