Exemple #1
0
        private RidesStatisticsDto GetRideStatistics(DocumentCollection collection, string sql)
        {
            var rides = DocumentContext.CreateDocumentQueryFromSQL(collection,
                                                                   sql).
                        ToList();

            var statistics = new RidesStatisticsDto();
            var count      = 0;

            foreach (dynamic rideData in rides)
            {
                statistics.Breakdowns += rideData.Breakdowns;
                statistics.AvgSpeed    = ((statistics.Miles * statistics.AvgSpeed) + (rideData.Miles * rideData.GpsAverageSpeed)) / (statistics.Miles + rideData.Miles);
                statistics.Miles      += rideData.Miles;
                statistics.Items       = ++count;
            }


            return(statistics);
        }
        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);
        }