Exemplo n.º 1
0
        //On Country button click
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Write Category Label only once - dont waste resources
            if (leftLabel.Content.Equals(""))
            {
                showCategories();
            }

            //Use query to get desired country based, on button content
            Button     btnClicked  = (Button)sender;
            JsonObject countryJSON = GetJSON.GetData(string.Join(",", CountryJsonLink.abbreviationMap.Where(n => n.Key.Equals(btnClicked.Content)).Select(n => n.Value).ToArray()));

            //Write all the data from API
            rightLabel.FontWeight = FontWeight.FromOpenTypeWeight(150);
            rightLabel.Content    = countryJSON.countrydata[0].info.title + "\n" +
                                    countryJSON.countrydata[0].total_new_cases_today + "\n" +
                                    countryJSON.countrydata[0].total_new_deaths_today + "\n" +
                                    countryJSON.countrydata[0].total_cases + "\n" +
                                    countryJSON.countrydata[0].total_deaths + "\n" +
                                    countryJSON.countrydata[0].total_unresolved + "\n" +
                                    countryJSON.countrydata[0].total_recovered + "\n" +
                                    countryJSON.countrydata[0].total_active_cases + "\n" +
                                    countryJSON.countrydata[0].total_serious_cases + "\n" +
                                    countryJSON.countrydata[0].total_danger_rank + "\n";
        }
Exemplo n.º 2
0
        private void btn_count(object sender, RoutedEventArgs e)
        {
            int NumOfP = Int32.Parse(perDay.Text); // liczba ludzi spotykanych jednego dnia
            //int PerInContry;
            JsonObject CountryData = GetJSON.GetData(Country);
            int        TotalCases  = CountryData.countrydata[0].total_cases;

            Chance.Content = TotalCases / NumOfP;
        }
Exemplo n.º 3
0
 public void GetCountryLinkTest()
 {
     Assert.AreEqual("Poland", GetJSON.GetData(CountryJsonLink.addrPL).countrydata[0].info.title);
     Assert.AreEqual("Germany", GetJSON.GetData(CountryJsonLink.addrDE).countrydata[0].info.title);
     Assert.AreEqual("Czechia", GetJSON.GetData(CountryJsonLink.addrCZ).countrydata[0].info.title);
     Assert.AreEqual("Slovakia", GetJSON.GetData(CountryJsonLink.addrSK).countrydata[0].info.title);
     Assert.AreEqual("Ukraine", GetJSON.GetData(CountryJsonLink.addrUA).countrydata[0].info.title);
     Assert.AreEqual("Belarus", GetJSON.GetData(CountryJsonLink.addrBY).countrydata[0].info.title);
     Assert.AreEqual("Lithuania", GetJSON.GetData(CountryJsonLink.addrLT).countrydata[0].info.title);
     Assert.AreEqual("Russia", GetJSON.GetData(CountryJsonLink.addrRU).countrydata[0].info.title);
 }
Exemplo n.º 4
0
        public void GetCountryInfoTest()
        {
            JsonObject countryInfo;

            //Dispose WebClient resource immediately
            using (var client = new WebClient())
            {
                String trueJson = client.DownloadString(CountryJsonLink.addrDE);
                countryInfo = JsonConvert.DeserializeObject <JsonObject>(trueJson);
            }

            Assert.AreEqual(countryInfo, GetJSON.GetData(CountryJsonLink.addrDE));
        }
Exemplo n.º 5
0
        //Insert record
        public static String putIntoDB(string countryAddr)
        {
            //Assumption: Only data form PL
            if (!countryAddr.Equals(CountryJsonLink.addrPL))
            {
                Logger.log.Error("DB can only contain data from Poland :(");
                return("DB can only contain data from Poland :(");
            }

            JsonObject countryPL = GetJSON.GetData(countryAddr);

            //Create new data object
            var todayPoland = new HistoricalData
            {
                Date = DateTime.Now,
                Name = countryPL.countrydata[0].info.title,
                Total_active_cases    = countryPL.countrydata[0].total_active_cases - countryPL.countrydata[0].total_new_cases_today, //Take from yesterday
                Total_new_cases_today = countryPL.countrydata[0].total_new_cases_today
            };

            //Perform on DB
            using (var db = new HistoricalDataDBContext())
            {
                var record = db.Datas.OrderByDescending(n => n.Id).FirstOrDefault();

                //If Table == empty add first
                if (record == null)
                {
                    db.Datas.Add(todayPoland);
                    db.SaveChanges();
                    return("");
                }

                //Insert only if data from the following day does not exist
                if (!record.Date.Date.Equals(DateTime.Now.Date))
                {
                    db.Datas.Add(todayPoland);
                    db.SaveChanges();
                }
            }

            return("");
        }