/// <summary> /// Calculates the series with the SEIR object for a number days /// </summary> /// <param name="iDays">Days for which the series should be calculated.</param> /// <returns>Awaitable task</returns> public async Task CalcAsync(int iDays) { int iPopulation = _seir.Susceptible + _seir.Exposed + _seir.Infectious + _seir.Removed; Queue <int> q7Days = new Queue <int>(7); for (int i = 1; i < iDays; i++) { int iDay = _seir.Day; int iCases = _seir.Exposed + _seir.Infectious + _seir.Removed; _seir.Calc(i); if (_serSusceptible != null) { _serSusceptible.Points.AddXY(_seir.Day, _seir.Susceptible); } if (_serExposed != null) { _serExposed.Points.AddXY(_seir.Day, _seir.Exposed); } if (_serInfectious != null) { _serInfectious.Points.AddXY(_seir.Day, _seir.Infectious); } if (_serRemoved != null) { _serRemoved.Points.AddXY(_seir.Day, _seir.Removed); } if (_serCases != null) { _serCases.Points.AddXY(_seir.Day, _seir.Exposed + _seir.Infectious + _seir.Removed); } if (_serDaily != null) { _serDaily.Points.AddXY(_seir.Day, Math.Max(_seir.Exposed + _seir.Infectious + _seir.Removed - iCases, 0)); } if (_ser7Days != null) { q7Days.Enqueue(Math.Max(_seir.Exposed + _seir.Infectious + _seir.Removed - iCases, 0)); while (q7Days.Count > 7) { q7Days.Dequeue(); } _ser7Days.Points.AddXY(_seir.Day, q7Days.Sum() / (iPopulation / 100000d)); } if (_serReproduction != null) { _serReproduction.Points.AddXY(_seir.Day, _seir.Reproduction); } } await Task.CompletedTask; }
/// <summary> /// Calculates the series with the SEIR object for a time range with R₀-values of a dictionary. /// </summary> /// <param name="dtStart">Start date of the time range</param> /// <param name="dtEnd">End date of teh time range</param> /// <param name="p">Optional progress object</param> /// <returns>Awaitable task.</returns> public virtual async Task CalcAsync(DateTime dtStart, DateTime dtEnd, IProgress <int> p = null) { double dReproduction = _seir.Reproduction; int iPCount = 0; int iTotalDays = (dtEnd - dtStart).Days; int iPopulation = _seir.Susceptible + _seir.Exposed + _seir.Infectious + _seir.Removed; Queue <int> q7Days = new Queue <int>(7); int iCasesToday = 0; int iDailyToday = 0; int i7DaysToday = 0; for (DateTime dt = dtStart.AddDays(1d); dt <= dtEnd; dt = dt.AddDays(1d)) { int iCases = _seir.Exposed + _seir.Infectious + _seir.Removed; int iDays = (dt - dtStart).Days; _seir.Reproduction = _dicReproduction.TryGetValue(dt, out double d) ? d : dReproduction; _seir.Calc(iDays); if (_serSusceptible != null) { _serSusceptible.Points.AddXY(dt, _seir.Susceptible); } if (_serExposed != null) { _serExposed.Points.AddXY(dt, _seir.Exposed); } if (_serInfectious != null) { _serInfectious.Points.AddXY(dt, _seir.Infectious); } if (_serRemoved != null) { _serRemoved.Points.AddXY(dt, _seir.Removed); } if (_serCases != null) { int i = _serCases.Points.AddXY(dt, _seir.Exposed + _seir.Infectious + _seir.Removed); if (_bDoubledMarker && iCasesToday != 0 && iCasesToday * 2 < _seir.Exposed + _seir.Infectious + _seir.Removed) { iCasesToday = 0; _serCases.Points[i].MarkerStyle = MarkerStyle.Diamond; _serCases.Points[i].MarkerSize = _serCases.BorderWidth * 2; _serCases.Points[i].MarkerBorderColor = Color.DarkGray; } } if (_serDaily != null) { int i = _serDaily.Points.AddXY(dt, Math.Max(_seir.Exposed + _seir.Infectious + _seir.Removed - iCases, 0)); // Remarks: Rounding errors might lead to -1 as value. Thus, Math.Max([Cases], 0) is used if (_bDoubledMarker && iDailyToday != 0 && iDailyToday * 2 < Math.Max(_seir.Exposed + _seir.Infectious + _seir.Removed - iCases, 0)) { iDailyToday = 0; _serDaily.Points[i].MarkerStyle = MarkerStyle.Diamond; _serDaily.Points[i].MarkerSize = _serDaily.BorderWidth * 2; _serDaily.Points[i].MarkerBorderColor = Color.DarkGray; } } if (_ser7Days != null) { q7Days.Enqueue(Math.Max(_seir.Exposed + _seir.Infectious + _seir.Removed - iCases, 0)); while (q7Days.Count > 7) { q7Days.Dequeue(); } int i = _ser7Days.Points.AddXY(dt, Math.Round(q7Days.Sum() / (iPopulation / 100000d), 2)); if (_bDoubledMarker && i7DaysToday != 0 && i7DaysToday * 2 < q7Days.Sum()) { i7DaysToday = 0; _ser7Days.Points[i].MarkerStyle = MarkerStyle.Diamond; _ser7Days.Points[i].MarkerSize = _ser7Days.BorderWidth * 2; _ser7Days.Points[i].MarkerBorderColor = Color.DarkGray; } } if (_serReproduction != null) { _serReproduction.Points.AddXY(dt, _seir.Reproduction); } if (_bDoubledMarker && dt == DateTime.Today) { iCasesToday = _seir.Exposed + _seir.Infectious + _seir.Removed; iDailyToday = Math.Max(_seir.Exposed + _seir.Infectious + _seir.Removed - iCases, 0); i7DaysToday = q7Days.Sum(); } if (iPCount != 25 * iDays / iTotalDays) { iPCount = 25 * iDays / iTotalDays; p?.Report(4 * iPCount); } } await Task.CompletedTask; }