public IActionResult GetCSVModel(string url) { try { List <Dictionary <string, object> > obj = CovidSerializerExtension.FromXMLURL <Dictionary <string, object> >(url); if (obj == null || obj.Count == 0) { throw new Exception(); } var source = new AddedSource() { source = url, value = obj }; return(Ok(source)); } catch (Exception xmlEx) { try { List <object> obj = CovidSerializerExtension.FromCSVURL <object>(url, CovidDataManager.csvConfig); if (obj == null || obj.Count == 0) { throw new Exception(); } var source = new AddedSource() { source = url, value = obj }; return(Ok(source)); } catch (Exception csvEx) { try { List <Dictionary <string, object> > obj = CovidSerializerExtension.FromJSONURL <Dictionary <string, object> >(url); if (obj == null || obj.Count == 0) { throw new Exception(); } var source = new AddedSource() { source = url, value = obj }; return(Ok(source)); } catch (Exception JsonEx) { return(StatusCode(400, "Error attempting to build object from URL")); } } } }
public async static void UpdateHopkinsAndWHO() { try { var date = DateTime.Now; string hopkinEnd = date.ToString("MM-dd-yyyy") + ".csv"; string HopkinSource = ""; while (!(new Uri(hopkinSource + hopkinEnd).Reachable())) { date = date.AddDays(-1); hopkinEnd = date.ToString("MM-dd-yyyy") + ".csv"; HopkinSource = hopkinSource + hopkinEnd; } DateTime maxDate = date.AddDays(-31); List <HopkinsData> newData = new List <HopkinsData>(); while (new Uri(HopkinSource).Reachable() && date > maxDate) { IEnumerable <HopkinsData> hopkinData = CovidSerializerExtension.FromCSVURL <HopkinsData>(HopkinSource, csvConfig); if (hopkinData != null) { newData.AddRange(hopkinData.ToList()); } date = date.AddDays(-1); hopkinEnd = date.ToString("MM-dd-yyyy") + ".csv"; HopkinSource = hopkinSource + hopkinEnd; } hopkinsData = newData; IEnumerable <WHOcountrys> whodata = CovidSerializerExtension.FromCSVURL <WHOcountrys>(whoSource, csvConfig); if (whodata != null) { whoData = whodata.ToList(); } } catch (Exception ex) { await Task.Delay(TimeSpan.FromMinutes(5)); UpdateHopkinsAndWHO(); return; } await Task.Delay(TimeSpan.FromHours(6)); UpdateHopkinsAndWHO(); }
public async Task <IActionResult> PostCSVFile([FromForm] IFormFile file) { using (var sr = new System.IO.StreamReader(file.OpenReadStream())) { var content = await sr.ReadToEndAsync(); try { List <object> obj = CovidSerializerExtension.FromCSV <object>(content, CovidDataManager.csvConfig); if (obj == null || obj.Count == 0) { throw new Exception(); } var source = new AddedSource() { source = "User uploaded file", value = obj }; return(Ok(source)); } catch (Exception) { try { List <Dictionary <string, object> > obj = CovidSerializerExtension.FromJSON <Dictionary <string, object> >(content); if (obj == null || obj.Count == 0) { throw new Exception(); } var source = new AddedSource() { source = "User uploaded file", value = obj }; return(Ok(source)); } catch (Exception ex) { return(StatusCode(400, "Error attempting to build object from CSV " + ex.Message)); } } } }
void GenerateData() { if (iso_code == "DEU") { string source = "https://raw.githubusercontent.com/jgehrcke/covid-19-germany-gae/master/data.csv"; List <CovidGermanyStates> obj = CovidSerializerExtension.FromCSVURL <CovidGermanyStates>(source, CovidDataManager.csvConfig); addedSources.Add(new AddedSource() { source = source + " - RKI & Spiegel Online Datensatz von JGehrecke @GitHub", value = obj }); string sourceRKI = "https://opendata.arcgis.com/datasets/917fc37a709542548cc3be077a786c17_0.csv"; List <RKILandkreis> objRKI = CovidSerializerExtension.FromCSVURL <RKILandkreis>(sourceRKI, CovidDataManager.csvConfig); addedSources.Add(new AddedSource() { source = sourceRKI + " - Datensatz zu Landkreisen direkt vom Robert Koch Institut", value = objRKI }); //string sourceRKIGeneral = "https://opendata.arcgis.com/datasets/dd4580c810204019a7b8eb3e0b329dd6_0.csv"; //List<RKIGeneral> objRKIGeneral = CovidCSVExtension.FromCSV<RKIGeneral>(sourceRKIGeneral, CovidDataManager.csvConfig); //addedSources.Add(new AddedSource() { source = sourceRKIGeneral + " - Datensatz zu allgemeinen Daten direkt vom Robert Koch Institut", value = objRKIGeneral }); } if (iso_code == "USA") { string source = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/live/us-states.csv"; List <CovidUSStates> obj = CovidSerializerExtension.FromCSVURL <CovidUSStates>(source, CovidDataManager.csvConfig); addedSources.Add(new AddedSource() { source = source + " - Dataset by New York Times", value = obj }); } if (iso_code == "BRA") { string source = "https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv"; List <CovidBrazilStates> obj = CovidSerializerExtension.FromCSVURL <CovidBrazilStates>(source, CovidDataManager.csvConfig); addedSources.Add(new AddedSource() { source = source + " - Casos e óbitos confirmados por dia, utilizando informação oficial pelo Ministério da Saúde", value = obj }); } }
public async static void UpdateData() { try { string source = "https://covid.ourworldindata.org/data/owid-covid-data.csv"; IEnumerable <CovidCountry> countries = CovidSerializerExtension.FromCSVURL <CovidCountry>(source, csvConfig); if (countries != null) { covidCountries = countries.ToList(); dataConfigs = covidCountries .GroupBy(p => p.iso_code) .Select(g => g.First()) .Select(x => new DataConfig { iso_code = x.iso_code, location = x.location, continent = x.continent }).ToList(); } } catch { } await Task.Delay(TimeSpan.FromHours(1)); UpdateData(); }
public IActionResult SaveCSV(string url, string iso_code, string location) { try { List <object> obj = CovidSerializerExtension.FromCSVURL <object>(url, CovidDataManager.csvConfig); AddedExternalSource externalSource = new AddedExternalSource(); externalSource.iso_code = iso_code.ToUpper(); externalSource.location = location; externalSource.url = url; string path = System.IO.Directory.GetCurrentDirectory() + "\\sources.json"; if (System.IO.File.Exists(path)) { string json = System.IO.File.ReadAllText(path); CovidDataManager.externalSources.AddRange(new List <AddedExternalSource>().FromJson(json)); } CovidDataManager.externalSources.Add(externalSource); System.IO.File.WriteAllText(path, CovidDataManager.externalSources.ToJson()); return(Ok()); } catch (Exception ex) { return(StatusCode(400, "Error attempting to save config to file " + ex.Message)); } }