public void TestEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var statistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => statistics.FindDayOfFirstPositiveTest()); }
/// <summary>Resets this instance to the start value.</summary> public void Reset() { this.Summary = string.Empty; this.IsCovidDataLoaded = false; this.covidErrorLogger = null; this.FilteredCovidDataCollection = null; this.AllCovidData = new CovidDataCollection(); this.mergeController = null; }
/// <Summary> /// Initializes a new instance of the /// <a onclick="return false;" href="CovidDataStateSummary" originaltag="see">CovidDataStateSummary</a> class. /// <para>If the stateFilter is empty, then the collection will not be filtered</para> /// <code>Precondition: collection != null</code> /// <code>Postcondition: CovidRecords == collection AND StateFilter == stateFilter </code> /// </Summary> /// <param name="collection">The collection.</param> /// <param name="stateFilter">The state filter for the collection</param> /// <exception cref="ArgumentNullException">collection</exception> public CovidDataSummary(CovidDataCollection collection, string stateFilter) { this.CovidRecords = collection ?? throw new ArgumentNullException(nameof(collection)); this.StateFilter = stateFilter ?? throw new ArgumentNullException(); var filteredCollection = collection.CreateAFilteredCollection(stateFilter); this.CovidRecords.ReplaceAllWithNewCovidCollection(filteredCollection); this.covidStatistics = new CovidDataStatistics(this.CovidRecords); }
public void TestFindEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => covidStatistics.FindNumberOfDaysForPositiveTestsLessThanThreshold(this.threshold)); }
public void TestFindThresholdLessThanZero() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <ArgumentOutOfRangeException>(() => covidStatistics.FindNumberOfDaysForPositiveTestsLessThanThreshold(-1)); }
public void TestAverageEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => covidStatistics.FindAverageTotalTestsSinceSpecifiedDate(this.defaultDate)); }
/// <summary>Loads the covid data from xml.</summary> /// <param name="xmlContent">Content of the xml.</param> /// <exception cref="ArgumentNullException">xmlContent</exception> public void LoadCovidData(CovidDataCollection xmlContent) { xmlContent = xmlContent ?? throw new ArgumentNullException(nameof(xmlContent)); this.FilteredCovidDataCollection = xmlContent; this.AllCovidData = this.FilteredCovidDataCollection.Clone(); this.IsCovidDataLoaded = true; this.buildCovidSummary(); }
public void TestEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>( () => covidStatistics.FindRecordWithHighestPositiveCases()); }
public void TestAverageOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindAveragePositiveTestsSinceFirstPositiveTest(); Assert.AreEqual(30, result); }
public void TestOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var record = covidStatistics.FindRecordWithHighestPositiveCases(); Assert.AreEqual(this.record1, record); }
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()); }
/// <summary>Loads the covid data from text.</summary> /// <param name="textContent">Content of the text.</param> /// <exception cref="ArgumentNullException">textContent</exception> public void LoadCovidData(string textContent) { textContent = textContent ?? throw new ArgumentNullException(nameof(textContent)); var parser = new CovidCsvParser(textContent); this.covidErrorLogger = parser.CovidErrorLogger; this.FilteredCovidDataCollection = parser.GenerateCovidDataCollection(); this.AllCovidData = this.FilteredCovidDataCollection.Clone(); this.IsCovidDataLoaded = true; this.buildCovidSummary(); }
public void TestFindARecordOnThreshold() { var covidCollection = new CovidDataCollection { this.record2, this.record3 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindNumberOfDaysForPositiveTestsLessThanThreshold(this.threshold); Assert.AreEqual(0, result); }
public void TestAverageOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindAverageTotalTestsSinceSpecifiedDate(this.defaultDate); Assert.AreEqual(30, result); }
public void TestMultipleItemCovidDataCollectionLastPlace() { var covidCollection = new CovidDataCollection { this.record1, this.record2, this.record3 }; var covidStatistics = new CovidDataStatistics(covidCollection); var record = covidStatistics.FindRecordWithHighestPositiveCases(); Assert.AreEqual(this.record3, record); }
public void TestAverageMultiItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1, this.record2, this.record3 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindAveragePositiveTestsSinceSpecifiedDate(this.defaultDate); Assert.AreEqual(40, result); }
public void TestReplaceSingleItemCollectionWithMatch() { var covidCollection = new CovidDataCollection { this.record1 }; var recordBeforeChange = covidCollection[0]; var isReplaced = covidCollection.ReplaceDuplicateRecords(this.record2); var recordAfterChange = covidCollection[0]; Assert.AreNotEqual(this.record2.PositiveTests, recordBeforeChange.PositiveTests); Assert.IsTrue(isReplaced); Assert.AreEqual(this.record2.PositiveTests, recordAfterChange.PositiveTests); }
public void TestOverallPositivityOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var positiveTestAverage = covidStatistics.FindAveragePositiveTestsSinceSpecifiedDate(this.defaultDate); var totalTestAverage = covidStatistics.FindAverageTotalTestsSinceSpecifiedDate(this.defaultDate); var expected = positiveTestAverage / totalTestAverage; var actual = covidStatistics.FindOverallPositivityRateSinceFirstPositiveTest(); Assert.AreEqual(expected, actual, Delta); }
private void mergeAndLoadCovidData(CovidDataCollection xmlContent, bool mergeAllStates) { this.covidDataAssembler.MergeAndLoadCovidData(xmlContent, mergeAllStates); var duplicates = this.covidDataAssembler.GetDuplicatesFromMergedData(); var covidRecords = duplicates as CovidRecord[] ?? duplicates.ToArray(); if (covidRecords.Any()) { this.keepOrReplaceDialog(covidRecords); } this.applyFilteredCollectionToViewModel(); this.summaryTextBox.Text = this.covidDataAssembler.Summary; }
/// <summary> /// Merges the and loads the covid data using xml content. /// </summary> /// <param name="xmlContent">Content of the XML.</param> /// <param name="mergeAllStates">if set to <c>true</c> [merge all states].</param> /// <exception cref="ArgumentNullException">xmlContent</exception> public void MergeAndLoadCovidData(CovidDataCollection xmlContent, bool mergeAllStates) { xmlContent = xmlContent ?? throw new ArgumentNullException(nameof(xmlContent)); var newCovidDataCollection = xmlContent; if (mergeAllStates) { this.FilteredCovidDataCollection = this.AllCovidData.Clone(); } this.mergeController = new CovidDataMergeController(this.FilteredCovidDataCollection, newCovidDataCollection); this.mergeController.AddAllNonDuplicates(); this.mergeAndRebuildAllCovidData(); }
/// <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(); }
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); }
public void TestReplaceMultipleItemCollection() { var covidCollection = new CovidDataCollection { this.record1, this.record3 }; var recordBeforeChange = covidCollection[0]; var isReplaced = covidCollection.ReplaceDuplicateRecords(this.record2); var recordAfterChange = covidCollection[1]; var unalteredRecord = covidCollection[0]; Assert.AreNotEqual(this.record2.PositiveTests, recordBeforeChange.PositiveTests); Assert.IsTrue(isReplaced); Assert.AreEqual(this.record2.PositiveTests, recordAfterChange.PositiveTests); Assert.AreEqual(this.record3.PositiveTests, unalteredRecord.PositiveTests); }
/// <summary> /// Merges the and loads the covid data using csv content. /// </summary> /// <param name="textContent">Content of the text.</param> /// <param name="mergeAllStates">if set to <c>true</c> [merge all states].</param> /// <exception cref="ArgumentNullException">textContent</exception> public void MergeAndLoadCovidData(string textContent, bool mergeAllStates) { textContent = textContent ?? throw new ArgumentNullException(nameof(textContent)); var parser = new CovidCsvParser(textContent); var newCovidDataCollection = parser.GenerateCovidDataCollection(); this.covidErrorLogger = parser.CovidErrorLogger; if (mergeAllStates) { this.FilteredCovidDataCollection = this.AllCovidData.Clone(); } this.mergeController = new CovidDataMergeController(this.FilteredCovidDataCollection, newCovidDataCollection); this.mergeController.AddAllNonDuplicates(); this.mergeAndRebuildAllCovidData(); }
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 void displayCovidData(CovidDataCollection xmlContent) { try { this.applyThresholds(); this.applyBinSize(); if (this.covidDataAssembler.IsCovidDataLoaded) { this.promptMergeOrReplaceDialog(xmlContent); } else { this.loadCovidData(xmlContent); } } catch (Exception exception) { Console.WriteLine(exception); this.summaryTextBox.Text = Assets.NoCovidDataText; } }
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); }
private async void promptMergeOrReplaceDialog(CovidDataCollection xmlContent) { var answer = await this.mergeOrReplaceDialog.ShowAsync(); switch (answer) { case ContentDialogResult.Primary: this.mergeAndLoadCovidData(xmlContent, false); break; case ContentDialogResult.Secondary: this.loadCovidData(xmlContent); break; case ContentDialogResult.None: break; default: this.mergeAndLoadCovidData(xmlContent, true); break; } this.applyFilteredCollectionToViewModel(); }
private void buildCovidSummary() { try { const string genericHeader = Assets.StateCovidDataHeadingLabel; this.FilteredCovidDataCollection = this.AllCovidData.Clone(); var stateSummary = new CovidDataSummary(this.FilteredCovidDataCollection, this.StateFilter); var isStateNotNull = this.StateFilter != null; var stateSpecificHeader = $"{this.StateFilter} {Assets.StateCovidDataHeadingLabel}"; this.Summary = string.Empty; this.Summary += isStateNotNull ? stateSpecificHeader : genericHeader; this.Summary += stateSummary.GetFirstDayOfPositiveTest(); this.Summary += stateSummary.GetHighestPositiveWithDate(); this.Summary += stateSummary.GetHighestNegativeWithDate(); this.Summary += stateSummary.GetHighestTotalTestsWithDate(); this.Summary += stateSummary.GetHighestDeathsWithDate(); this.Summary += stateSummary.GetHighestHospitalizationsWithDate(); this.Summary += stateSummary.GetHighestCurrentHospitalizationsWithDate(); this.Summary += stateSummary.GetHighestPercentageOfTestsPerDayWithDate(); this.Summary += stateSummary.GetAveragePositiveTestsSinceFirstPositiveTest(); this.Summary += stateSummary.GetOverallPositivityRateSinceFirstPositiveTest(); this.Summary += this.getPositiveThresholds(stateSummary); this.Summary += this.getHistogram(stateSummary); this.Summary += stateSummary.GetMonthlySummary(); } catch (Exception e) { Console.WriteLine(e); this.Reset(); } }
public void TestReplaceEmptyCollection() { var covidCollection = new CovidDataCollection(); Assert.IsFalse(covidCollection.ReplaceDuplicateRecords(this.record1)); }