Esempio n. 1
0
        public async Task SaveTimeZonePreference(string abbreviation, ulong discordUserId)
        {
            var timePref = await _plogDbContext.Times.FirstOrDefaultAsync(t => t.DiscordUserId == discordUserId);

            if (timePref == null)
            {
                timePref = new TimeZonePreference
                {
                    DiscordUserId = discordUserId,
                    TimeZone      = abbreviation
                };
                _plogDbContext.Add(timePref);
            }
            else
            {
                timePref.TimeZone = abbreviation;
                _plogDbContext.Update(timePref);
            }

            await _plogDbContext.SaveChangesAsync();
        }
Esempio n. 2
0
        public ICollection <TerminalArrivalEstimation> GetArrivalEstimations(Plan plan, IEnumerable <int> locationIds, bool recalculateStatistics = true, TimeZonePreference timeZone = TimeZonePreference.Utc)
        {
            var result = new List <TerminalArrivalEstimation>();

            if (plan != null)
            {
                // force recalculation of statistics if requested or if DriverPlan contains a Metric object that is null
                if (recalculateStatistics ||
                    (plan.DriverPlans.Any() && plan.DriverPlans.Where(p => p.RouteSegmentMetrics == null).ToList().Any()))
                {
                    _planGenerator.RecalculatePlanStatistics(plan);
                }

                foreach (var driverPlans in plan.DriverPlans)
                {
                    var driverMetrics = driverPlans.RouteSegmentMetrics.ToList();
                    for (int i = 0; i < driverMetrics.Count; i++)
                    {
                        var m = driverMetrics[i];
                        if (m.EndStop.LocationId.HasValue && (locationIds == null || locationIds.Contains(m.EndStop.LocationId.Value)))
                        {
                            if (m.StartTime.HasValue == false)
                            {
                                continue;
                            }

                            var match = new TerminalArrivalEstimation()
                            {
                                JobId           = m.EndStop.JobId,
                                RouteStopId     = m.EndStop.Id,
                                StartLocationId = m.StartStop.LocationId,
                                EndLocationId   = m.EndStop.LocationId.Value,
                                ArrivalTime     = plan.PlanConfig.DueDate.Date.AddTicks(m.StartTime.Value + m.TotalTravelTime),
                            };

                            if (i > 0)
                            {
                                match.ArrivalTime = match.ArrivalTime.Value.AddTicks(m.TotalExecutionTime);
                            }

                            if (timeZone == TimeZonePreference.Utc && match.ArrivalTime.HasValue)
                            {
                                match.ArrivalTime = _dateTimeHelper.ConvertLocalToUtcTime(match.ArrivalTime.Value);
                            }

                            result.Add(match);
                        }
                    }
                }
            }

            return(result);
        }