public void SickTest() { CovidRecord covidRecord = new CovidRecord(5, "Rungsted", 4, 2, 1); Assert.AreEqual(1, covidRecord.Sick); Assert.ThrowsException <ArgumentOutOfRangeException>(() => covidRecord.Sick = -1); }
private static CovidRecord createCovidRecord(string record) { var fields = record.Split(Assets.CsvDelimiter); CovidRecord covidRecord; if (!doesRecordHaveNoErrors(fields)) { return(null); } try { covidRecord = new CovidRecord(Format.FormatAsDateTime(fields[Assets.ColumnNumberForDate]), fields[Assets.ColumnNumberForState]) { PositiveTests = Format.FormatStringToInteger(fields[Assets.ColumnNumberForPositives]), NegativeTests = Format.FormatStringToInteger(fields[Assets.ColumnNumberForNegatives]), HospitalizedCurrently = Format.FormatStringToInteger(fields[Assets.ColumnNumberForHospitalizedCurrently]), Hospitalizations = Format.FormatStringToInteger(fields[Assets.ColumnNumberForHospitalizations]), Deaths = Format.FormatStringToInteger(fields[Assets.ColumnNumberForDeaths]) }; } catch (Exception e) { Console.WriteLine(e); covidRecord = null; } return(covidRecord); }
public async Task <IActionResult> PutCovidRecord(int id, CovidRecord covidRecord) { if (id != covidRecord.Id) { return(BadRequest()); } _context.Entry(covidRecord).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CovidRecordExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CityTest() { CovidRecord covidRecord = new CovidRecord(5, "Rungsted", 4, 2, 1); Assert.AreEqual("Rungsted", covidRecord.City); Assert.ThrowsException <ArgumentException>(() => covidRecord.City = "R"); }
public void HouseholdTest() { CovidRecord covidRecord = new CovidRecord(5, "Rungsted", 4, 2, 1); Assert.AreEqual(4, covidRecord.Household); Assert.ThrowsException <ArgumentOutOfRangeException>(() => covidRecord.Household = 0); }
public int AddRecord([FromBody] CovidRecord covidRecord) { covidRecords.Add(covidRecord); int newId = covidRecords.Max(c => c.Id) + 1; covidRecord.Id = newId; return(newId); }
public void GetByIdTest() { CovidRecord result = ctx.GetById(1); Assert.AreEqual(1, result.Id); result = ctx.GetById(1000); Assert.IsNull(result); }
public void CovidRecordTest() { CovidRecord covidRecord = new CovidRecord(1, "Nykøbing SJ", 4, 4, 2); Assert.AreEqual(1, covidRecord.Id); Assert.AreEqual("Nykøbing SJ", covidRecord.City); Assert.AreEqual(4, covidRecord.Household); Assert.AreEqual(4, covidRecord.Tested); Assert.AreEqual(2, covidRecord.Sick); }
public async Task <ActionResult <CovidRecord> > PostCovidRecord(CovidRecord covidRecord) { covidRecord.Id = IDCounter; _context.CovidRecords.Add(covidRecord); await _context.SaveChangesAsync(); //return CreatedAtAction("GetCovidRecord", new { id = covidRecord.Id }, covidRecord); IDCounter++; return(CreatedAtAction(nameof(GetCovidRecord), new { id = covidRecord.Id }, covidRecord)); }
/// <summary>Does the covid record exist.</summary> /// <param name="record">The record.</param> /// <returns>True if record is present in the CovidDataCollection, false otherwise.</returns> public bool DoesCovidRecordExist(CovidRecord record) { var doesCovidRecordExist = false; if (this.IsCovidDataLoaded) { doesCovidRecordExist = this.AllCovidData.Contains(record); } return(doesCovidRecordExist); }
public void TestOneItemCovidDataCollectionNoPositiveTest() { var record = new CovidRecord(DateTime.Now, "GA"); var covidCollection = new CovidDataCollection { record }; var statistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => statistics.FindDayOfFirstPositiveTest()); }
public void PostTest() { CovidRecord r = new CovidRecord { Id = 23, City = "Holte", Household = 5, Sick = 0, Tested = 5 }; ctx.AddRecord(r); IEnumerable <CovidRecord> result = ctx.GetAllRecords(); Assert.AreEqual(6, result.Count()); }
public void constructorTest() { try { CovidRecord test = new CovidRecord(2, "a", 0, -1, -1); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual("mindst 2 tegn", ex.Message); } }
private void addCovidRecordToExistingCollection(CovidRecord record) { if (record.State.Equals(this.StateFilter)) { this.FilteredCovidDataCollection.Add(record); this.AllCovidData.Add(record); } else { this.AllCovidData.Add(record); } }
public void TestOneItemCovidDataCollectionOnePositiveTest() { var record = new CovidRecord(this.inputDate1, "GA") { PositiveTests = 1 }; var covidCollection = new CovidDataCollection { record }; var statistics = new CovidDataStatistics(covidCollection); var result = statistics.FindDayOfFirstPositiveTest(); Assert.AreEqual(this.inputDate1, result.Date); }
/// <summary>Replaces the Covid covidRecord with the covidRecord passed in to it.</summary> /// <param name="covidRecord">The covidRecord.</param> public void ReplaceRecord(CovidRecord covidRecord) { if (this.mergeController == null) { this.FilteredCovidDataCollection.ReplaceDuplicateRecords(covidRecord); this.AllCovidData.ReplaceDuplicateRecords(covidRecord); this.buildCovidSummary(); return; } this.mergeController.ReplaceDuplicate(covidRecord); this.FilteredCovidDataCollection = this.mergeController.MergedCovidDataCollection; this.IsCovidDataLoaded = true; this.mergeAndRebuildAllCovidData(); }
/// <summary>Adds the covid record to collection or creates a new collection if there is not a collection present.</summary> /// <param name="record">The record.</param> public void AddCovidRecordToCollection(CovidRecord record) { if (this.IsCovidDataLoaded) { this.addCovidRecordToExistingCollection(record); } else { this.createAndAddToTheCovidDataCollection(record); } if (this.FilteredCovidDataCollection != null) { this.buildCovidSummary(); } }
private void createAndAddToTheCovidDataCollection(CovidRecord record) { if (record.State.Equals(this.StateFilter)) { this.FilteredCovidDataCollection = new CovidDataCollection { record }; this.AllCovidData = this.FilteredCovidDataCollection.Clone(); this.IsCovidDataLoaded = true; } else { this.AllCovidData = new CovidDataCollection { record }; } }
private List <CovidRecord> ParseNewData() { List <CovidRecord> records = new List <CovidRecord>(); for (int i = 3; i <= 5; i++) { using (WebClient wc = new WebClient()) { var json = wc.DownloadString("https://api.covid19india.org/raw_data" + i.ToString() + ".json"); System.IO.File.WriteAllText("raw1.json", json); //var json = System.IO.File.ReadAllText("raw1.json"); QuickType.raw_data deserializedRecords = JsonConvert.DeserializeObject <QuickType.raw_data>(json); var rows = deserializedRecords.RawData; CultureInfo MyCultureInfo = new CultureInfo("hi-IN"); foreach (Dictionary <string, string> row in rows) { if (string.IsNullOrWhiteSpace(row["dateannounced"]) || string.IsNullOrWhiteSpace(row["currentstatus"]) || string.IsNullOrWhiteSpace(row["numcases"])) { continue; } if (row["currentstatus"] == "Hospitalized") { CovidRecord covidRecord = new CovidRecord { CurrentStatus = row["currentstatus"], DateAnnounced = DateTime.Parse(row["dateannounced"], MyCultureInfo), State = row["detectedstate"], District = (string.IsNullOrWhiteSpace(row["detecteddistrict"]) ? "Unknown" : row["detecteddistrict"]) + " [" + row["detectedstate"] + "]", NoCases = int.Parse(row["numcases"]) }; records.Add(covidRecord); } } } } return(records); }
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { var date = this.covidRecordDate.Date.Date; var state = this.determineStateComboBoxSelectedItem(); var positiveCases = Format.FormatStringToInteger(this.positiveCasesTextBox.Text); var negativeCases = Format.FormatStringToInteger(this.negativeCasesTextBox.Text); var currentlyHospitalized = Format.FormatStringToInteger(this.hospitalizedCurrentlyTextBox.Text); var hospitalizations = Format.FormatStringToInteger(this.hospitalizationsTextBox.Text); var deaths = Format.FormatStringToInteger(this.deathsTextBox.Text); this.CreatedRecord = new CovidRecord(date, state) { PositiveTests = positiveCases, NegativeTests = negativeCases, HospitalizedCurrently = currentlyHospitalized, Hospitalizations = hospitalizations, Deaths = deaths }; }
public CovidRecord GetCountryOnDate(string CountryName, int Year, int Month, int Day) { DateTime from = new DateTime(Year, Month, Day); TimeSpan oneDay = new TimeSpan(1, 0, 0, 0); DateTime to = from + oneDay; var result = _country.AsQueryable().Where(country => country.CountryName == CountryName) .Select(country => new { arrayVal = country.Records.Where(cv => cv.Last_Update >= from & cv.Last_Update < to) }); CovidRecord toRet = new CovidRecord(); foreach (var x in result) { foreach (var y in x.arrayVal) { toRet = y; } } return(toRet); }
public void TestMultipleItemCovidDataCollectionLastPlace() { var record1 = new CovidRecord(this.inputDate1, "GA"); var record2 = new CovidRecord(this.inputDate2, "GA"); var record3 = new CovidRecord(this.inputDate3, "GA") { PositiveTests = 1 }; var covidCollection = new CovidDataCollection { record1, record2, record3 }; var statistics = new CovidDataStatistics(covidCollection); var result = statistics.FindDayOfFirstPositiveTest(); Assert.AreEqual(this.inputDate3, result.Date); }
/// <summary>Sets the duplicate record string representation to the current value of the covidRecordTextBlock.</summary> /// <param name="covidRecord">The covid record.</param> /// <exception cref="ArgumentNullException">covidRecord</exception> public void SetDuplicateRecord(CovidRecord covidRecord) { covidRecord = covidRecord ?? throw new ArgumentNullException(nameof(covidRecord)); this.covidRecordTextBlock.Text = covidRecord.ToString(); }
private List <CovidRecord> AppendUsaRecordToAllCountriesRecords(ICollection <CovidRecord> allCountries, CovidRecord usaMapRecord, BsonDocument usaRecord) { var usaRecordParsed = BsonSerializer.Deserialize <CovidRecord>(usaRecord); usaRecordParsed.Lat = usaMapRecord.Lat; usaRecordParsed.Long = usaMapRecord.Long; usaRecordParsed.CountryRegion = "United States"; usaRecordParsed.FIPS = DefaultValues.DEFAULT_STRING; allCountries.Add(usaRecordParsed); return(allCountries.OrderBy(record => record.CountryRegion).ToList()); }
public int AddRecord(CovidRecord record) { record.Id = _nextId++; liste.Add(record); return(record.Id); }
public void IdTest() { CovidRecord covidRecord = new CovidRecord(5, "Rungsted", 4, 2, 1); Assert.AreEqual(5, covidRecord.Id); }
internal void GenerateActiveData(List <CovidRecord> parsedData) { // Group by district and state var stateDisctrictGrouping = parsedData .GroupBy(x => new { x.State, x.District }) .Select(y => new { State = y.Key.State, District = y.Key.District, Records = y.Sum(x => x.NoCases) } ).OrderByDescending(x => x.Records).ToList(); // Select only top 25 districts from each state var states = stateDisctrictGrouping.Select(y => y.State).Distinct(); var districtParsedData = new CovidRecord[parsedData.Count()]; parsedData.CopyTo(districtParsedData); var districtParsedDataList = districtParsedData.ToList(); foreach (var state in states) { var bottomDistricts = stateDisctrictGrouping.Where(y => y.State == state) .Select(y => y.District).Skip(25).ToList(); foreach (var district in bottomDistricts) { var count = districtParsedDataList.RemoveAll(y => y.District == district); } } districtParsedDataList = districtParsedDataList.OrderBy(y => y.DateAnnounced).ToList(); List <CovidRecord> districtGroup = districtParsedDataList .GroupBy(x => new { x.DateAnnounced, x.State, x.District }) .Select(y => new CovidRecord { DateAnnounced = y.Key.DateAnnounced, District = y.Key.District, NoCases = y.Sum(x => x.NoCases) } ).ToList(); // Create cumulative counts for (int i = 0; i < districtGroup.Count(); i++) { var group = districtGroup[i]; var lastLocation = districtGroup.Where(x => x.DateAnnounced < group.DateAnnounced && x.District == group.District).LastOrDefault(); if (lastLocation != null) { group.NoCases = lastLocation.NoCases + group.NoCases; } } var districtGroupAnony = districtGroup.Select(x => new { DateAnnounced = x.DateAnnounced, Location = x.District, Records = x.NoCases }); string jsonDistrict = JsonConvert.SerializeObject(districtGroupAnony); System.IO.File.WriteAllText("output/output_districts_active.json", jsonDistrict); // Group by State List <CovidRecord> stateGroup = parsedData .GroupBy(x => new { x.DateAnnounced, x.State }) .Select(y => new CovidRecord { DateAnnounced = y.Key.DateAnnounced, State = y.Key.State, NoCases = y.Sum(x => x.NoCases) } ).ToList(); // Create cumulative counts for (int i = 0; i < stateGroup.Count(); i++) { var group = stateGroup[i]; var lastLocation = stateGroup.Where(x => x.DateAnnounced < group.DateAnnounced && x.State == group.State).LastOrDefault(); if (lastLocation != null) { group.NoCases = lastLocation.NoCases + group.NoCases; } } var stateGroupAnony = stateGroup.Select(x => new { DateAnnounced = x.DateAnnounced, Location = x.State, Records = x.NoCases }); string jsonState = JsonConvert.SerializeObject(stateGroupAnony); System.IO.File.WriteAllText("output/output_states_active.json", jsonState); // Group by country List <CovidRecord> countryGroup = parsedData .GroupBy(x => new { x.DateAnnounced }) .Select(y => new CovidRecord { DateAnnounced = y.Key.DateAnnounced, State = "India", NoCases = y.Sum(x => x.NoCases) } ).ToList(); // Create cumulative counts for (int i = 0; i < countryGroup.Count(); i++) { var group = countryGroup[i]; var lastLocation = countryGroup.Where(x => x.DateAnnounced < group.DateAnnounced && x.State == group.State).LastOrDefault(); if (lastLocation != null) { group.NoCases = lastLocation.NoCases + group.NoCases; } } var countryGroupAnony = countryGroup.Select(x => new { DateAnnounced = x.DateAnnounced, Location = x.State, Records = x.NoCases }); string jsonCountry = JsonConvert.SerializeObject(countryGroupAnony); System.IO.File.WriteAllText("output/output_country_active.json", jsonCountry); }
internal void GenerateGrowthData(List <CovidRecord> parsedData) { // Group by district and state var stateDisctrictGrouping = parsedData .GroupBy(x => new { x.State, x.District }) .Select(y => new { State = y.Key.State, District = y.Key.District, Records = y.Sum(x => x.NoCases) } ).OrderByDescending(x => x.Records).ToList(); // Select only top 25 districts from each state var states = stateDisctrictGrouping.Select(y => y.State).Distinct(); var districtParsedData = new CovidRecord[parsedData.Count()]; parsedData.CopyTo(districtParsedData); var districtParsedDataList = districtParsedData.ToList(); foreach (var state in states) { var bottomDistricts = stateDisctrictGrouping.Where(y => y.State == state) .Select(y => y.District).Skip(25).ToList(); foreach (var district in bottomDistricts) { var count = districtParsedDataList.RemoveAll(y => y.District == district); } } districtParsedDataList = districtParsedDataList.OrderBy(y => y.DateAnnounced).ToList(); var districtGroup = districtParsedDataList .GroupBy(x => new { x.DateAnnounced, x.District }) .Select(y => new { DateAnnounced = y.Key.DateAnnounced, Location = y.Key.District, Records = y.Sum(x => x.NoCases) } ); string jsonDistrict = JsonConvert.SerializeObject(districtGroup); System.IO.File.WriteAllText("output/output_districts_growth.json", jsonDistrict); // Group by State var stateGroup = parsedData .GroupBy(x => new { x.DateAnnounced, x.State }) .Select(y => new { DateAnnounced = y.Key.DateAnnounced, Location = y.Key.State, Records = y.Sum(x => x.NoCases) } ); string jsonState = JsonConvert.SerializeObject(stateGroup); System.IO.File.WriteAllText("output/output_states_growth.json", jsonState); // Group by country var countryGroup = parsedData .GroupBy(x => new { x.DateAnnounced }) .Select(y => new { DateAnnounced = y.Key.DateAnnounced, Location = "India", Records = y.Sum(x => x.NoCases) } ); string jsonCountry = JsonConvert.SerializeObject(countryGroup); System.IO.File.WriteAllText("output/output_country_growth.json", jsonCountry); //States list List <string> uniqueStatesList = parsedData .GroupBy(p => new { p.State }) .Select(g => g.First().State) .ToList(); string jsonStatesList = JsonConvert.SerializeObject(uniqueStatesList); System.IO.File.WriteAllText("output/states_names.json", jsonStatesList); }
public void TestEmptyConstructor() { covidRecord = new CovidRecord(); }
public void BeforeTest() { _record = new CovidRecord(1, "jyllinge", 2, 1, 1); }