-
Notifications
You must be signed in to change notification settings - Fork 2
/
classes.js
100 lines (88 loc) · 3.71 KB
/
classes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* js class reference: https://www.w3schools.com/js/js_classes.asp */
class CoronaSimSettings {
constructor() {
this.initialDate = null;
this.simulatonDaysInt = 0;
this.initialInfectionsInt = 0;
this.infectionDailyIncreasePercentFloat = 0;
this.testPercentFloat = 0;
this.positiveTestResultPercentFloat = 0;
this.positiveCaseDeathPercentFloat = 0;
this.positiveCaseHospitalizedPercentFloat = 0;
this.daysHospitalizedInt = 0;
this.hospitalBedsInt = 0;
this.populationInt = 0;
}
}
class DayStats {
/*
fields:
dayStats.dayNumberInt
dayStats.finalHospitalDayNumberInt
dayStats.infectionsInt
dayStats.testedInt
dayStats.positiveTestsInt
dayStats.hospitalizationsInt
dayStats.deathsInt
*/
constructor(dayNumberInt, totalInfectionCountSoFarInt, coronaSimSettings) {
debug("Creating daystats.", { dayNumberInt:dayNumberInt, totalInfectionCountSoFarInt:totalInfectionCountSoFarInt,
coronaSimSettings:coronaSimSettings });
this._dayNumberInt = dayNumberInt;
this._finalHospitalDayNumberInt = this._dayNumberInt + coronaSimSettings.daysHospitalizedInt;
if (dayNumberInt == 0) {
this._infectionsInt = totalInfectionCountSoFarInt;
} else {
this._infectionsInt = multiplyAndRound(totalInfectionCountSoFarInt, coronaSimSettings.infectionDailyIncreasePercentFloat);
}
this._testedInt = multiplyAndRound(this._infectionsInt, coronaSimSettings.testPercentFloat);
this._positiveTestsInt = multiplyAndRound(this._testedInt, coronaSimSettings.positiveTestResultPercentFloat);
this._hospitalizationsInt = multiplyAndRound(this._positiveTestsInt, coronaSimSettings.positiveCaseHospitalizedPercentFloat);
this._deathsInt = multiplyAndRound(this._positiveTestsInt, coronaSimSettings.positiveCaseDeathPercentFloat);
debug("DayStats created.", { this:this, dayNumberInt:dayNumberInt, totalInfectionCountSoFarInt:totalInfectionCountSoFarInt,
coronaSimSettings:coronaSimSettings });
}
get dayNumberInt() { return this._dayNumberInt; }
get finalHospitalDayNumberInt() { return this._finalHospitalDayNumberInt; }
get infectionsInt() { return this._infectionsInt; }
get testedInt() { return this._testedInt; }
get positiveTestsInt() { return this._positiveTestsInt; }
get hospitalizationsInt() { return this._hospitalizationsInt; }
get deathsInt() { return this._deathsInt; }
}
class TotalStats {
constructor() {
this._totalDays = 0;
this._totalInfectionsInt = 0;
this._totalTestedInt = 0;
this._totalPositiveTestsInt = 0;
this._totalHospitalizationsInt = 0;
this._totalDeathsInt = 0;
}
addDayStats(dayStats) {
debug("Total stats adding daystats.", { this:this.copy(), dayStats:dayStats });
this._totalDays += 1;
this._totalInfectionsInt += dayStats.infectionsInt;
this._totalTestedInt += dayStats.testedInt;
this._totalPositiveTestsInt += dayStats.positiveTestsInt;
this._totalHospitalizationsInt += dayStats.hospitalizationsInt;
this._totalDeathsInt += dayStats.deathsInt;
debug("Total stats state after adding.", { this:this.copy(), dayStats:dayStats });
}
copy() {
var that = new TotalStats();
that._totalDays = this._totalDays;
that._totalInfectionsInt = this._totalInfectionsInt;
that._totalTestedInt = this._totalTestedInt;
that._totalPositiveTestsInt = this._totalPositiveTestsInt;
that._totalHospitalizationsInt = this._totalHospitalizationsInt;
that._totalDeathsInt = this._totalDeathsInt;
return that;
}
get totalDays() { return this._totalDays; }
get totalInfectionsInt() { return this._totalInfectionsInt; }
get totalTestedInt() { return this._totalTestedInt; }
get totalPositiveTestsInt() { return this._totalPositiveTestsInt; }
get totalHospitalizationsInt() { return this._totalHospitalizationsInt; }
get totalDeathsInt() { return this._totalDeathsInt; }
}