Beispiel #1
0
        private async Task DownloadTimelineHelperAsync()
        {
            // Create a list of tasks
            var availableCountries = this.GetListOfProperty(CountryProperty.SLUG);

            List <Task <CountryTimeline> > taskList = new List <Task <CountryTimeline> >();

            foreach (var country in availableCountries)
            {
                taskList.Add(apiHandler.LoadCountryTimelineAsync(country));
            }

            // Await all in parallel
            var results = await Task.WhenAll(taskList);

            OnDataLoaded(new DataPercentlyLoadedEventArgs(80));

            // Add the results to the DataStore
            CountryTimeline tmpGlobalSum = new CountryTimeline();

            dataStore.Timeline = new TimelineData();

            foreach (var result in results)
            {
                // Take first element, just to get the CountryName
                string countryName = result.Days.First().Country;
                if (dataStore.Timeline.Countries.ContainsKey(countryName))
                {
                    throw new Exception($"{countryName} already exists in Dict!");
                }
                else
                {
                    // Add the current CountryTimeline to the DataStore
                    dataStore.Timeline.Countries.Add(countryName, result);

                    foreach (Day day in result.Days)
                    {
                        var tmpDate = tmpGlobalSum.Days.Where(i => i.Date == day.Date).FirstOrDefault();
                        if (tmpDate == null)
                        {
                            tmpGlobalSum.Days.Add(new Day()
                            {
                                Country = "Global", Date = day.Date, Confirmed = day.Confirmed, Active = day.Active, Recovered = day.Recovered, Deaths = day.Deaths
                            });
                        }
                        else
                        {
                            tmpDate.Confirmed += day.Confirmed;
                            tmpDate.Active    += day.Active;
                            tmpDate.Recovered += day.Recovered;
                            tmpDate.Deaths    += day.Deaths;
                        }
                    }
                }
            }
            dataStore.Timeline.Countries.Add("Global", tmpGlobalSum);
            OnDataLoaded(new DataPercentlyLoadedEventArgs(90));
        }
Beispiel #2
0
        public static List <DataElement> GetStatisticOfTimeline(this SelectableStatistics stat, CountryTimeline timeline)
        {
            List <DataElement> dataElements = new List <DataElement>();

            foreach (var day in timeline.Days)
            {
                DataElement element = new DataElement();
                element.Date = day.Date;

                switch (stat)
                {
                case SelectableStatistics.ConfirmedCases:
                    element.Value = day.Confirmed;
                    break;

                case SelectableStatistics.ActiveCases:
                    element.Value = day.Active;
                    break;

                case SelectableStatistics.Deaths:
                    element.Value = day.Deaths;
                    break;

                case SelectableStatistics.Recovered:
                    element.Value = day.Recovered;
                    break;
                }

                dataElements.Add(element);
            }

            return(dataElements);
        }