public PlotViewModel GetAbsoluteDataViewModel() { Covid19DeathsModel model = _repository.GetCovid19DeathsModel(); List <CountrySerieViewModel> series = new List <CountrySerieViewModel>(); foreach (var country in model.Countries) { List <int> ints = model.MapCountryDeaths[country]; List <double> data = ints.Select(i => (double)i).ToList(); double max = data.Max(); PopulationCountry countryPop = _countryService.GetCountry(country); if ((max > MIN_DEATHS) && (countryPop != null)) { if (countryPop.Population > MIN_POPULATION) { var item = new CountrySerieViewModel { name = country, data = data.Where(d => d > MIN_DEATHS).ToList() }; series.Add(item); } } } return(new PlotViewModel { Series = series, UpdateTime = model.UpdateTime }); }
public PlotViewModel GetGrowthViewModel() { Covid19DeathsModel model = _repository.GetCovid19DeathsModel(); List <CountrySerieViewModel> series = new List <CountrySerieViewModel>(); foreach (var country in model.Countries) { List <int> deaths = model.MapCountryDeaths[country]; double maxDeaths = deaths.Max(); deaths = deaths.Where(d => d > MIN_DEATHS).ToList(); if ((maxDeaths > MIN_DEATHS) && (deaths.Count > 1)) { List <double> data = new List <double>(deaths.Count - 1); for (int i = 0; i < deaths.Count - 1; i++) { data.Add(deaths[i + 1] - deaths[i]); } var item = new CountrySerieViewModel { name = country, data = data.Where(d => d > MIN_DEATHS).ToList() }; series.Add(item); } } return(new PlotViewModel { Series = series, UpdateTime = model.UpdateTime }); }
public void TestDecoder() { Covid19DeathsModelFileCacheReader reader = new Covid19DeathsModelFileCacheReader(new Covid19DeathsModelDowloader()); Covid19DeathsModelRepositoryCsv decoder = new Covid19DeathsModelRepositoryCsv(reader); Covid19DeathsModel model = decoder.GetCovid19DeathsModel(); Assert.AreNotEqual(model.MapCountryDeaths["Spain"], null); }
public void TestData() { List <int> expected = new List <int>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 10, 17, 28, 35, 54, 55, 133, 195, 289, 342, 533, 623, 830, 1043, 1375, 1772 }; Covid19DeathsModelFileReader reader = new Covid19DeathsModelFileReader("time_series_19-covid-Deaths_2020-03-23.csv"); Covid19DeathsModelRepositoryCsv decoder = new Covid19DeathsModelRepositoryCsv(reader); Covid19DeathsModel model = decoder.GetCovid19DeathsModel(); CollectionAssert.AreEqual(model.MapCountryDeaths["Spain"], expected); }
public PlotViewModel GetRelativeGrowthViewModel(string option, int minDeathsValue = MIN_DEATHS_MILLION) { Covid19DeathsModel model = _repository.GetCovid19DeathsModel(); List <CountrySerieViewModel> series = new List <CountrySerieViewModel>(); foreach (var country in model.Countries) { List <int> deathsCountry = model.MapCountryDeaths[country]; double maxDeaths = deathsCountry.Max(); var normalizationStrategy = _normalizationStrategyMap[option]; PopulationCountry populationCountry = _countryService.GetCountry(country); deathsCountry = deathsCountry.Where(d => d > MIN_DEATHS).ToList(); if ((maxDeaths > MIN_DEATHS) && (populationCountry != null) && (deathsCountry.Count > 1)) { if (populationCountry.Population > MIN_POPULATION) { double scale = normalizationStrategy.Invoke(populationCountry); List <double> dataRelative = new List <double>(deathsCountry.Count - 1); for (int i = 0; i < deathsCountry.Count - 1; i++) { dataRelative.Add(deathsCountry[i + 1] - deathsCountry[i]); } for (int i = 0; i < dataRelative.Count; i++) { dataRelative[i] *= scale; } var item = new CountrySerieViewModel { name = country, data = dataRelative }; if (dataRelative.Count > 0) { series.Add(item); } } } } return(new PlotViewModel { Series = series, UpdateTime = model.UpdateTime }); }