Exemplo n.º 1
0
 private InfectionsStatsModel GetDayDataDiff(LiveUpdateData previousDayData, LiveUpdateData dayData)
 {
     return(new InfectionsStatsModel
     {
         Confirmed = GetIntOrDefault(dayData?.NumberDiagnosed) - GetIntOrDefault(previousDayData?.NumberDiagnosed),
         Hospitalized = GetIntOrDefault(0) - GetIntOrDefault(0), // TODO: update when we have data for hospitalized
         Monitored = GetIntOrDefault(dayData?.NumberMonitoredAtHome) - GetIntOrDefault(previousDayData?.NumberMonitoredAtHome),
         Date = new DateTimeOffset(dayData.Timestamp).ToUnixTimeSeconds(),
         DateString = dayData.Timestamp.ToShortDateString(),
         Cured = GetIntOrDefault(dayData?.NumberCured) - GetIntOrDefault(previousDayData?.NumberCured),
         InQuarantine = GetIntOrDefault(dayData?.NumberQuarantined) - GetIntOrDefault(previousDayData?.NumberQuarantined),
         InIcu = GetIntOrDefault(0) - GetIntOrDefault(0), // TODO: update when we have data for InIcu
     });
 }
        public static InfectionsStatsModel MapToInfectionsStatsModel(LiveUpdateData liveData)
        {
            if (liveData == null)
            {
                return(new InfectionsStatsModel());
            }

            var data = new InfectionsStatsModel()
            {
                Confirmed    = liveData.NumberDiagnosed ?? 0,
                Cured        = liveData.NumberCured ?? 0,
                Hospitalized = 0,
                InQuarantine = liveData.NumberQuarantined ?? 0,
                Monitored    = liveData.NumberMonitoredAtHome ?? 0,
                InIcu        = 0,
                Date         = new DateTimeOffset(liveData.Timestamp).ToUnixTimeSeconds(),
                DateString   = liveData.Timestamp.ToShortDateString()
            };

            return(data);
        }
Exemplo n.º 3
0
        public async Task <DailyStatsModel> Handle(GetDailyStats request, CancellationToken cancellationToken)
        {
            var data = await _dataService.GetCurrentData();

            if (data?.LiveUpdateData == null)
            {
                return(new DailyStatsModel()
                {
                    History = new InfectionsStatsModel[0]
                });
            }

            if (data.LiveUpdateData.Length == 1)
            {
                return(new DailyStatsModel()
                {
                    DatePublished = data?.DatePublished,
                    DatePublishedString = data?.DatePublishedString,
                    History = new InfectionsStatsModel[] { ParsedDataToApiModelsMapper.MapToInfectionsStatsModel(data.LiveUpdateData.First(), data) }
                });
            }

            List <InfectionsStatsModel> history        = new List <InfectionsStatsModel>();
            List <LiveUpdateData>       oderedLiveData = data.LiveUpdateData.OrderBy(x => x.Timestamp).ToList();
            LiveUpdateData previousDayData             = null;

            foreach (var dayData in oderedLiveData)
            {
                var dayStats = GetDayDataDiff(previousDayData, dayData);
                history.Add(dayStats);
                previousDayData = dayData;
            }

            return(new DailyStatsModel()
            {
                DatePublished = data?.DatePublished,
                DatePublishedString = data?.DatePublishedString,
                History = history.ToArray()
            });
        }
        public static InfectionsStatsModel MapToInfectionsStatsModel(LiveUpdateData liveData, ParsedDataModel parsedData)
        {
            if (liveData == null)
            {
                return(new InfectionsStatsModel());
            }

            var data = new InfectionsStatsModel()
            {
                Confirmed    = liveData.NumberDiagnosed ?? 0,
                Cured        = liveData.NumberCured ?? 0,
                Hospitalized = parsedData.PatientsInfo.Count(p => p.Condition == PatientCondition.Hospitalised),
                InQuarantine = liveData.NumberQuarantined ?? 0,
                Monitored    = liveData.NumberMonitoredAtHome ?? 0,
                Deaths       = parsedData.PatientsInfo.Count(p => p.Condition == PatientCondition.Deceased),
                InIcu        = parsedData.PatientsInfo.Count(p => p.Condition == PatientCondition.ICU),
                Date         = new DateTimeOffset(liveData.Timestamp).ToUnixTimeSeconds(),
                DateString   = liveData.Timestamp.ToShortDateString()
            };

            return(data);
        }