public IActionResult Create(CovidData covidData) { if (ModelState.IsValid) { var covid_datas = covidDataRepository.GetAllCovidDatas(); var matched = false; foreach (var item in covid_datas) { if ((item.Date.Day == DateTime.Now.Day) && (item.Date.Month == DateTime.Now.Month) && (item.Date.Year == DateTime.Now.Year)) { matched = true; } } if (matched) { //add error //you hve covid data already for this day TempData["ErrorMessage"] = "You have already Published today's Covid19 Data!"; return(RedirectToAction("Index")); } covidData.Date = DateTime.Now; CovidData newCovidData = covidDataRepository.Add(covidData); TempData["SuccessMessage"] = "Today's Covid19 Data published!"; } return(RedirectToAction("Index")); }
public async Task <List <CovidData> > ScrapeData() { using var httpClient = new HttpClient(); var result = await httpClient.GetStringAsync(URL); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(result); var stateHtml = htmlDoc.DocumentNode.Descendants("tbody").ToList(); var stateList = stateHtml[0].Descendants("tr").ToList(); var listState = new List <CovidData>(); if (stateList != null && stateList.Any()) { foreach (var state in stateList) { var covData = new CovidData { State = state.SelectSingleNode("td[1]").InnerHtml?.Trim(), AdmittedCases = state.SelectSingleNode("td[3]").InnerHtml?.Trim(), ConfirmedCases = state.SelectSingleNode("td[2]").InnerHtml?.Trim(), DeathNumber = state.SelectSingleNode("td[5]").InnerHtml?.Trim(), DischargedNumber = state.SelectSingleNode("td[4]").InnerHtml?.Trim() }; listState.Add(covData); } } return(listState); }
private void GetGeoZoneData(CovidData oCovidData, out object oToReturn) { this.SetDateFormat(oCovidData); bool isDemandingAllGeoZoneData = false; foreach (var country in oCovidData.oCountryList) { if (country == "*") { isDemandingAllGeoZoneData = true; break; } } if (isDemandingAllGeoZoneData) { _oCovidCache.GetListFilteredByDate( oCovidData.oDates.startDate, oCovidData.oDates.endDate, out oToReturn); } else { oToReturn = this.GetFromDAO(oCovidData, UtilsConstants.POSTMethodsConstants.GET_GEO_ZONE_DATA).Result; } }
public IActionResult Edit(CovidData covidData) { CovidData changed_covidData = covidDataRepository.Update(covidData); TempData["SuccessMessage"] = "Data Updated Successfully!"; return(RedirectToAction("Index", "CovidData")); }
public IActionResult Details(int id) { //dummy record for checking //Student s = new Student { StudentID = Student_ID, cpi = 92, email = "*****@*****.**", mobile = "9998889998", Name = "j", Subjects = null }; CovidData covidData = covidDataRepository.GetCovidData(id); var userid = signInManager.UserManager.GetUserId(User); var user = context.Users.Where(usr => usr.Id == userid).FirstOrDefault(); if (covidData == null) { TempData["ErrorMessage"] = "Data not found!"; if (user.IsGoverment) { return(RedirectToAction("Index", "CovidData")); } return(RedirectToAction("CovidDataList", "CovidData")); } else { if (user.IsGoverment) { return(View(covidData)); } return(View("CovidDataDetails", covidData)); } }
private static void DisplayRegionalDeaths(CovidData data) { var table = new Table(); table.Border = TableBorder.Minimal; table.AddColumns("", "Deaths", "Per 100k", "7d Avg", "Per 100k"); table.Columns[0].LeftAligned(); table.Columns[1].RightAligned(); table.Columns[2].RightAligned(); table.Columns[3].RightAligned(); table.Columns[4].RightAligned(); var subregions = data.SubRegionData .Where(d => d.Name != "Unknown") .OrderByDescending(d => d.DailyAverageCasesLastSevenDaysPerHundredThousand); foreach (var region in subregions) { table.AddRow( region.Name, region.LatestDeaths.ToString("n0"), region.DeathsPerHundredThousand.ToString("n0"), region.DailyAverageDeathsLastSevenDays.ToString("n0"), region.DailyAverageDeathsLastSevenDaysPerHundredThousand.ToString("n1")); } AnsiConsole.Render(table); }
public CovidData Get() { CovidData covidData = new CovidData(); HttpClient client = new HttpClient { BaseAddress = new Uri("https://api.covid19api.com/") }; HttpResponseMessage response = client.GetAsync("summary").Result; if (response.IsSuccessStatusCode) { covidData = JsonConvert.DeserializeObject <CovidData>(response.Content.ReadAsStringAsync().Result); } else { Debug.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } foreach (var country in covidData.Countries) { string continent = this.GetContinent(country.CountryCode); country.Continent = continent; country.TotalActive = country.TotalConfirmed - (country.TotalDeaths + country.TotalRecovered); } return(covidData); }
private static void DisplayCountryData(CovidData data) { var table = new Table(); table.Border = TableBorder.Minimal; table.AddColumns("", "Total Reported", "Per 100k", data.RegionData.LatestDate.ToString("yyyy-MM-dd"), "Weekly Trend"); table.Columns[0].LeftAligned(); table.Columns[1].RightAligned(); table.Columns[2].RightAligned(); table.Columns[3].RightAligned(); table.Columns[4].RightAligned(); string casesColor = data.RegionData.CasesWeeklyTrend > 0 ? "[red]" : "[green]"; table.AddRow( "[white]Cases[/]", data.RegionData.LatestCases.ToString("n0"), data.RegionData.CasesPerHundredThousand.ToString("n0"), data.RegionData.LastReportedCases.ToString("n0"), casesColor + data.RegionData.CasesWeeklyTrend + "%[/]" ); string deathsColor = data.RegionData.DeathsWeeklyTrend > 0 ? "[red]" : "[green]"; table.AddRow( "[white]Deaths[/]", data.RegionData.LatestDeaths.ToString("n0"), data.RegionData.DeathsPerHundredThousand.ToString("n0"), data.RegionData.LastReportedDeaths.ToString("n0"), deathsColor + data.RegionData.DeathsWeeklyTrend + "%[/]" ); AnsiConsole.Render(table); }
private void AddCovidHospitalDataByCounty(List <CovidData> covidData, string countyName) { string covidHospitalDataJson = GetCARawCovidHospitalJsonDataByCounty(countyName); CovidHospitalDataEntity.Root covidDataDeserialized = JsonConvert.DeserializeObject <CovidHospitalDataEntity.Root>(covidHospitalDataJson); foreach (CovidHospitalDataEntity.Record hospitalRecord in covidDataDeserialized.result.records) { CovidData covidRecord = covidData.FirstOrDefault(x => x.Date == hospitalRecord.todays_date && x.County == hospitalRecord.county); if (covidRecord == null) { continue; } decimal?icuCovidPatient = null; if (decimal.TryParse(hospitalRecord.icu_covid_confirmed_patients.ToString(), out decimal icuCovidPatientCount)) { icuCovidPatient = icuCovidPatientCount; } covidRecord.ICUCovidPatientCount = icuCovidPatient ?? 0; decimal?icuAvailableBeds = null; if (decimal.TryParse(hospitalRecord.icu_available_beds.ToString(), out decimal icuAvailableBedsCount)) { icuAvailableBeds = icuAvailableBedsCount; } covidRecord.ICUAvailableBedsCount = icuAvailableBeds ?? 0; } }
public void GetDatesIDs(CovidData pCovidData, out Tuple <string, string> oStartIDEndID) { Query oQuery; List <object[]> oResultList = new List <object[]>(); this.SetQuery(_SELECT_ID_QUERY_PATH, out oQuery); oQuery.query = oQuery.query.Replace(UtilsConstants.QueryConstants.ZERO_STRING, pCovidData.oDates.startDate); var isAWellResponse = this._oConnection.ExecuteSelectCommand(oQuery.query, oResultList); if (!isAWellResponse) { oStartIDEndID = null; return; } this.SetQuery(_SELECT_ID_QUERY_PATH, out oQuery); oQuery.query = oQuery.query.Replace(UtilsConstants.QueryConstants.ZERO_STRING, pCovidData.oDates.endDate); isAWellResponse = this._oConnection.ExecuteSelectCommand(oQuery.query, oResultList); if (!isAWellResponse || oResultList.Count < UtilsConstants.IntConstants.TWO) { oStartIDEndID = null; return; } var oRow = oResultList[UtilsConstants.IntConstants.ZERO]; string start = oRow[UtilsConstants.IntConstants.ZERO].ToString(); oRow = oResultList[UtilsConstants.IntConstants.ONE]; string end = oRow[UtilsConstants.IntConstants.ZERO].ToString(); oStartIDEndID = new Tuple <string, string>(start, end); }
private CovidData GetGraphData(string url) { String data = GetData(url); CovidData covidData = JsonConvert.DeserializeObject <CovidData>(data); return(covidData); }
public CovidData Update(CovidData covidDataChanges) { var data = context.CovidDatas.Attach(covidDataChanges); data.State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); return(covidDataChanges); }
protected override void OnContinue() { DataDownloader.DownloadFile(Session.settingsPath); CovidData data = CovidData.LoadJson(); GraphGenerator.GenerateGraph(1200, 1200, data.getNewCasesForDays(14)); EmailSender.sendMail(); timer.Change(3600000, Timeout.Infinite); }
private String ConvertDataToGraphFormat(CovidData covidData) { List <DataPoint> graphData = new List <DataPoint>(); foreach (CovidDataItem figures in covidData.data) { graphData.Add(new DataPoint(Convert.ToDateTime(figures.date), figures.newCasesBySpecimenDate)); } return(JsonConvert.SerializeObject(graphData)); }
public override void GetAllGeoZoneData(CovidData pCovidData, List <GeoZone> pListToComplete) { ConnectionPostgreSql oConnection; this.SetConnection(out oConnection); if (_oPostgreSqlSelect is null) { this._oPostgreSqlSelect = PostgreSqlSelect.GetInstance(oConnection); } _oPostgreSqlSelect.GetAllGeoZoneData(pCovidData, pListToComplete); }
public async void DataFetch() { try { RootObject covidData = await CovidData.GetCovidData(); covidData.Countries.ForEach(country => countriesList.Add(new CountryListData(country.Country))); } catch (Exception ex) { Console.WriteLine(ex); } }
public IActionResult Edit(int id) { CovidData covidData = covidDataRepository.GetCovidData(id); if (covidData == null) { TempData["ErrorMessage"] = "Data not found!"; return(RedirectToAction("Index", "CovidData")); } else { return(View(covidData)); } }
// GET: Home public ActionResult Index(string area) { //string area = "Eastleigh"; string url = "https://api.coronavirus.data.gov.uk/v1/data?filters=areaName=" + area + "&structure={%22date%22:%22date%22,%22newCasesBySpecimenDate%22:%22newCasesBySpecimenDate%22}"; CovidData covidData = GetGraphData(url); ViewBag.CasesInLastDays = CasesInLastDays(covidData, -7); ViewBag.DataPoints = ConvertDataToGraphFormat(covidData); ViewBag.Area = area; ViewBag.Url = url; return(View()); }
private void SetDateFormat(CovidData oCovidData) { if (oCovidData.oDates.separator == UtilsConstants.StringConstants.RIGHT_BAR) { return; } oCovidData.oDates.startDate = oCovidData.oDates.startDate.Replace( oCovidData.oDates.separator, UtilsConstants.StringConstants.RIGHT_BAR); oCovidData.oDates.endDate = oCovidData.oDates.endDate.Replace( oCovidData.oDates.separator, UtilsConstants.StringConstants.RIGHT_BAR); }
public async Task <ActionResult <CovidData> > GetGlobalSummary() { var serviceUrl = string.Concat(this._configuration.GetValue <string>("CovidService"), "/summary"); CovidData covidData = new CovidData(); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(serviceUrl)) { string apiResponse = await response.Content.ReadAsStringAsync(); covidData = JsonConvert.DeserializeObject <CovidData>(apiResponse); } } return(covidData); }
public void GetGeoZoneData(CovidData pCovidData, List <GeoZone> pListToComplete) { Tuple <string, string> oStartIDEndID; this.GetDatesIDs(pCovidData, out oStartIDEndID); if (oStartIDEndID is null) { return; } List <GeoZone> oListToOrderComplete = new List <GeoZone>(); this.GetGetGeoZoneListData(oStartIDEndID, pCovidData, oListToOrderComplete); pListToComplete.AddRange( oListToOrderComplete.OrderBy(oGeozone => oGeozone.geoID).ToList()); }
private int CasesInLastDays(CovidData covidData, int numerOfDays) { int cases = 0; TimeSpan lastSevenDays = new TimeSpan(numerOfDays, 0, 0, 0); //DateTime[] dates = new DateTime[7]; List <DateTime> dates = new List <DateTime>(); foreach (CovidDataItem figures in covidData.data) { if (Convert.ToDateTime(figures.date) >= DateTime.Today.Add(lastSevenDays) && (!dates.Contains(Convert.ToDateTime(figures.date)))) { cases += figures.newCasesBySpecimenDate; dates.Add(Convert.ToDateTime(figures.date)); } } return(cases); }
public void GetAllGeoZoneData(CovidData pCovidData, List <GeoZone> pListToComplete) { List <GeoZone> oGeoZoneCompleteList = new List <GeoZone>(); this.GetAllCountries(oGeoZoneCompleteList); if (oGeoZoneCompleteList.Count == UtilsConstants.IntConstants.ZERO) { return; } pCovidData.oCountryList = new List <string>(); foreach (var oGeoZone in oGeoZoneCompleteList) { pCovidData.oCountryList.Add(oGeoZone.geoID); } this.GetGeoZoneData(pCovidData, pListToComplete); }
public CovidData() { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://covidnigeria.herokuapp.com/api"); request.Method = "GET"; String getresponse = String.Empty; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); getresponse = reader.ReadToEnd(); reader.Close(); dataStream.Close(); } //List<Data =JsonConvert.DeserializeObject<List<data(Reader); CovidData covidData = JsonConvert.DeserializeObject<CovidData>(getresponse); Console.WriteLine("Total discharged: "+covidData.discharged); }
public Task GetCovidDataAsync() { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://corona.lmao.ninja/"); var response = client.GetAsync("v2/all").GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { var data = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); CovidData covidData = JsonConvert.DeserializeObject <CovidData>(data); Random random = new Random(); var number = random.Next(1, 4); switch (number) { case 1: return(ReplyAsync(string.Format("Out of {0} total cases, {1} were reported today.", covidData.Cases, covidData.TodayCases))); case 2: return(ReplyAsync(string.Format("Out of {0} deaths, {1} were died today.", covidData.Deaths, covidData.TodayDeaths))); default: return(ReplyAsync(string.Format("Great news! {0} people recovered today.", covidData.TodayRecovered))); } } else { return(ReplyAsync("I'm feeling dizzy")); } } } catch (Exception ex) { return(ReplyAsync("I'm exhausted")); } }
public MainWindow(LoadWindow loadWindow) { Countries = loadWindow.Countries; Rates = loadWindow.Rates; CovidDataList = loadWindow._CovidData; GetCovidByCountry(Countries); InitializeComponent(); var connection = loadWindow.networkService.CheckConnection(); if (!connection.IsSuccess) { TabMap.Visibility = Visibility.Hidden; TabCovid.Visibility = Visibility.Hidden; } listBoxPaises.ItemsSource = Countries; treeContinents.ItemsSource = GetContinents(Countries); cbWorldCurrencies.ItemsSource = Rates; string CountryCode = loadWindow.LocalCountry; if (!string.IsNullOrEmpty(CountryCode)) { Country selectedCountry = Countries.Find(c => c.alpha2Code == CountryCode); if (selectedCountry != null) { listBoxPaises.SelectedItem = selectedCountry; } else { listBoxPaises.SelectedIndex = 0; } } else { listBoxPaises.SelectedIndex = 0; } }
public async Task <ActionResult <CovidData> > PostCovidData(CovidData covidData) { _context.CovidData.Add(covidData); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CovidDataExists(covidData.CountryCode, covidData.Date)) { return(Conflict("This Covid data is already contained in database.")); } else { throw; } } return(CreatedAtAction("GetCovidData", new { id = covidData.CountryCode }, covidData)); }
private async void GetGetGeoZoneListData( Tuple <string, string> pStartIDEndID, CovidData pCovidData, List <GeoZone> pListToComplete) { ConcurrentBag <GeoZone> oConcurrentBagToFill = new ConcurrentBag <GeoZone>(); List <Task> oTaskList = new List <Task>(); foreach (var country in pCovidData.oCountryList) { oTaskList.Add(this.FillCountryData( oConcurrentBagToFill, country, pStartIDEndID.Item1, pStartIDEndID.Item2)); } foreach (var oTask in oTaskList) { await oTask; } pListToComplete.AddRange(oConcurrentBagToFill); }
private async Task View(string country, bool cases, bool deaths) { try { var c = country.GetCountry(); if (c == Country.Unknown) { AnsiConsole.MarkupLine($"[red][[:cross_mark: Could not find country ${country}]][/]"); return; } CovidData data = await _mediator.Send(new CovidCountryDataQuery { Country = c }); AnsiConsoleHelper.TitleRule($":biohazard: Covid data for {country}"); DisplayCountryData(data); AnsiConsole.WriteLine(); if (cases) { DisplayRegionalCases(data); AnsiConsole.WriteLine(); } if (deaths) { DisplayRegionalDeaths(data); AnsiConsole.WriteLine(); } AnsiConsoleHelper.Rule("white"); } catch (Exception ue) { AnsiConsole.MarkupLine($"[red][[:cross_mark: ${ue.Message}]][/]"); } }
public List <CovidData> GetCovidDataByCounty(string countyName) { string covidDataJson = GetCARawCovidJsonDataByCounty(countyName); CovidDataEntity.Root covidDataDeserialized = JsonConvert.DeserializeObject <CovidDataEntity.Root>(covidDataJson); var covidDataList = new List <CovidData>(); foreach (CovidDataEntity.Record covidRecord in covidDataDeserialized.result.records) { DateTime?covidDate = covidRecord.date; if (covidDate is null) { continue; } DateTime yesterdayDate = DateTime.Now.AddDays(-1); if (covidDate.Value.ToString("d") == yesterdayDate.ToString("d") && (covidRecord.reported_deaths == null && covidRecord.reported_cases == null)) //CA Open Data reports the date with no data in the morning. Waiting until they report to show the numbers. { continue; } var covidData = new CovidData(); covidData.ID = covidRecord._id; covidData.TotalCountConfirmed = covidRecord.cumulative_cases ?? 0; covidData.NewCountDeaths = covidRecord.reported_deaths ?? 0; covidData.TotalCountDeaths = covidRecord.cumulative_deaths ?? 0; covidData.County = covidRecord.area; covidData.NewCountConfirmed = covidRecord.reported_cases ?? 0; covidData.Date = (DateTime)covidDate; covidDataList.Add(covidData); } AddCovidHospitalDataByCounty(covidDataList, countyName); return(covidDataList); }