private async Task <IEnumerable <PlaceWithETAResponse> > GetPlacesWithEta( Domains.Place[] places, BusTracker busTracker) { IEnumerable <Domains.Place> placesVia = places; if (busTracker.LastDestinationId.HasValue) { placesVia = placesVia.SkipWhile(p => p.Id != busTracker.LastDestinationId.Value).Skip(1); } var distanceResponse = await _googleMapService.GetDuration( new GeoCoordinateDto(busTracker.CurrentLattitude, busTracker.CurrentLongitude), placesVia.Select(p => new GeoCoordinateDto(p.Lattitude, p.Longitude))); if (distanceResponse == null) { return(placesVia.ToList <PlaceWithETAResponse>()); } var distanceMatrixResponse = JsonConvert.DeserializeObject <DistanceMatrixResponse>(distanceResponse); var durations = distanceMatrixResponse.Rows.First().RowElements .Select(r => r.Duration); var placesWithEta = placesVia.Select((place, index) => { var placeResponse = place.To <PlaceWithETAResponse>(); placeResponse.Duration = durations.Take(index + 1).Sum(d => d.Seconds) / 60; return(placeResponse); }); return(placesWithEta); }
public TrackerTests() { _busTracker = new BusTracker { Schedules = new List<Schedule> { _scheduleLubbockDFw, _scheduleHoustonAustin, _scheduleHoustonDfw, _scheduleLubbockAustin } }; }
public TrackerTests() { _busTracker = new BusTracker { Schedules = new List <Schedule> { _scheduleLubbockDFw, _scheduleHoustonAustin, _scheduleHoustonDfw, _scheduleLubbockAustin } }; }
public static void StartBackend() { LoadConfiguration(); Console.Title = string.Format("{0}, CheckDelay: {1}s", Bus.Model.ToString(), Bus.checkDelay); BusCCTV.Start(); BusLogger.Start(); BusTracker.Start(); BusWebInterfaceListener.Start(); while (validConfig) { ConsoleOutput(); Thread.Sleep(Bus.checkDelay * 1000); } }
public async Task <bool> NotifyUsers(BusTracker tracker) { var routeAssociations = _routeAssociationRepository.Set .Where(ra => ra.RouteId == tracker.RouteId) .OrderBy(ra => ra.SequenceNumber) .ToArray(); var nextPlace = routeAssociations .SkipWhile(ra => ra.PlaceId != tracker.LastDestinationId) .Skip(1) .FirstOrDefault()? .Place; var nextPlaceId = nextPlace?.Id; var studentsToNotify = _studentRepository.Set .Where(s => s.PlaceId == tracker.LastDestinationId || s.PlaceId == nextPlaceId) .ToArray(); var studentsToNotifyForCompletedTrip = studentsToNotify.Where(s => s.PlaceId == tracker.LastDestinationId); var deviceIdsForCompletedTrip = studentsToNotifyForCompletedTrip.Select(s => s.FcmId).ToArray(); await SendPushNotification( deviceIdsForCompletedTrip, "eMTe Bus Status", $"Bus reached {tracker.LastDestination.Name}", null); if (nextPlaceId.HasValue) { var studentsToNotifyForNextStop = studentsToNotify.Except(studentsToNotifyForCompletedTrip); var deviceIdsForNextStop = studentsToNotifyForNextStop.Select(s => s.FcmId).ToArray(); await SendPushNotification( deviceIdsForNextStop, "eMTe Bus Status", $"Bus reached {tracker.LastDestination.Name} & Next stop {nextPlace.Name} is yours", null); } return(true); }
public async Task <bool> NotifyBusStarted(BusTracker tracker) { var studentsToNotify = _studentRepository.Set .Where(s => s.RouteId == tracker.RouteId) .Select(s => s.FcmId) .ToArray(); var routeAssociations = _routeAssociationRepository.Set .Where(ra => ra.RouteId == tracker.RouteId) .OrderBy(ra => ra.SequenceNumber) .ToArray(); var origin = routeAssociations[0]; var destination = routeAssociations.Last(); return(await SendPushNotification( studentsToNotify, "eMTe Bus Status", $"Bus started for route '{origin.Place.Name}' to '{destination.Place.Name}'", null)); }