Exemplo n.º 1
0
        public ExposuresPageViewModel(INavigationService navigationService, IUserDataService userDataService) : base(navigationService)
        {
            Title = Resources.AppResources.MainExposures;
            this.userDataService = userDataService;
            userData             = this.userDataService.Get();
            _exposures           = new ObservableCollection <ExposureSummary>();

            foreach (var en in userData.ExposureInformation.GroupBy(eni => eni.Timestamp))
            {
                var ens = new ExposureSummary();
                ens.ExposureDate  = en.Key.ToLocalTime().ToString("D", CultureInfo.CurrentCulture);
                ens.ExposureCount = en.Count().ToString();
                _exposures.Add(ens);
            }
        }
Exemplo n.º 2
0
        public ExposuresPageViewModel(INavigationService navigationService, IExposureNotificationService exposureNotificationService) : base(navigationService)
        {
            Title      = Resources.AppResources.MainExposures;
            _exposures = new ObservableCollection <ExposureSummary>();

            var exposureInformationList = exposureNotificationService.GetExposureInformationListToDisplay();

            if (exposureInformationList != null)
            {
                foreach (var en in exposureInformationList.GroupBy(eni => eni.Timestamp))
                {
                    var ens = new ExposureSummary();
                    ens.ExposureDate  = en.Key.ToLocalTime().ToString("D", CultureInfo.CurrentCulture);
                    ens.ExposureCount = en.Count().ToString();
                    _exposures.Add(ens);
                }
            }
        }
Exemplo n.º 3
0
        public async Task InitExposures()
        {
            var exposures = new ObservableCollection <ExposureSummary>();

            var exposureRiskCalculationConfiguration
                = await _exposureRiskCalculationConfigurationRepository.GetExposureRiskCalculationConfigurationAsync(preferCache : false);

            _loggerService.Info(exposureRiskCalculationConfiguration.ToString());

            var dailySummaryList
                = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);

            var dailySummaryMap = dailySummaryList.ToDictionary(ds => ds.GetDateTime());

            var exposureWindowList
                = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);

            var userExposureInformationList
                = _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

            if (dailySummaryList.Count() > 0)
            {
                foreach (var ew in exposureWindowList.GroupBy(exposureWindow => exposureWindow.GetDateTime()))
                {
                    if (!dailySummaryMap.ContainsKey(ew.Key))
                    {
                        _loggerService.Warning($"ExposureWindow: {ew.Key} found, but that is not contained the list of dailySummary.");
                        continue;
                    }

                    var dailySummary = dailySummaryMap[ew.Key];

                    RiskLevel riskLevel = _exposureRiskCalculationService.CalcRiskLevel(
                        dailySummary,
                        ew.ToList(),
                        exposureRiskCalculationConfiguration
                        );
                    if (riskLevel < RiskLevel.High)
                    {
                        continue;
                    }

                    var ens = new ExposureSummary()
                    {
                        Timestamp    = ew.Key,
                        ExposureDate = IExposureDataRepository.ConvertToTerm(dailySummary.GetDateTime()),
                    };
                    var exposureDurationInSec = ew.Sum(e => e.ScanInstances.Sum(s => s.SecondsSinceLastScan));
                    ens.SetExposureTime(exposureDurationInSec);

                    exposures.Add(ens);
                }
            }

            if (userExposureInformationList.Count() > 0)
            {
                foreach (var ei in userExposureInformationList.GroupBy(userExposureInformation => userExposureInformation.Timestamp))
                {
                    var ens = new ExposureSummary()
                    {
                        Timestamp    = ei.Key,
                        ExposureDate = IExposureDataRepository.ConvertToTerm(ei.Key),
                    };
                    ens.SetExposureCount(ei.Count());
                    exposures.Add(ens);
                }
            }

            Exposures.Clear();
            foreach (var exposure in exposures.OrderByDescending(exposureSummary => exposureSummary.Timestamp))
            {
                Exposures.Add(exposure);
            }
        }