private ICollection <CountryValue> GetLastSeriesTop(List <CountrySerieViewModel> series) { List <CountryValue> lastValues = new List <CountryValue>(); foreach (var country in series) { if (country.data.Count > 0) { CountryValue cv = new CountryValue { name = country.name, y = country.data.Last() }; lastValues.Add(cv); } } List <CountryValue> sortedList = lastValues.OrderByDescending(o => o.y).ToList(); // return sortedList.Take(NUM_COUNTRY_BAR).ToList(); return(sortedList.ToList()); }
private void btn_LIScraper_Save_Click(object sender, RoutedEventArgs e) { try { LinkedInScraper.selectedEmailId = cmb_LIScraper_SelectedAcc.SelectedItem.ToString(); LinkedInScraper.FirstName = txt_LIScraper_FirstName.Text; LinkedInScraper.LastName = txt_LIScraper_LastName.Text; LinkedInScraper.selectedLocation = cmb_LIS_Location.SelectedItem.ToString(); LinkedInScraper.selectedCountry = cmb_LIS_Country_Code.SelectedItem.ToString(); LinkedInScraper.postalCode = txt_LIScraper_PostalCode.Text; LinkedInScraper.Within = cmb_LIS_Within.SelectedItem.ToString(); LinkedInScraper.CompanyValue = txt_LIScraper_Comapny.Text; LinkedInScraper.CompanyScope = cmb_LIS_Company_CrrentOrPast.SelectedItem.ToString(); string countryName = cmb_LIS_Country_Code.SelectedItem.ToString(); #region within CompanyScope try { // if (cmb_LIS_Company_CrrentOrPast.Enabled == true) { string[] arrayTitleList = Regex.Split(TitleValue, ","); foreach (string item in arrayTitleList) { string[] arrayTitleValue = Regex.Split(item, ":"); if (arrayTitleValue[1] == cmb_LIS_Company_CrrentOrPast.SelectedItem.ToString()) { LinkedInScraper.CompanyScope = arrayTitleValue[0]; } } } } catch (Exception ex) { } #endregion #region Within the PostalCode try { string[] arraywithinList = Regex.Split(WithingList, ","); foreach (string item in arraywithinList) { if (item.Contains(cmb_LIS_Within.SelectedItem.ToString())) { string[] arrayWithin = Regex.Split(item, ":"); LinkedInScraper.Within = arrayWithin[0]; } } } catch (Exception ex) { } #endregion #region country Code try { ClsSelect CountryList = new ClsSelect(); string[] arrayCountry = Regex.Split(CountryList.country, ","); foreach (string CountryValue in arrayCountry) { if (CountryValue.Contains(countryName)) { if (countryName == "India") { string[] value = Regex.Split(CountryValue, ":"); countryName = value[1].ToString(); LinkedInScraper.Country = value[0].ToString(); } else { string[] value = Regex.Split(CountryValue, ":"); countryName = value[1].ToString(); LinkedInScraper.Country = value[0].ToString(); break; } } } } catch (Exception ex) { } #endregion } catch (Exception ex) { } }
public TimelineViewModel GetTimeline(string metric, string option) { const int SecondsHour = 3600; const string DateFormat = "MMMM dd yyyy"; HopkinsModel model = _repository.GetHopkinsModel(metric); List <PeakDeaths> data = new List <PeakDeaths>(); HashSet <DateTime> usedDates = new HashSet <DateTime>(); Random random = new Random(); foreach (var country in model.Countries) { List <int> deathsCountry = model.MapCountryDeaths[country]; int maxDeaths = deathsCountry.Max(); PopulationCountry populationCountry = _countryService.GetCountry(country, model.GetCountryIsoCode(country)); if ((maxDeaths >= MIN_DEATHS) && (populationCountry != null) && (deathsCountry.Count > 1)) { if (populationCountry.Population > MIN_POPULATION) { List <int> dataDaily = new List <int>(deathsCountry.Count); dataDaily.Add(deathsCountry[0]); for (int i = 0; i < deathsCountry.Count - 1; i++) { dataDaily.Add(deathsCountry[i + 1] - deathsCountry[i]); } int maxDeathsDaily = dataDaily.Max(); int maxIndexDaily = dataDaily.IndexOf(maxDeathsDaily); if (maxDeathsDaily >= MIN_DEATHS) { DateTime peakDate; if (maxIndexDaily >= model.Dates.Count) { peakDate = DateTime.Now; } else { peakDate = model.Dates[maxIndexDaily]; } // Avoid repeat exact same date while (usedDates.Contains(peakDate)) { peakDate = model.Dates[maxIndexDaily].AddSeconds(random.Next(0, SecondsHour)); } usedDates.Add(peakDate); string peakDateStr = peakDate.ToString(DateFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo); PeakDeaths item = new PeakDeaths { x = new DateTimeOffset(peakDate.AddDays(1)).ToUnixTimeMilliseconds(), name = country, label = country, max = maxDeathsDaily, date = peakDateStr, description = $"{maxDeathsDaily} {metric} - {peakDateStr}" }; data.Add(item); } } } } List <CountryValue> MaxDeathsAbsolute = new List <CountryValue>(); List <CountryValue> MaxDeathsRelative = new List <CountryValue>(); var normalizationStrategy = _normalizationStrategyMap[option]; foreach (var item in data) { PopulationCountry populationCountry = _countryService.GetCountry(item.name, model.GetCountryIsoCode(item.name)); if ((populationCountry != null)) { double scale = normalizationStrategy.Invoke(populationCountry); var itemCountryValueRelative = new CountryValue { name = item.name, y = item.max * scale, date = item.date }; MaxDeathsRelative.Add(itemCountryValueRelative); var itemCountryValueAbsolute = new CountryValue { name = item.name, y = item.max, date = item.date }; MaxDeathsAbsolute.Add(itemCountryValueAbsolute); } } List <CountryValue> sortedMaxDeathsRelative = MaxDeathsRelative.OrderByDescending(o => o.y).ToList(); List <CountryValue> sortedMaxDeathsAbsolute = MaxDeathsAbsolute.OrderByDescending(o => o.y).ToList(); return(new TimelineViewModel { Data = data, MaxDeathsRelative = sortedMaxDeathsRelative.Take(NUM_COUNTRY_BAR).ToList(), MaxDeathsAbsolute = sortedMaxDeathsAbsolute.Take(NUM_COUNTRY_BAR).ToList() }); }