//todo: unit tests
        public void UpdateDailyStatistics()
        {
            List <string> vesselCategories = new List <string>()
            {
                "Cargo", "Dredging", "Fishing", "Offshore", "Other", "Passenger", "Tanker", "Tug"
            };
            List <string> areaNames = GetSeaAreas().Select(a => a.Name).ToList();

            using (IServiceScope scope = _scopeFactory.CreateScope())
            {
                IEFStatRepository _statsRepo = scope.ServiceProvider.GetRequiredService <EFStatRepository>();

                RemoveIncompleteStatsIfAny(_statsRepo);

                for (int i = 0; i < vesselCategories.Count(); i++)
                {
                    for (int j = 0; j < areaNames.Count(); j++)
                    {
                        if (areaNames[j] != "Unknown")
                        {
                            DailyStatisticsModel updateStats = new DailyStatisticsModel()
                            {
                                Date           = DateTime.UtcNow,
                                Moving         = _statsRepo.GetMoving(areaNames[j], vesselCategories[i]),
                                Moored         = _statsRepo.GetMoored(areaNames[j], vesselCategories[i]),
                                Anchored       = _statsRepo.GetAnchored(areaNames[j], vesselCategories[i]),
                                VesselCategory = vesselCategories[i],
                                Area           = areaNames[j]
                            };

                            _statsRepo.SaveStatistics(updateStats);
                        }
                    }
                }
            };
        }
Example #2
0
        public void SaveStatistics(DailyStatisticsModel updateStats)
        {
            _context.Statistics.Add(updateStats);

            _context.SaveChanges();
        }