-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPolData.pde
156 lines (133 loc) · 7.89 KB
/
GetPolData.pde
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
IMPORTANT: Some borough information was not collected from the API as it was not present.
Barnet, Hounslow, Waltham Forest, Bromley, Newham and Westminster are all included in this exemption.
The aim here was to process all JSON data from the London Air Quality API, unfortunately the more I delved into the data the more complex the data structures were and thus
did not complete the full data visualisation for pollution levels around London.
Each Borough has 1 or many sites and each site mesasures 1 or many species.
I used a number of nested try catch methods in order to capture all present information storing it into a 2d array where necessary.
myArray[site][pollutant/species]
I struggled with PolDisplay as this required further linear thinking and processing and I found a slight issues when the borough had only 1 site. a null pointer exsists.
Also in the data exsists multiple sites at 1 latitude and longitiude location makeing this even more complex as i would then need to display 1 or two bits of informtion to screen
depending on this.
I was unable to complete the pollution part of the program but was able to have all information stored how I wanted it to.
Note: Object means singular in site or species
Array means many sites or species
*/
class GetPolData {
JSONObject dailyMonitorPerBorough, annualTargetPerBorough;
int sitesNum = 0;
int speciesNum, objectiveNum, airQualityIndex;
boolean dailyHasData, annualHasData, dailyHasManySites;
String day, month, year, dateCollected, speciesDesc, speciesCode;
int[][] airQualityIndexArr, speciesAnnualValueArr, valueAnnualArr;
boolean[][] dailyHasManySpecies;
String[][] speciesDescArr, speciesCodeDailyArr, speciesCodeAnnualArr, objectiveDesc, targetAchived;
SimplePointMarker[] siteMarkers;
SimplePointMarker siteMarker;
GetPolData() {
}
void runDaily() {
//These need to be drawn as the size of the array will vary per borough
//Using an arraylist may have ended up having unnecessary data filled within arrays.
airQualityIndexArr = new int[sitesNum][speciesNum];
speciesAnnualValueArr = new int[sitesNum][speciesNum];
valueAnnualArr = new int[sitesNum][speciesNum];
dailyHasManySpecies = new boolean[sitesNum][speciesNum];
speciesDescArr = new String[sitesNum][speciesNum];
speciesCodeDailyArr = new String[sitesNum][speciesNum];
speciesCodeAnnualArr = new String[sitesNum][speciesNum];
objectiveDesc = new String[sitesNum][speciesNum];
targetAchived = new String[sitesNum][speciesNum];
siteMarkers = new SimplePointMarker[sitesNum];
//Data is put into above Arrays
try { //TEST: all available JSON Files
dailyMonitorPerBorough = loadJSONObject("../Kings_AirQuality_API/data/Daily Monitoring/" + currentBorough + ".json");
JSONObject airQuality = dailyMonitorPerBorough.getJSONObject("DailyAirQualityIndex"); // Go to the next level down in the JSON file
JSONObject locAuth = airQuality.getJSONObject("LocalAuthority");//Go one more level down in the JSON file
dailyHasData = true; // If it has data then set to true
try { //TEST: If there is more than 1 site
dailyHasManySites = true;
JSONArray siteArray = locAuth.getJSONArray("Site"); //Get the array of sites
sitesNum = siteArray.size(); // Store the total number of sites to the array above
//Get date that data was updated from site information only get first in siteArray
JSONObject siteInfo = siteArray.getJSONObject(0); //only 0 is used to pick first site date as they are all the same
String dateCollected = siteInfo.getString("@BulletinDate");
//strip the data and collect only day month and year storing them
day = dateCollected.substring(8, 10);
month = dateCollected.substring(5, 7);
year = dateCollected.substring(0, 4);
//Get all other site information
for (int i = 0; i < sitesNum; i++) {
JSONObject sitesObject = siteArray.getJSONObject(i);// Within the site array gather each object
float latitude = sitesObject.getFloat("@Latitude");
float longitude = sitesObject.getFloat("@Longitude");
Location siteLocation = new Location(latitude, longitude);
siteMarkers[i] = new SimplePointMarker(siteLocation);
map.addMarker(siteMarkers[i]);
siteMarkers[i].setColor(255);
siteMarkers[i].setId(currentBorough + i); //This will be used to match the individual site markers to present information to screen
try { //TEST: If it has more than one species and more than one site
JSONArray speciesArray = sitesObject.getJSONArray("Species"); //If it does then get the array
speciesNum = speciesArray.size(); //Store the total number of species in an array
for (int j = 0; j < speciesNum; j ++) { //Cycle through all species within the array
dailyHasManySpecies[i][j] = true;
JSONObject speciesObject = speciesArray.getJSONObject(j); //Get each of the species for each site
airQualityIndexArr[i][j] = speciesObject.getInt("@AirQualityIndex");
speciesDescArr[i][j] = speciesObject.getString("@SpeciesDescription");
speciesCodeDailyArr[i][j] = speciesObject.getString("@SpeciesCode");
}
}
catch (Throwable t) { //TEST: If only one species but many sites
dailyHasManySpecies[i][0] = false;
JSONObject speciesObject = sitesObject.getJSONObject("Species");
airQualityIndex = speciesObject.getInt("@AirQualityIndex");
speciesDesc = speciesObject.getString("@SpeciesDescription"); //Used to match all possible values and only to display the value once.
speciesCode = speciesObject.getString("@SpeciesCode"); //Used to display which pollutants are being measured at each site
}
}
}
catch (Throwable t) { //TEST: If only has 1 site
dailyHasManySites = false;
JSONObject sitesObject = locAuth.getJSONObject("Site");
float latitude = sitesObject.getFloat("@Latitude");
float longitude = sitesObject.getFloat("@Longitude");
Location siteLocation = new Location(latitude, longitude);
siteMarker = new SimplePointMarker(siteLocation);
map.addMarker(siteMarker);
siteMarker.setColor(255);
siteMarker.setId(currentBorough + 0);
}
}
catch(Throwable t) {
//If there is no JSON
dailyHasData = false;
}
}
void runAnnual() {
// try {//All Annual JSON files
// annualTargetPerBorough = loadJSONObject("../Kings_AirQuality_API/data/Annual Target/" + currentBorough + ".json");
// JSONObject siteObjOverallAnnual = annualTargetPerBorough.getJSONObject("SiteObjectives");
// JSONArray sitesAnnual = siteObjOverallAnnual.getJSONArray("Site");
// annualHasData = true;
// try { // if has more than one site
// for (int i = 0; i < sitesNum; i ++) {
// JSONObject sitesAnnualArr = sitesAnnual.getJSONObject(i);
// JSONArray siteObjective = sitesAnnualArr.getJSONArray("Objective");
// objectiveNum = sitesAnnualArr.size();
// for (int j = 0; j < objectiveNum; j++) { //more than one objective
// objectiveDesc[i][j] = sitesAnnualArr.getString("@ObjectiveName");
// speciesCodeAnnualArr[i][j]= sitesAnnualArr.getString("@SpeciesCode");
// targetAchived[i][j] = sitesAnnualArr.getString("@Achieved");
// valueAnnualArr[i][j] = sitesAnnualArr.getInt("@Value");
// }
// }
// }
// catch(Throwable t) {//if only 1 site
// //Incomplete section
// }
// }
// catch (Throwable t) { //If any JSON file do not exsist
// annualHasData = false;
// }
}
}