-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileIO.pde
More file actions
357 lines (281 loc) · 11.5 KB
/
FileIO.pde
File metadata and controls
357 lines (281 loc) · 11.5 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import controlP5.*;
//store following member variables
//filePath to store the path of the selected sensor data file
//dataTable of type Table to load the data in the csv input file
ControlP5 cp5;
Button bar, plot, max, min;
Button jan, feb, mar, apr, may, jun, jul ,aug ,sep , oct, nov, dec;
Button[] buttons= {jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}; //used to assign buttons
String months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; //used to name buttons
Table table;
Date[] date;
TemperatureData[] tempData;
public String name, name2; //for making month buttons
public int perYear, month;
public float maxTemp, minTemp, snowFall;
public int xMin = 210;
public int xMax = 1590;
public float yMin = 450;
public int yMax = 800;
public int initialWidth = 4;
public int initialLength = 10;
public int multFact = 15; //to scale raw data onto graphs
void setup(){
background(0xffFFFFFF);
size(1700,800);
/* Adding buttons */
textSize(9); //for formatting
PFont font = createFont("Georgia Bold", 5);
cp5 = new ControlP5(this);
bar = cp5.addButton("Bar")
.setValue(0)
.setPosition(10,10)
.setSize(120,50)
.setSwitch(true)
.addCallback(new CallbackListener(){
public void controlEvent(CallbackEvent event){
if(event.getAction() == ControlP5.ACTION_PRESS){
if(bar.isOn()){
bar.setOff();
background(0xffFFFFFF);
axis(); //reset field
}
else if (plot.isOn()){
plot.setOff(); //since plot and bar cannot be on at same time
bar.setOn();
drawBars();
}
else if(!bar.isOn()){
bar.setOn();
drawBars();
}
else{
for(Button b: buttons){
if (b.isOn()){
bar.setOn();
drawBarMonth();
}
else if (bar.isOn() && b.isOn()){
bar.setOff();
}
}
}
}
}
});
plot = cp5.addButton("Plot")
.setValue(0)
.setPosition(10,70)
.setSize(120,50)
.setSwitch(true)
.addCallback(new CallbackListener(){
public void controlEvent(CallbackEvent event){
if(event.getAction() == ControlP5.ACTION_PRESS){
if(plot.isOn()){
plot.setOff();
background(0xffFFFFFF);
axis(); //reset field
}
else if (bar.isOn()){
bar.setOff(); //since plot and bar cannot be on at same time
plot.setOn();
drawPlot();
}
else if(!plot.isOn()){
plot.setOn();
drawPlot();
}
else{
for(Button b: buttons){
if (b.isOn()){
plot.setOn();
drawPlotMonth();
}
else if (plot.isOn() && b.isOn()){
plot.setOff();
}
}
}
}
}
});
///////////////////////////////////////////
max = cp5.addButton("Max")
.setValue(0)
.setPosition(10,220)
.setSize(50,50)
.setColorBackground(0xff5C5D5D)
.setColorForeground(0xff889393)
.setColorActive(0xff889393)
.setSwitch(true)
.addCallback(new CallbackListener(){
public void controlEvent(CallbackEvent event){
if(event.getAction() == ControlP5.ACTION_PRESS){
//turn off min if it is already on when max is clicked
if((min.isOn())){
min.setOff();
max.setOn();
//if max was turned on while bar is turned on, draw max bar
if(max.isOn() && bar.isOn()){
drawBars();
}
//if max was turned on while plot is turned on, draw max plot
else if(max.isOn() && plot.isOn()){
drawPlot();
}
}
else if (!max.isOn()){
max.setOn();
//if max was turned on while bar is turned on, draw max bar
if(max.isOn() && bar.isOn()){
drawBars();
}
//if max was turned on while plot is turned on, draw max plot
else if(max.isOn() && plot.isOn()){
drawPlot();
}
}
//if max is turned off, redraw bars
else if(max.isOn() && bar.isOn()){
max.setOff();
drawBars();
}
else if(max.isOn() && plot.isOn()){
max.setOff();
drawPlot();
}
}
}
});
min = cp5.addButton("Min")
.setValue(0)
.setPosition(10,280)
.setSize(50,50)
.setColorBackground(0xff5C5D5D)
.setColorForeground(0xff889393)
.setColorActive(0xff889393)
.setSwitch(true)
.addCallback(new CallbackListener(){
public void controlEvent(CallbackEvent event){
if(event.getAction() == ControlP5.ACTION_PRESS){
//turn off max if it is already on when min is clicked
if(max.isOn()){
max.setOff();
min.setOn();
//if min was turned on while bar is turned on, draw min bar
if(min.isOn() && bar.isOn()){
drawBars();
}
//if min was turned on while plot is on, draw min bar
else if(min.isOn() && plot.isOn()){
drawPlot();
}
}
else if(!min.isOn()){
min.setOn();
//if min was turned on while bar is turned on, draw min bar
if(min.isOn() && bar.isOn()){
drawBars();
}
//if min was turned on while plot is on, draw min bar
else if(min.isOn() && plot.isOn()){
drawPlot();
}
}
//if min is turned on, and bar is still on draw bars again
else if(min.isOn() && bar.isOn()){
min.setOff();
drawBars();
}
//if min is turned on and plot is still on draw plot again
else if(min.isOn() && plot.isOn()){
min.setOff();
drawPlot();
}
}
}
});;
////////////////////////////
//Month buttons
for(int a = 0, b = 400, c = 20; a < months.length-1; a++, b+=30){
String name = months[a];
String name2 = months[a+1];
if(a%2 == 0){ //retrieve from index 0,2,4,6..
buttons[a] = cp5.addButton(name)
.setValue(0)
.setPosition(c, b)
.setSize(30,30)
.setColorBackground(0xffFABD8B)
.setColorForeground(0xffFADAC0)
.setColorActive(0xffFADAC0)
.setSwitch(true);
}
if((a+1)%2 != 0 ){ //retrieve from index 1,3,5,7...
buttons[a+1] = cp5.addButton(name2)
.setValue(0)
.setPosition(c*4, b)
.setSize(30,30)
.setColorBackground(0xffFABD8B)
.setColorForeground(0xffFADAC0)
.setColorActive(0xffFADAC0)
.setSwitch(true);
}
}
for(Button b: buttons){
final Button c = b;
b.addCallback(new CallbackListener(){
public void controlEvent(CallbackEvent event){
if (event.getAction() == ControlP5.ACTION_PRESS){
println("You're in!");
//turn off all other month buttons
if(!c.isOn())
desMonth(c);
//bar
if(bar.isOn() && !c.isOn()){
c.setOn();
drawBarMonth();
}
else if(bar.isOn() && c.isOn()){
c.setOff();
drawBars();
}
//plot
if(plot.isOn() && !c.isOn()){
c.setOn();
drawPlotMonth();
}
else if(plot.isOn() && c.isOn()){
c.setOff();
drawPlot();
}
}
}
});
}
/* */
/*CSV loader*/
table = loadTable("CalgaryWeather.csv", "header");
date = new Date[table.getRowCount()];
tempData = new TemperatureData[table.getRowCount()];
int counter = 0;
for(TableRow row: table.rows()){
date[counter] = new Date(row.getInt("Month"),row.getInt("Year"));
tempData[counter] = new TemperatureData(date[counter], row.getFloat("Min Temperature"), row.getFloat("Max Temperature"), row.getFloat("Snow Fall"));
// print(tempData[counter].maxTemp);
// print(tempData[counter].minTemp, tempData[counter].maxTemp, tempData[counter].snowFall);
counter++;
}
/* */
//axis labels
axis();
}
void draw(){
//axis(); //label is pixelated for some reason
}
void desMonth(Button a){ //turning off all other Month buttons other than the one selected.
for(Button b: buttons){
if(b != a){
b.setOff();
}
}
}