public JhState(string stateName)
 {
     State       = StateMapHelper.StringToStateMap(stateName);
     StateString = stateName;
     CovidData   = new List <JhCovidDay>();
 }
Exemple #2
0
        public async void CtpToJHTransition(List <State> CtpData)
        {
            StorageFolder exportFolder = null;

            if (StorageApplicationPermissions.FutureAccessList.ContainsItem("ExportFolder"))
            {
                DateTime currentDate = new DateTime(2020, 3, 2);
                DateTime endDate     = new DateTime(2020, 4, 11);
                while (currentDate <= endDate)
                {
                    exportFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("ExportFolder");

                    StorageFile csvFile = await exportFolder?.CreateFileAsync(currentDate.Date.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture) + ".csv", Windows.Storage.CreationCollisionOption.ReplaceExisting);

                    using (CsvFileWriter dataWriter = new CsvFileWriter(await csvFile.OpenStreamForWriteAsync()))
                    {
                        CsvRow headerRow = new CsvRow();
                        headerRow.Add("Province_State");
                        headerRow.Add("Country_Region");
                        headerRow.Add("Last_Update");
                        headerRow.Add("Lat");
                        headerRow.Add("Long_");
                        headerRow.Add("Confirmed");
                        headerRow.Add("Deaths");
                        headerRow.Add("Recovered");
                        headerRow.Add("Active");
                        headerRow.Add("FIPS");
                        headerRow.Add("Incident_Rate");
                        headerRow.Add("Total_Test_Results");
                        headerRow.Add("People_Hospitalized");
                        headerRow.Add("Case_Fatality_Ratio");
                        headerRow.Add("UID");
                        headerRow.Add("ISO3");
                        headerRow.Add("Testing_Rate");
                        headerRow.Add("Testing_Rate");

                        dataWriter.WriteRow(headerRow);
                        foreach (State s in CtpData)
                        {
                            var dataPoint = s.CovidData.FirstOrDefault(dat => dat.Date.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture) == currentDate.Date.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture));
                            if (dataPoint != null)
                            {
                                CsvRow nextRow = new CsvRow();
                                nextRow.Add(StateMapHelper.StateBaseToString(s.StateBase.Name));
                                nextRow.Add("US");
                                nextRow.Add(currentDate.Date.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture) + " 4:30:00 PM");
                                nextRow.Add("");
                                nextRow.Add("");

                                if (dataPoint.Positive != null)
                                {
                                    nextRow.Add(dataPoint.Positive.ToString());
                                }
                                else
                                {
                                    nextRow.Add("0");
                                }

                                if (dataPoint.Death != null)
                                {
                                    nextRow.Add(dataPoint.Death.ToString());
                                }
                                else
                                {
                                    nextRow.Add("0");
                                }

                                nextRow.Add(""); //Recovered
                                nextRow.Add(""); //active
                                nextRow.Add(""); // FIPS
                                nextRow.Add(""); // Incident_Rate

                                if (dataPoint.TotalTestResults != null)
                                {
                                    nextRow.Add(dataPoint.TotalTestResults.ToString());
                                }
                                else
                                {
                                    nextRow.Add("0");
                                }

                                if (dataPoint.Hospitalized != null)
                                {
                                    nextRow.Add(dataPoint.Hospitalized.ToString());
                                }
                                else
                                {
                                    nextRow.Add("0");
                                }

                                if (dataPoint.Positive > 0)
                                {
                                    nextRow.Add(((Convert.ToDouble(dataPoint.Death) / Convert.ToDouble(dataPoint.Positive)) * 100).ToString());
                                }
                                else
                                {
                                    nextRow.Add("0.0");
                                }
                                nextRow.Add(""); // UID
                                nextRow.Add(""); // ISO3
                                nextRow.Add(""); // TestingRate
                                nextRow.Add(""); // Hospitalization Rate

                                dataWriter.WriteRow(nextRow);
                            }
                            else
                            {
                                CsvRow nextRow = new CsvRow();
                                nextRow.Add(s.StateBase.Name.ToString());
                                nextRow.Add("US");
                                nextRow.Add(currentDate.Date.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture) + " 4:30:00 PM");
                                nextRow.Add("");
                                nextRow.Add("");
                                nextRow.Add("0");
                                nextRow.Add("0");
                                nextRow.Add(""); //Recovered
                                nextRow.Add(""); //active
                                nextRow.Add(""); // FIPS
                                nextRow.Add(""); // Incident_Rate
                                nextRow.Add("0");
                                nextRow.Add("0");
                                nextRow.Add("0.0");
                                nextRow.Add(""); // UID
                                nextRow.Add(""); // ISO3
                                nextRow.Add(""); // TestingRate
                                nextRow.Add(""); // Hospitalization Rate

                                dataWriter.WriteRow(nextRow);
                            }
                        }

                        currentDate = currentDate + new TimeSpan(1, 0, 0, 0);
                    }
                }
            }
        }