-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatistics.java
More file actions
110 lines (100 loc) · 3.98 KB
/
Statistics.java
File metadata and controls
110 lines (100 loc) · 3.98 KB
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
101
102
103
104
105
106
107
108
109
110
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* Write a description of class Statistics here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Statistics
{
// Singleton pattern
private static Statistics instance;
// instance variables - replace the example below with your own
CovidDataLoader loader = new CovidDataLoader();
ArrayList<CovidData> records = loader.load();
// private static ControllerMain instance; // Delete soon if unnecessary
// Declare other controllers
ModelMain modelMain;
private LocalDate startDate;
private LocalDate endDate;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/**
* Constructor
*/
public Statistics() {}
// Singleton getInstance() method
public static Statistics getInstance() {
if (instance == null) {
instance = new Statistics();
}
return instance;
}
public int totalDeath() {
this.modelMain = modelMain.getInstance();
startDate = modelMain.getStartDate();
endDate = modelMain.getEndDate();
int totalDeath = 0;
for (CovidData record : records) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if((date.isAfter(startDate) && date.isBefore(endDate)) || (date.isEqual(startDate) || date.isEqual(endDate))){
totalDeath = totalDeath + record.getNewDeaths();
}
}
System.out.println(""+totalDeath);
return totalDeath;
}
public int averageCases(){
ArrayList<CovidData> records = this.records;
this.modelMain = modelMain.getInstance();
startDate = modelMain.getStartDate();
endDate = modelMain.getEndDate();
int totalCases = 0;
int numberOfDates = 0;
for (CovidData record : records) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if((date.isAfter(startDate) && date.isBefore(endDate)) || (date.isEqual(startDate) || date.isEqual(endDate))){
totalCases = totalCases + record.getNewCases();
numberOfDates++;
}
}
int averageCases = totalCases/numberOfDates;
System.out.println(""+averageCases);
return averageCases;
}
public int averageTransit(){
this.modelMain = modelMain.getInstance();
startDate = modelMain.getStartDate();
endDate = modelMain.getEndDate();
int totalTransit = 0;
int numberOfDates = 0;
for (CovidData record : records) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if((date.isAfter(startDate) && date.isBefore(endDate)) || (date.isEqual(startDate) || date.isEqual(endDate))){
totalTransit = totalTransit + record.getTransitGMR();
numberOfDates++;
}
}
int averageTransit = totalTransit/numberOfDates;
System.out.println(""+averageTransit);
return averageTransit;
}
public int averageWorkPlace(ArrayList<CovidData> records){
this.modelMain = modelMain.getInstance();
startDate = modelMain.getStartDate();
endDate = modelMain.getEndDate();
int totalWorkPlace = 0;
int numberOfDates = 0;
for (CovidData record : records) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if((date.isAfter(startDate) && date.isBefore(endDate)) || (date.isEqual(startDate) || date.isEqual(endDate))){
totalWorkPlace = totalWorkPlace + record.getWorkplacesGMR();
numberOfDates++;
}
}
int averageWorkPlace= totalWorkPlace/numberOfDates;
System.out.println(""+averageWorkPlace);
return averageWorkPlace;
}
}