-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatisticsBorough.java
More file actions
66 lines (58 loc) · 2.29 KB
/
StatisticsBorough.java
File metadata and controls
66 lines (58 loc) · 2.29 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
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Arrays;
import javax.swing.table.DefaultTableModel;
/**
* Write a description of class StatisticsBorough here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class StatisticsBorough
{
// Singleton pattern
private static StatisticsBorough instance;
CovidDataLoader loader = new CovidDataLoader();
ArrayList<CovidData> records = loader.load();
ModelMain modelMain;
private LocalDate startDate;
private LocalDate endDate;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Object[][] data ;
//String[] columnNames = {"Date", "retail Recreation GMR","park GMR","Transit GMR", "Work Places GMR","Residential GMR","new COVID cases", "total COVID cases "};
/**
* Constructor
*/
public StatisticsBorough() {}
// Singleton getInstance() method
public static StatisticsBorough getInstance() {
if (instance == null) {
instance = new StatisticsBorough();
}
return instance;
}
public Object[][] boroughData(String borough) {
List<Object[]> dataList = new ArrayList<>();
this.modelMain = modelMain.getInstance();
startDate = modelMain.getStartDate();
endDate = modelMain.getEndDate();
for (CovidData record : records) {
if(borough.equals(record.getBorough())) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if((date.isAfter(startDate) && date.isBefore(endDate)) || (date.isEqual(startDate) || date.isEqual(endDate))){
record.getNewDeaths();
Object[] newRow = {""+date, record.getRetailRecreationGMR(),record.getGroceryPharmacyGMR(),record.getParksGMR(),record.getTransitGMR(),record.getWorkplacesGMR(),record.getResidentialGMR(),record.getNewCases(),record.getTotalCases(),record.getNewDeaths()};
dataList.add(newRow);
}
}
data = dataList.toArray(new Object[0][0]);
}
return data;
}
}