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 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 GetRelativeGrowthViewModel(string metric, string option, int minDeathsValue = MIN_DEATHS_MILLION) { HopkinsModel model = _repository.GetHopkinsModel(metric); 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, model.GetCountryIsoCode(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, SeriesLast = GetLastSeriesTop(series) }); }
public PlotViewModel GetRelativeViewModel(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> deathsCountryInt = model.MapCountryDeaths[country]; List <double> deathsCountry = deathsCountryInt.Select(i => (double)i).ToList(); double maxDeaths = deathsCountry.Max(); var normalizationStrategy = _normalizationStrategyMap[option]; PopulationCountry populationCountry = _countryService.GetCountry(country); if ((maxDeaths > MIN_DEATHS) && (populationCountry != null)) { if (populationCountry.Population > MIN_POPULATION) { double scale = normalizationStrategy.Invoke(populationCountry); for (int i = 0; i < deathsCountry.Count; i++) { deathsCountry[i] *= scale; } var item = new CountrySerieViewModel { name = country, data = deathsCountry.Where(d => d > minDeathsValue).ToList() }; if (deathsCountry.Count > 0) { series.Add(item); } } } } return(new PlotViewModel { Series = series, UpdateTime = model.UpdateTime }); }
public PlotViewModel GetGrowthViewModel(string metric) { HopkinsModel model = _repository.GetHopkinsModel(metric); 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(); PopulationCountry populationCountry = _countryService.GetCountry(country, model.GetCountryIsoCode(country)); if ((maxDeaths >= MIN_DEATHS) && (deaths.Count > 1) && (populationCountry != null)) { if (populationCountry.Population > MIN_POPULATION) { 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 }; series.Add(item); } } } return(new PlotViewModel { Series = series, UpdateTime = model.UpdateTime, SeriesLast = GetLastSeriesTop(series) }); }