-
Notifications
You must be signed in to change notification settings - Fork 0
/
UNArcTest.pde
665 lines (552 loc) · 21.7 KB
/
UNArcTest.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
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
import java.util.Map; // for DataCard Hashmaps
import processing.pdf.*;
boolean pdfRecord = false;
// UN Funding by Agency and Country Arc Diagram Test
////Declare Globals
int rSn; // randomSeed number. put into var so can be saved in file name. defaults to 47
final float PHI = 0.618033989;
boolean recording = false; // used for MovieMaker output
Table agencyCountryTbl, expenditureByCountryTbl, agencyExpenditureTotalTbl;
Table unAbbrevTbl2;
int transactionMax, transactionMin;
int countryExpendMax, countryExpendMin;
//// Declare Font Variables
PFont mainTitleF, axesLabelF, titleF, agHoverLabelF, cntryHoverLabelF;
//Highlight colour (UN Blue)
color unBlueClr = color(65, 143, 222);
color transactionCurveClr = color(0);
color chartBkgClr = 255;
color axisClr = transactionCurveClr;
color barChartClr = transactionCurveClr;
// color countryLabelClr = unBlueClr;
// UN Logo
PShape unLogo;
boolean univHover = false;
//// Declare Positioning Variables
float margin;
float PLOT_X1, PLOT_X2, PLOT_Y1, PLOT_Y2, PLOT_W, PLOT_H;
PVector agencyAxis1, fundingAxis1, countryAxis1, agencyAxis2, fundingAxis2, countryAxis2;
boolean fundingScaleLinLog; // true=linear false=log
float fundingAxisLogBase;
int fundingAxisMin, fundingAxisMax;
ArrayList<Country> countries;
ArrayList<Transaction> transactions;
ArrayList<Agency> agencies;
//// Declare Globals for Data Cards
// AgCard agCard1;
HashMap<String, AgencyCard> agencyCards;
// public void settings() {
// if (pdfRecord) {
// size(6000, 4800, "processing.pdf.PGraphicsPDF", generateSaveImgFileName(".pdf")); // sized for 8x10 @ 600dpi
// }else{
// size(1920, 1030, "processing.opengl.PGraphics2D");
// smooth(8);
// }
// }
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SETUP
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
void setup() {
background(255);
// PDF output
// size(6000, 4800, PDF, generateSaveImgFileName(".pdf")); // only works with the Processing PDE
// Regular output
// size(7020,4965); // 150 dpi for A0 size paper
// size(2048, 1536); // iPad Air 2;
// size(1920, 1030, P2D); // office display size
size(1440, 850, P2D); // curent macbook pro size at half scaling?
// size(1280, 800); // curent macbook pro size at half scaling?
// size(1600, 900);
// size(1300, 850);
// size(720, 650);
frameRate(30);
smooth(8);
setPositioningVariables();
rSn = 47; // 4,7,11,18,29...;
randomSeed(rSn);
// Load UN Logo
unLogo = loadShape("UNBlueLogo.svg");
unLogo.scale(.29);
// load data
// agencyCountryTbl = loadTable("Agency_Expenditure_by_Country_2015.csv", "header");
agencyCountryTbl = loadTable("CountryLevelExpenditureByAgency-2015.csv", "header");
// expenditureByCountryTbl = loadTable("Total_Expenditure_by_Country.csv", "header");
expenditureByCountryTbl = loadTable("TotalExpenditureByCountry-2015.csv", "header");
// agencyExpenditureTotalTbl = loadTable("Agency_Expenditure_Total_2015.csv", "header");
agencyExpenditureTotalTbl = loadTable("TotalExpenditureByAgency-2015.csv", "header");
unAbbrevTbl2 = loadTable("UN-Agencies-Metadata.csv", "header");
// Prep data
// min / max for transactions (used on funding axis)
transactionMin = Integer.MAX_VALUE;
transactionMax = 0;
for (int i=0; i < agencyCountryTbl.getRowCount(); i++) {
TableRow agencyCountryRow = agencyCountryTbl.getRow(i);
int currAmtVal= agencyCountryRow.getInt("Amount");
if ( currAmtVal > transactionMax) transactionMax = currAmtVal;
if ( currAmtVal < transactionMin) transactionMin = currAmtVal; // this could be a negative value!
}
println("agencyCountryTbl.getRowCount() = "+ agencyCountryTbl.getRowCount());
println("transactionMax = "+ transactionMax);
// max/min spend by country
countryExpendMax = 0;
countryExpendMin = Integer.MAX_VALUE;
for (int i = 0; i < expenditureByCountryTbl.getRowCount(); i++) {
TableRow countryRow = expenditureByCountryTbl.getRow(i);
int currAmtVal= countryRow.getInt("Amount");
if ( currAmtVal > countryExpendMax) countryExpendMax = currAmtVal;
if ( currAmtVal < countryExpendMin) countryExpendMin = currAmtVal; // this could be a negative value!
}
// Prep ArrayList
countries = new ArrayList<Country>();
transactions = new ArrayList<Transaction>();
agencies = new ArrayList<Agency>();
// Prep Data Card Hashmaps
agencyCards = new HashMap<String, AgencyCard>();
// Populate ArrayLists
// Transactions ArrayLists
for (int i=0; i < agencyCountryTbl.getRowCount(); i++) {
TableRow agencyCountryRow = agencyCountryTbl.getRow(i);
float currAmount = agencyCountryRow.getFloat("Amount");
if (currAmount > 0) {
String currAgency = agencyCountryRow.getString("Agency");
int currYear = agencyCountryRow.getInt("Year");
String currCountryName = agencyCountryRow.getString("Country");
// println(currYear, currCountryName, currAmount, currAgency);
Transaction newTransaction = new Transaction(currYear, currCountryName, currAmount, currAgency);
if (currCountryName.indexOf("Congo") != -1) {
// println("New Transaction object params: "+currYear+", "+currCountryName+", "+currAmount+", "+currAgency);
}
transactions.add(newTransaction);
}
}
// Countries ArrayList
for (int i=0; i < expenditureByCountryTbl.getRowCount(); i++) {
TableRow countryRow = expenditureByCountryTbl.getRow(i);
int currYear= countryRow.getInt("Year");
String currCountryName= countryRow.getString("Country");
float currAmount= countryRow.getFloat("Amount");
Country newCountry = new Country(currYear, currCountryName, currAmount);
countries.add(newCountry);
}
// Agencies ArrayList
for (int i=0; i < agencyExpenditureTotalTbl.getRowCount(); i++) {
TableRow agencyRow = agencyExpenditureTotalTbl.getRow(i);
if (i<1) {
// println("column headers for agencyExpenditureTotalTbl");
// println(agencyRow.getColumnTitle(0));
// println(agencyRow.getColumnTitle(1));
// println(agencyRow.getColumnTitle(2));
}
int currYear = 2015; // hardcoding year val....
String currAgencyName = agencyRow.getString("Agency description");
// println("currAgencyUNAbbrev : " + currAgencyUNAbbrev);
// result var is too vague it. its really a table row for the first (only) entry for
// a row matching the 'Official name' column entry.
// so, better var name is... trAgencyData
TableRow trAgencyData = unAbbrevTbl2.findRow(currAgencyName, "Official name");
// if(trAgencyData == null) println("currAgencyName gives a null, " + currAgencyName);
String currAgencyUNAbbrev = "";
// if(trAgencyData != null) println(trAgencyData.toString());
if (trAgencyData != null) {
currAgencyUNAbbrev = trAgencyData.getString("Abbreviation");
// println("Matching row to Official name: " + currAgencyName + ", " + trAgencyData.getString("Abbreviation"));
} else {
println("Matching row to Official name: " + currAgencyName + ", " + trAgencyData);
}
float currAmount= agencyRow.getFloat("Expenditure");
if (trAgencyData != null) {
// println("data for new agency object: "+ currAgencyUNAbbrev, currAgencyName);
Agency newAgency = new Agency(currYear, currAgencyUNAbbrev, currAgencyName, currAmount);
agencies.add(newAgency);
}
// println("new Agency params: "+ currYear +", "+ currAgencyUNAbbrev +", "+ currAgencyName +", "+ currAmount);
}
// // Agencies ArrayList
// for (int i=0; i < agencyExpenditureTotalTbl.getRowCount(); i++) {
// TableRow agencyRow = agencyExpenditureTotalTbl.getRow(i);
// int currYear = 2015; // hardcoding year val....
// String currAgencyUNAbbrev= agencyRow.getString("Agency");
// // String currExpenditure = agencyRow.getString("Expenditure");
// // println("currAgencyUNAbbrev : " + currAgencyUNAbbrev);
// TableRow result = unAbbrevTbl2.findRow(currAgencyUNAbbrev, "Abbreviation");
// // println("TableRow result: " + result);
// String currAgencyName = "";
// if (result != null) {
// currAgencyName = result.getString("Official name");
// }
// float currAmount= agencyRow.getFloat("Expenditure");
// Agency newAgency = new Agency(currYear, currAgencyUNAbbrev, currAgencyName, currAmount);
// println("new Agency params: "+ currYear +", "+ currAgencyUNAbbrev +", "+ currAgencyName +", "+ currAmount);
// agencies.add(newAgency);
// }
// Set references between Country, Agency and Transaction objects
println("setting transaction references");
for (Transaction currTrans : transactions) {
currTrans.setTransactionCountry();
currTrans.setTransactionAgency();
}
println("setting agency references");
for (Agency currAgency : agencies) {
currAgency.setAgencyTransactionList();
}
println("setting country references");
for (Country currCnty : countries) {
currCnty.setCountryTransactionList();
}
// Initialize Axes
agencyAxis1 = new PVector();
agencyAxis2 = new PVector();
fundingAxis1 = new PVector();
fundingAxis2 = new PVector();
fundingScaleLinLog = false; // true=linear false=log
fundingAxisLogBase = 10;
countryAxis1 = new PVector();
countryAxis2 = new PVector();
// updateAxes();
fundingAxisMin =0;
fundingAxisMax = 1000000000;
// Creating AgencyCards and HashMap to name
for (Agency currAg : agencies) {
AgencyCard newAgCard = new AgencyCard(currAg);
agencyCards.put(currAg.agencyName, newAgCard);
}
// Font Stuff
// titleF = loadFont("HelveticaNeue-Thin-72.vlw");
mainTitleF = createFont("HelveticaNeue-Thin", 48, true); //requires a font file in the data folder?
axesLabelF = createFont("Helvetica", 11); //requires a font file in the data folder?
agHoverLabelF = createFont("Helvetica", 18); //requires a font file in the data folder?
cntryHoverLabelF = createFont("HelveticaNeue-Thin", 36, true); //requires a font file in the data folder?
// Run tests
// test_CountryObj("Lebanon");
// test_AgencyObj("UNICEF");
// test_AgencyNullObj();
println("setup done: " + nf(millis() / 1000.0, 1, 2));
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DRAW
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
void draw() {
if (pdfRecord) {
beginRecord(PDF, generateSaveImgFileName(".pdf"));
}
background(chartBkgClr);
// unLogo.enableStyle();
color logoClr = color(unBlueClr, 123);
unLogo.setFill(logoClr);
shape(unLogo, PLOT_X1, PLOT_Y1+200);
updateAxes();
// renderBarChart();
// Reset hover and highlight values to off
univHover = false;
for (Agency ag : agencies) {
ag.resetHoverHighlight();
}
for (Country cty : countries) {
cty.resetHoverHighlight();
}
for (Transaction t : transactions) {
t.resetHoverHighlight();
}
// check to see if the mouse is hovering over Agencies
if ((mouseX > (agencyAxis1.x - 50)) && (mouseX < (agencyAxis2.x + 50)) && (mouseY > (agencyAxis1.y-175))) {
Agency nearestAg = nearestAgency(agencies);
nearestAg.setHover();
}
if ( (countryAxis1.x-200 < mouseX) && (mouseX < PLOT_X2) && (mouseY > countryAxis1.y-textAscent()*3) && mouseY < countryAxis2.y + textAscent()*3 ) {
Country nearestCty = nearestCountry(countries);
nearestCty.setHover();
}
for (Transaction t : transactions) {
t.checkHover();
}
// Render the objects
for (Agency ag : agencies) {
ag.updateStyle();
ag.update();
ag.render();
}
for (Country cty : countries) {
cty.updateStyle();
cty.update();
cty.render();
}
for (Transaction t : transactions) {
t.updateStyle();
t.update();
t.render();
}
for (AgencyCard currAc : agencyCards.values()) {
currAc.render();
}
// Render chart title
textFont(mainTitleF);
// textFont(titleF, 144);
fill(unBlueClr);
textAlign(LEFT);
text("$23 Billion USD\nUN Agency Expenditures \nin 2015", PLOT_X1, PLOT_Y1+textAscent()*PHI);
renderAxes();
renderFundingAxisScaleMarkers();
// renderBarChart();
if (recording) saveFrame("MM_output/" + getSketchName() + "-#####.png");
if (pdfRecord) {
endRecord();
pdfRecord = false;
}
}
// DRAW Loop Ends ///////////////////////////////////////////////////////////////////////////////////
Agency nearestAgency(ArrayList<Agency> _agencies) {
// check if mouse location is within 'hover' range of the agency axis
Agency closestAgency = new Agency(); // create a new placeholder agency object.
float currMinDist = Float.MAX_VALUE; // set initally to max possible value for floats
for (Agency currAg : _agencies) {
float currAgDist = dist(mouseX, mouseY, currAg.currLoc.x, currAg.currLoc.y);
if (currAgDist < currMinDist) {
currMinDist = currAgDist;
closestAgency = currAg;
}
}
return closestAgency;
}
Country nearestCountry(ArrayList<Country> _countries) {
// check if mouse location is within 'hover' range of the agency axis
Country closestCty = new Country(); // create a new placeholder agency object.
float currMinDist = Float.MAX_VALUE; // set initally to max possible value for floats
for (Country currCty : _countries) {
float currCtyDist = dist(mouseX, mouseY, currCty.currLoc.x, currCty.currLoc.y);
if (currCtyDist < currMinDist) {
currMinDist = currCtyDist;
closestCty = currCty;
}
}
return closestCty;
}
void updateAxes() {
fundingAxis1.x = PLOT_X1 + (PLOT_W*(1-PHI));
fundingAxis1.y = PLOT_Y1;
fundingAxis2.x = fundingAxis1.x;
fundingAxis2.y = PLOT_Y1 + (PLOT_H*(PHI));
agencyAxis1.x = PLOT_X1;
agencyAxis1.y = PLOT_Y2;
agencyAxis2.x = PLOT_X1 + (PLOT_W*(1-PHI))-50;
agencyAxis2.y = PLOT_Y2;
countryAxis1.x = PLOT_X2- PLOT_W * (pow(PHI, 3));
countryAxis1.y = PLOT_Y1;
countryAxis2.x = countryAxis1.x;
countryAxis2.y = PLOT_Y2;
}
void renderAxes() {
// render the axes
stroke(axisClr);
strokeWeight(1);
line(agencyAxis1.x, agencyAxis1.y, agencyAxis2.x, agencyAxis2.y);
line(countryAxis1.x, countryAxis1.y, countryAxis2.x, countryAxis2.y);
line(fundingAxis1.x, fundingAxis1.y, fundingAxis2.x, fundingAxis2.y);
// label axes
fill(unBlueClr);
noStroke();
textFont(axesLabelF);
// text("Countries", countryAxis1.x, countryAxis1.y + textAscent() + 5);
// text("UN Agencies", agencyAxis1.x, agencyAxis1.y + textAscent() + 5);
pushMatrix();
translate(fundingAxis1.x+(textAscent()*2), fundingAxis1.y + ((fundingAxis2.y - fundingAxis1.y) * PHI));
rotate(-HALF_PI);
text("Funding", 0, 0);
popMatrix();
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
KEYBOARD UI
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
void keyPressed() {
if (key == 'S') screenCap(".jpg");
if (key == 'P') pdfRecord = true;
if (key == 'L') fundingScaleLinLog = true;
if (key == 'l') fundingScaleLinLog = false;
if (key == 'e') {
exit();
}
}
String generateSaveImgFileName(String fileType) {
String fileName;
// save functionality in here
String outputDir = "output/";
String sketchName = getSketchName() + "-";
String randomSeedNum = "rSn" + rSn + "-";
String dateTimeStamp = "" + year() + nf(month(), 2) + nf(day(), 2) + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2);
//// With using a rSn (random seed number)
fileName = outputDir + sketchName + randomSeedNum + dateTimeStamp + fileType;
//// Without rSn
// fileName = outputDir + sketchName + dateTimeStamp + fileType;
return fileName;
}
void screenCap(String fileType) {
String saveName = generateSaveImgFileName(fileType);
save(saveName);
println("Screen shot saved to: " + saveName);
}
String getSketchName() {
String[] path = split(sketchPath(), "/");
return path[path.length-1];
}
// Exponential scale
float powMap(int incr, double base, int start1, int stop1, float start2, float stop2) {
float normX = map(incr, start1, stop1, 0, 1);
float newX = pow(normX, (float)base);
return map(newX, 0, 1, start2, stop2);
}
void setPositioningVariables() {
margin = width * pow(PHI, 6);
println("margin: " + margin);
PLOT_X1 = margin;
PLOT_X2 = width-margin;
PLOT_Y1 = margin;
PLOT_Y2 = height-margin;
PLOT_W = PLOT_X2 - PLOT_X1;
PLOT_H = PLOT_Y2 - PLOT_Y1;
}
void renderFundingAxisScaleMarkers() {
float maxTickVal = getHigherOrderOfMag(transactionMax);
// 0, 10, 100, 1,000, 10,000, 100,000, 1,000,000, 10,000,000, 100,000,000, 1,000,000,000
float fundingScaleTickVal = maxTickVal;
float tickX, tickY;
tickX = fundingAxis1.x;
tickY = 0;
float numTicks = floor(log(maxTickVal)/log(10));
// println("numTicks: " + numTicks);
// println("maxTickVal: " + maxTickVal);
for (int i = (int)numTicks; i > 1; i--) {
float currTickVal = pow(10, i);
if (fundingScaleLinLog) {
// Linear scale please!
tickY = map(currTickVal, (int)maxTickVal, transactionMin, fundingAxis1.y, fundingAxis2.y);
} else {
// Log scale pfv
// tickY = powMap((int)currTickVal, fundingAxisLogBase, (int)maxTickVal, transactionMin, fundingAxis1.y, fundingAxis2.y);
tickY = map(log(currTickVal), log(pow(10, 9)), 0, fundingAxis1.y, fundingAxis2.y);
}
// tickX = map(i, numTicks, 0, PLOT_X1, fundingAxis1.x-0);
tickX = fundingAxis1.x-200;
// place tick
stroke(unBlueClr, 123);
// line(tickX, tickY, tickX-10, tickY);
line(tickX, tickY, fundingAxis1.x, tickY);
// place text
fill(transactionCurveClr);
textAlign(LEFT);
text("$"+nfc((int)currTickVal, 0), tickX, tickY+textAscent()+5);
}
// mark the bottom of the funding axis with a $0 tick
text("$0", fundingAxis1.x - textWidth("$0 "), fundingAxis2.y+textAscent()+5);
line(fundingAxis1.x-10, fundingAxis2.y, fundingAxis1.x, fundingAxis2.y);
}
float getHigherOrderOfMag(float _n) {
float n = _n;
float roundUpLogTen = ceil(log(n)/log(10));
float higher = pow(10, roundUpLogTen);
// println(n + " becomes " + higher);
return higher;
}
float getLowerOrderOfMag(float _n) {
float n = _n;
float roundLogTen = floor(log(n)/log(10));
float lower = pow(10, roundLogTen);
// println(n + " becomes " + lower);
return lower;
}
void renderBarChart() {
int rowCounter=0;
for (TableRow row : expenditureByCountryTbl.rows()) {
float tx = countryAxis1.x + 18;
float ty = map(rowCounter+=1, 0, expenditureByCountryTbl.getRowCount(), PLOT_Y1, PLOT_Y2);
float barChartW = map(row.getFloat("Amount"), 0, countryExpendMax, 0, PLOT_X2-countryAxis1.x);
fill(unBlueClr, 76);
noStroke();
rect(tx, ty, barChartW, 2);
}
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ARRAYLIST UTILITIES
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
Country findCountryByName(String _cName) {
String cName = _cName;
for (Country country : countries) {
if (country.countryName.equals(cName)) {
return country;
}
}
return null;
}
Agency findAgencyByUnAbbrev(String _unAbbrev) {
String unAbbrev = _unAbbrev;
// println("in findAgencyByUnAbbrev()\nagencies.size(): "+agencies.size());
for (Agency agency : agencies) {
if (agency.unAgencyAbbrev.equals(unAbbrev)) {
return agency;
}
}
return null;
}
ArrayList<Transaction> transactionCollectionByCountry(String countryName) {
ArrayList<Transaction> transactionCollection = new ArrayList<Transaction>();
for (Transaction currTransaction : transactions) {
if (currTransaction.countryName.equals(countryName)) {
transactionCollection.add(currTransaction);
}
}
return transactionCollection;
}
ArrayList<Transaction> transactionCollectionByAgency(String agencyAbbrev) {
ArrayList<Transaction> tColl = new ArrayList<Transaction>();
for (Transaction t : transactions) {
if (t.unAgencyAbbrev.equals(agencyAbbrev)) {
tColl.add(t);
}
}
return tColl;
}
ArrayList<Country> countryListByAgency(String agencyAbbrev, String countryName) {
ArrayList<Country> countryList = new ArrayList<Country>();
for (Transaction t : transactions) {
if (t.unAgencyAbbrev.equals(agencyAbbrev) && (t.countryName.equals(countryName))) {
countryList.add(t.country);
}
}
return countryList;
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Tests
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
void test_CountryObj(String _cName) {
String cName = _cName;
Country currCountry = findCountryByName(cName);
String output = "------- ---- ---";
output += "\n"+currCountry;
output += "\nCountry name: " + currCountry.countryName;
output += "\nyear: " + currCountry.year;
output += "\namount: " + currCountry.amount;
// print out country name, year, amount and
// every transaction showing agency and amount
output += "\n";
output += "\nAll transactions for " + currCountry.countryName;
for (Transaction currTrans : currCountry.countryTransactions) {
output += "\n"+currTrans.unAgencyAbbrev + ": " + currTrans.amount;
}
println(output);
}
void test_AgencyObj(String _ag) {
String ag = _ag;
Agency currAg = findAgencyByUnAbbrev(ag);
String output = "------- ---- ---";
output += "\n"+currAg;
output += "\nAgency name: " + currAg.unAgencyAbbrev;
output += "\nyear: " + currAg.year;
output += "\namount: " + currAg.expenditure;
for (Transaction t : currAg.agencyTransactions) {
output += "\n"+t.countryName + ": " + t.amount;
}
println(output);
}
void test_AgencyNullObj() {
Agency nullAg = new Agency();
println(nullAg);
println(nullAg.agencyName);
}