public async void GetData()
        {

            Status = "Loading data...";
            IsCollectingData = true;

            if (UseCovidDataSource)
            {

                StateData.Clear();
                var rawStateData = await ctService.GetHistoricStateData();
                var stateBaseInfo = StatesConstants.GetStatesList();
                foreach (StateBase sb in stateBaseInfo)
                {
                    var newState = new State(sb);
                    newState.CovidData = rawStateData.FindAll(sd => sd.State.ToString().ToLower() == newState.StateBase.Code.ToString().ToLower());
                    StateData.Add(newState);
                }

                // Add the vaccine data here
                // Send in a StateData value and then add the values to the state data day by day

                if (SortStatesByRegion)
                {
                    StateData = PerformStateSortByRegion(StateData);
                }

            }
            else if (UseOwidSource)
            {
                CountryData.Clear();
                CountryData = await owidService.GetAllWorldData();

                CountryData = CountryData.OrderBy(c => c.CountryName).ToList();

                if (SortCountriesByContinent)
                {
                    CountryData = PerformCountrySort(CountryData);
                }

                if (FilterSmallCountries)
                {
                    CountryData = PerformSmallCountryFilter(CountryData);
                }
            }

            IsCollectingData = false;
            isDataLoaded = true;

            Status = "Data Loaded!";
        }
        public async Task <List <State> > GetAllStateData()
        {
            List <StateBase> basicStates = StatesConstants.GetStatesList();
            var returnData   = new List <State>();
            var allStateData = await GetHistoricStateData();

            foreach (StateBase stateBase in basicStates)
            {
                var state = new State(stateBase);
                state.CovidData = allStateData.FindAll(sData => sData.State.ToLower() == stateBase.Code.ToString().ToLower());
                returnData.Add(state);
            }

            return(returnData);
        }
        public async void LoadVaccineData()
        {
            Status = "Loading Vaccine Data";
            // Step 1: select folder for vaccine data 
            //Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            var picker = new Windows.Storage.Pickers.FolderPicker();
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            picker.FileTypeFilter.Add("*");

            var vaccineFolder = await picker.PickSingleFolderAsync();
            if (vaccineFolder != null)
            {
                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("VaccineFolder", vaccineFolder);
            } else { return; }

            // Step 2: suck in all the data
            var vaccineFiles = await vaccineFolder.GetFilesAsync();
            foreach (StorageFile file in vaccineFiles)
            {
                // Suck in the data and add it to the list
                string vaccineData = await Windows.Storage.FileIO.ReadTextAsync(file);
                var vaccineDay = JsonConvert.DeserializeObject<VaccineSet>(vaccineData);
                if(vaccineDay != null) { 
                    vaccineDay.VaccineSetDate = vaccineDay.VaccineDay?.First()?.DataDate!= null ? vaccineDay.VaccineDay.First().DataDate : DateTime.Now;
                    RawVaccineData.Add(vaccineDay);
                }
            }

            //Step 3: Organize the data into state info
            StateVaccineData.Clear();
            var stateBaseInfo = StatesConstants.GetStatesList().Concat(StatesConstants.GetVaccineExtrasList());
            
            foreach (StateBase sb in stateBaseInfo)
            {
                var newState = new VaccineState(sb);
                foreach (VaccineSet vs in RawVaccineData)
                {
                    var vaccineDay = vs.VaccineDay.First(vd => vd.StateCode.ToString().ToLower() == newState.StateBase.Code.ToString().ToLower());
                    newState.VaccineData.Add(new VaccineDay(vaccineDay));
                }
                StateVaccineData.Add(newState);
            }

            StateVaccineData = PerformStateVaccineSortByRegion(StateVaccineData);
        }
Exemple #4
0
        static async Task <string> GetData(string rawInput, CovidTrackService cService)
        {
            string[] parameters = rawInput.Split(' ');

            if (parameters.Length >= 2 && parameters[0] == "get")
            {
                // Did they request data for the US or a state
                if (parameters[1].ToLower() == "us")
                {
                    // Is there a time-based parameter?
                    if (parameters.Length == 3)
                    {
                        // Is it today?
                        if (parameters[2].ToLower() == "today")
                        {
                            var result = await cService.GetCurrentUsData();

                            return("Current US Data \n " + FormatDayData(result.FirstOrDefault()));
                        }
                        else
                        {
                            // Parse the input date
                            string[] dateParams = parameters[2].Split('/');
                            if (dateParams.Length == 3)
                            {
                                var date = new DateTime(Int32.Parse(dateParams[2]), Int32.Parse(dateParams[0]), Int32.Parse(dateParams[1]));

                                // Was it a valid input?
                                if (date != null)
                                {
                                    var result = await cService.GetUsDataOnDate(date);

                                    return(FormatDayData(result));
                                }
                            }
                        }
                    }
                    else
                    {
                        // OK, no date. Just dump that data out
                        var result = await cService.GetHistoricUsData();

                        string printResult = "";
                        foreach (UsDay day in result)
                        {
                            printResult += FormatDayData(day);
                        }

                        return(printResult);
                    }
                }
                else
                {
                    var stateParam = parameters[1];

                    if (stateParam == "all")
                    {
                        var result = await cService.GetHistoricStateData();

                        string printResult = "";
                        foreach (StateDay stateDay in result)
                        {
                            printResult += FormatStateDayData(stateDay);
                        }
                        return(printResult);
                    }

                    // We want to turn that state code into a state object, b/c that's more flexible
                    var states      = StatesConstants.GetStatesList();
                    var targetState = states.FirstOrDefault(aState => aState.Code.ToString().ToLower() == stateParam.ToLower());

                    // Is there a time-based parameter?
                    if (parameters.Length == 3)
                    {
                        // Is it today?
                        if (parameters[2].ToLower() == "today")
                        {
                            var result = await cService.GetCurrentStateData(targetState.Code);

                            return(FormatStateDayData(result));
                        }
                        else
                        {
                            // Parse the input date
                            string[] dateParams = parameters[2].Split('/');
                            if (dateParams.Length == 3)
                            {
                                var date = new DateTime(Int32.Parse(dateParams[2]), Int32.Parse(dateParams[0]), Int32.Parse(dateParams[1]));

                                // Was it a valid input?
                                if (date != null)
                                {
                                    var result = await cService.GetStateDataByDate(targetState.Code, date);

                                    return(FormatStateDayData(result));
                                }
                            }
                        }
                    }
                    else
                    {
                        var result = await cService.GetHistoricStateData(targetState.Code);

                        string printResult = "";
                        foreach (StateDay stateDay in result)
                        {
                            printResult += FormatStateDayData(stateDay);
                        }
                        return(printResult);
                    }
                }
            }
            return("sorry, that didn't work");
        }
        public static StateBase StringToStateMap(string stateString)
        {
            var listOfStates = StatesConstants.GetStatesList();

            switch (stateString.ToLower())
            {
            case "alabama":
            case "al":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.AL));

            case "alaska":
            case "ak":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.AK));

            case "american samoa":
            case "americansamoa":
            case "as":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.AS));

            case "arizona":
            case "az":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.AZ));

            case "arkansas":
            case "ar":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.AR));

            case "california":
            case "ca":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.CA));

            case "colorado":
            case "co":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.CO));

            case "connecticut":
            case "ct":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.CT));

            case "delaware":
            case "de":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.DE));

            case "districtofcolumbia":
            case "district of columbia":
            case "washingtondc":
            case "dc":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.DC));

            case "florida":
            case "fl":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.FL));

            case "georgia":
            case "ga":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.GA));

            case "guam":
            case "gu":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.GU));

            case "hawaii":
            case "hi":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.HI));

            case "idaho":
            case "id":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.ID));

            case "illinois":
            case "il":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.IL));

            case "indiana":
            case "in":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.IN));

            case "iowa":
            case "ia":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.IA));

            case "kansas":
            case "ks":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.KS));

            case "kentucky":
            case "ky":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.KY));

            case "louisiana":
            case "la":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.LA));

            case "maine":
            case "me":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.ME));

            case "maryland":
            case "md":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MD));

            case "massachusetts":
            case "ma":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MA));

            case "michigan":
            case "mi":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MI));

            case "minnesota":
            case "mn":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MN));

            case "mississippi":
            case "ms":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MS));

            case "missouri":
            case "mo":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MO));

            case "montana":
            case "mt":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.MT));

            case "nebraska":
            case "ne":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NE));

            case "nevada":
            case "nv":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NV));

            case "new hampshire":
            case "newhampshire":
            case "nh":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NH));

            case "new jersey":
            case "newjersey":
            case "nj":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NJ));

            case "new mexico":
            case "newmexico":
            case "nm":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NM));

            case "new york":
            case "newyork":
            case "ny":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NY));

            case "north carolina":
            case "northcarolina":
            case "nc":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.NC));

            case "north dakota":
            case "northdakota":
            case "nd":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.ND));

            case "ohio":
            case "oh":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.OH));

            case "oklahoma":
            case "ok":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.OK));

            case "oregon":
            case "or":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.OR));

            case "pennsylvania":
            case "pa":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.PA));

            case "puerto rico":
            case "puertorico":
            case "pr":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.PR));

            case "rhode island":
            case "rhodeisland":
            case "ri":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.RI));

            case "south carolina":
            case "southcarolina":
            case "sc":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.SC));

            case "south dakota":
            case "southdakota":
            case "sd":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.SD));

            case "tennessee":
            case "tn":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.TN));

            case "texas":
            case "tx":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.TX));

            case "utah":
            case "ut":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.UT));

            case "vermont":
            case "vt":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.VT));

            case "virgin islands":
            case "virginislands":
            case "vi":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.VI));

            case "virginia":
            case "va":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.VA));

            case "washington":
            case "wa":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.WA));

            case "west virginia":
            case "westvirginia":
            case "wv":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.WV));

            case "wisconsin":
            case "wi":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.WI));

            case "wyoming":
            case "wy":
                return(listOfStates.FirstOrDefault(s => s.Code == Constants.StateCode.WY));

            default:
                Debug.WriteLine("Bad State - " + stateString.ToLower());
                return(null);
            }
        }