public async Task <VehiclesSummaryDocument> ExecuteAsync() { var ssql = string.Format("SELECT * FROM c"); var collection = await DocumentContext.GetCollectionAsync(DocumentDbContext.CollectionVehiclesSummary); var data = DocumentContext.CreateDocumentQuery <VehiclesSummaryDocument>(collection, ssql).ToArray(); var summary = data.SingleOrDefault(); return(summary ?? new VehiclesSummaryDocument() { Id = Guid.NewGuid().ToString(), Vehicles = new string[] { } }); //var items = 0; //double totalSeconds = 0; //var codes = new List<string>(); //foreach (var tr in data) //{ // items++; // totalSeconds += (tr.EndTime - tr.StartTime).TotalSeconds; // summary.TotalMiles += tr.Miles; // summary.Breakdowns += tr.Breakdowns; // if (!codes.Contains(tr.Device)) // { // codes.Add(tr.Device); // } //} //summary.AverageSpeed = summary.TotalMiles / totalSeconds * 3600.0; //summary.Accidents = 0; //summary.VehiclesCount = codes.Count; //summary.TotalSeconds = totalSeconds; //return summary; }
public async Task <IEnumerable <RatedDriverDto> > ExecuteAsync() { var collection = await DocumentContext.GetCollectionAsync(DocumentDbContext.CollectionDrivingStyles); var data = DocumentContext.CreateDocumentQuery <RatedDriverDto>(collection, "SELECT * FROM c") .ToList() .OrderByDescending(x => x.ClassificationAvg) .Take(DesiredDrivers); return(data); }
public async Task <IEnumerable <TrackedRideDocument> > ExecuteAsync() { var collection = await DocumentContext.GetCollectionAsync(DocumentDbContext.CollectionTrackedRides); var sql = string.Format("SELECT {0} from c where c.Device='{1}' {2}", _fields.Any() ? string.Join(",", _fields) : "*", DeviceId, AdditionalWhereClausule()); var rides = DocumentContext.CreateDocumentQuery <TrackedRideDocument>(collection, sql).ToList(); return(rides); }
public async Task <Tuple <RidesStatisticsDto, RidesStatisticsDto> > ExecuteAsync() { var collection = await DocumentContext.GetCollectionAsync(DocumentDbContext.CollectionTrackedRides); var driverRidesSql = "SELECT c.Miles, c.GpsAverageSpeed, c.Breakdowns FROM c where c.DriverId = " + DriverId; var driverStats = GetRideStatistics(collection, driverRidesSql); RidesStatisticsDto allStats = null; if (GetGlobalStatisticsAlso) { var allRidesSql = "SELECT c.Miles, c.GpsAverageSpeed, c.Breakdowns FROM c"; allStats = GetRideStatistics(collection, allRidesSql); } return(new Tuple <RidesStatisticsDto, RidesStatisticsDto>(item1: driverStats, item2: allStats)); }
public async Task <DrivingStyleDto> ExecuteAsync() { var stylesCollection = await DocumentContext.GetCollectionAsync(DocumentDbContext.CollectionDrivingStyles); var driverStyleDataItems = DocumentContext.CreateDocumentQueryFromSQL(stylesCollection, "select c.ClassificationAvg, c.Classifications from c where c.DriverId = " + DriverId).ToList(); dynamic driverStyleData = driverStyleDataItems.FirstOrDefault(); var driverStatisticsQuery = new DriverStatisticsQuery(DocumentContext) { DriverId = DriverId, GetGlobalStatisticsAlso = false }; var statistics = await driverStatisticsQuery.ExecuteAsync(); var driverStatistics = statistics.Item1; var style = new DrivingStyleDto(); if (driverStatistics != null) { style.Breakdowns = driverStatistics.Breakdowns <= 10 ? (int)driverStatistics.Breakdowns : 10; style.Speed = DrivingStyleDto.SpeedFromAvgSpeed(driverStatistics.AvgSpeed); if (driverStatistics.Items > 0) { style.Profiability = 10 - (int)(driverStatistics.Breakdowns / driverStatistics.Items); } } if (driverStyleData != null) { style.AvgStyle = driverStyleData.ClassificationAvg; style.Consumption = (int)driverStyleData.ClassificationAvg; style.Aggressiveness = 10 - (int)driverStyleData.ClassificationAvg; style.Brakes = (int)driverStyleData.ClassificationAvg; } return(style); }