private async static Task AddRidesToSummary(DocumentDbContext docdbCtx, IEnumerable <TrackedRideDocument> rides)
        {
            var summaryCollection = await docdbCtx.GetCollectionAsync(DocumentDbContext.CollectionVehiclesSummary);

            var summary  = await new VehicleSummaryQuery(docdbCtx).ExecuteAsync();
            var vehicles = new List <string>(summary.Vehicles);

            foreach (var ride in rides)
            {
                if (!vehicles.Contains(ride.Device))
                {
                    vehicles.Add(ride.Device);
                }


                var rideSpeed = ride.GpsAverageSpeed;
                summary.AverageSpeed  = ((summary.AverageSpeed * summary.TotalMiles) + (rideSpeed * ride.Miles)) / (summary.TotalMiles + ride.Miles);
                summary.TotalMiles   += ride.Miles;
                summary.TotalSeconds += (ride.EndTime - ride.StartTime).TotalSeconds;
                summary.Breakdowns   += ride.Breakdowns;
            }
            summary.Vehicles      = vehicles.ToArray();
            summary.VehiclesCount = vehicles.Count;
            await docdbCtx.UpdateDocumentAsync(summary, summaryCollection);
        }
Esempio n. 2
0
        private async Task <IEnumerable <ObdEventLine> > ReadOdbsFromFile()
        {
            const int CodeIdx     = 0;
            const int DriverIdIdx = 1;
            const int DeviceIdx   = 2;
            const int DateIdx     = 3;

            Console.WriteLine("Fetching ODBEvents from file data");
            var trackedRides = await _docCtx.GetCollectionAsync(DocumentDbContext.CollectionTrackedRides);

            var obds = new CommaSeparatedFileParser("obdevents.txt").Read().
                       Select(l => new ObdEventLine
            {
                Code     = l[CodeIdx],
                DriverId = int.Parse(l[DriverIdIdx]),
                DeviceId = l[DeviceIdx],
                Date     = l[DateIdx].FromDocumentDbDateTimeString()
            }).OrderBy(o => o.Date);

            return(obds);
        }
Esempio n. 3
0
        private async static Task AddRidesToSummary(DocumentDbContext docdbCtx, IEnumerable<TrackedRideDocument> rides)
        {
            var summaryCollection = await docdbCtx.GetCollectionAsync(DocumentDbContext.CollectionVehiclesSummary);
            var summary = await new VehicleSummaryQuery(docdbCtx).ExecuteAsync();
            var vehicles = new List<string>(summary.Vehicles);
            foreach (var ride in rides)
            {
                if (!vehicles.Contains(ride.Device))
                {
                    vehicles.Add(ride.Device);
                }


                var rideSpeed = ride.GpsAverageSpeed;
                summary.AverageSpeed = ((summary.AverageSpeed * summary.TotalMiles) + (rideSpeed * ride.Miles)) / (summary.TotalMiles + ride.Miles);
                summary.TotalMiles += ride.Miles;
                summary.TotalSeconds += (ride.EndTime - ride.StartTime).TotalSeconds;
                summary.Breakdowns += ride.Breakdowns;
            }
            summary.Vehicles = vehicles.ToArray();
            summary.VehiclesCount = vehicles.Count;
            await docdbCtx.UpdateDocumentAsync(summary, summaryCollection);
        }