コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }