import java.util.*; import java.math.*; /* Stealing code from splWeek1_Example 3 to jumpstart my project. Goal is a 2 dimensional array of blocks, where: the Y-Axis location handles time of day; The X-Axis handles day of month; and the color/alpha is set by the Dewey classification. */ /*DECLARATIONS*/ int deweyclassredstart = 796; int deweyclassredfinish = 797; int deweyclassgreenstart = 398; int deweyclassgreenfinish = 399; int deweyclassbluestart = 746; int deweyclassbluefinish = 747; //Drawing options int starttime; int finishtime; int gridlocx = 75; int gridlocy = 25; int titlelocx = 100; int titlelocy = 25; int dispwidth = 150; int dispheight; int disptxtvert; int dispvertunit; int disptxtlocx; // 2D Array of objects Cell[][] grid; // Number of columns and rows in the grid int cols = 7; //In this implementation this needs to stay 7 or it will break! int rows = 24*2; int cwidth = 120; int cheight = floor(1000/rows); /*BAGGAGE*/ ArrayList transactions = null; //global List of the data int idx = 0; int maxNum = 200; int[] deweyCount = new int[10]; int totalDeweys = 0; long timer = 0; /* MY BAGGAGE */ public int maxhits = 1; public int maxredhits = 1; public int maxbluehits = 1; public int maxgreenhits = 1; public boolean pressed = false; public String disptimestart = " "; public String disptimefinish = " "; public int disphits; public int dispred; public int dispgreen; public int dispblue; public float dispredperc; public float dispgreenperc; public float dispblueperc; /* THIS RUNS BEFORE ANYTHING ELSE */ void setup() { size(800,600, P2D); frameRate(1000); //that is, as fast as possible textFont(loadFont("GillSans-24.vlw"),24); background(0); fill(255); stroke(100,100,100,255); background(0); doVariables(); doGrid(); fillCells(); findMaxhits(); updateCells(); } //Initializes each cell in the grid void doGrid() { for (int k = 0; k < cols; k++) { for (int l = 0; l < rows; l++) { // Initialize each object grid[k][l] = new Cell(); } } } void updateCells() { for (int k = 0; k < cols; k++) { for (int l = 0; l < rows; l++) { // Update Each object grid[k][l].updateCell(); } } } void doVariables() { //Writing starttime for display starttime = floor( (9.5/24.0) * rows ); finishtime = floor( (20.5/24.0) * rows ); long before = millis(); this.transactions = loadTransactions("splxmldata.txt"); println("loaded " + this.transactions.size() + " transactions in " + (millis() - before) + " miiliseconds."); //Initializes the grid grid = new Cell[cols][rows]; } /* THIS RUNS EACH FRAME Draw draw draw draw... draw draw draw */ void draw() { //clearBackground background(255); redoVariables(); drawGrid(); drawTitle(); drawLabels(); drawDepth(); } void drawGrid() { stroke(0); for (int k = 0; k < cols; k++) { for (int l = starttime; l < finishtime; l++) { grid[k][l].drawCell(cwidth*k + gridlocx,cheight*(l-starttime) + gridlocy , cwidth, cheight) ; } } } void redoVariables() { cheight = floor(((height - 2 * gridlocy ) / ((11.0/24.0)*rows))); cwidth = floor(( (width - 2 * gridlocx - dispwidth) / cols)); disptxtlocx = floor( gridlocx * 1.5 + cwidth * 7 + dispwidth/2 ); dispvertunit = cheight * (finishtime - starttime) / 16; disptxtvert = 2 * dispvertunit; } void drawTitle() { textAlign(LEFT); text("More in the morning?",titlelocx,titlelocy); } void drawLabels() { fill(50,50,50,255); stroke(255,255,255,255); textAlign(RIGHT,CENTER); text(" 10 AM", gridlocx , gridlocy + (0.5/24.0) * rows * cheight); line( gridlocx , gridlocy + (0.5/24.0) * rows * cheight, gridlocx + cols * cwidth, gridlocy + (0.5/24.0) * rows * cheight ); text(" 12 PM", gridlocx , gridlocy + (2.5/24.0) * rows * cheight); line( gridlocx , gridlocy + (2.5/24.0) * rows * cheight, gridlocx + cols * cwidth, gridlocy + (2.5/24.0) * rows * cheight ); text(" 2 PM", gridlocx , gridlocy + (4.5/24.0) * rows * cheight); line( gridlocx , gridlocy + (4.5/24.0) * rows * cheight, gridlocx + cols * cwidth, gridlocy + (4.5/24.0) * rows * cheight ); text(" 4 PM", gridlocx , gridlocy + (6.5/24.0) * rows * cheight); line( gridlocx , gridlocy + (6.5/24.0) * rows * cheight, gridlocx + cols * cwidth, gridlocy + (6.5/24.0) * rows * cheight ); text(" 6 PM", gridlocx , gridlocy + (8.5/24.0) * rows * cheight); line( gridlocx , gridlocy + (8.5/24.0) * rows * cheight, gridlocx + cols * cwidth, gridlocy + (8.5/24.0) * rows * cheight ); text(" 8 PM", gridlocx , gridlocy + (10.5/24.0) * rows * cheight); line( gridlocx , gridlocy + (10.5/24.0) * rows * cheight, gridlocx + cols * cwidth, gridlocy + (10.5/24.0) * rows * cheight ); textAlign(LEFT,TOP); text("SUN", gridlocx, gridlocy + cheight*(finishtime - starttime)); text("MON", gridlocx + cwidth , gridlocy + cheight*(finishtime - starttime)); text("TUE", gridlocx + cwidth * 2, gridlocy + cheight*(finishtime - starttime)); text("WED", gridlocx + cwidth * 3, gridlocy + cheight*(finishtime - starttime)); text("THU", gridlocx + cwidth * 4, gridlocy + cheight*(finishtime - starttime)); text("FRI", gridlocx + cwidth * 5, gridlocy + cheight*(finishtime - starttime)); text("SAT", gridlocx + cwidth * 6, gridlocy + cheight*(finishtime - starttime)); } void drawDepth() { fill(0,0,0,255); stroke(100,100,100,255); rect(gridlocx * 1.5 + cwidth * 7, gridlocy, dispwidth, cheight*(finishtime - starttime) ); textAlign(CENTER,TOP); fill(200,200,200); text("Total Results:", disptxtlocx , gridlocy + disptxtvert ); disptxtvert += dispvertunit; text(disphits, disptxtlocx , gridlocy + disptxtvert ); disptxtvert += 2*dispvertunit; fill(255,0,0); text("Sports:", disptxtlocx, gridlocy + disptxtvert); disptxtvert += dispvertunit; text(dispred, disptxtlocx , gridlocy + disptxtvert ); disptxtvert += dispvertunit; fill(0,255,0); text("Folklore:", disptxtlocx , gridlocy + disptxtvert ); disptxtvert += dispvertunit; text(dispgreen, disptxtlocx , gridlocy + disptxtvert ); disptxtvert += dispvertunit; fill(0,0,255); text("Textiles:", disptxtlocx, gridlocy + disptxtvert ); disptxtvert += dispvertunit; text(dispblue , disptxtlocx , gridlocy + disptxtvert ); disptxtvert += 2*dispvertunit; fill(200,200,200); text("Between:", disptxtlocx , gridlocy + disptxtvert ); disptxtvert += dispvertunit; text(disptimestart,disptxtlocx , gridlocy + disptxtvert ); disptxtvert += 30; text("and", disptxtlocx , gridlocy + disptxtvert ); disptxtvert += 30; text(disptimefinish, disptxtlocx , gridlocy + disptxtvert ); disptxtvert += dispvertunit; } /* THE STUFF DOWN HERE PARSES THE DATA*/ public ArrayList loadTransactions(String nameOfDataFileWithinDataDirectory) { ArrayList transactions = new ArrayList(); String[] lines = loadStrings(nameOfDataFileWithinDataDirectory); for (int i = 0; i < lines.length; i++) { transactions.add(parseTransaction(lines[i])); } return transactions; } //create a new transaction obejct from a comma separated line. public Transaction parseTransaction(String line) { String sections[] = split(line, ","); Transaction t = new Transaction(); //store all fields t.ckodate = sections[0]; t.ckotime = sections[1]; t.title = sections[3]; t.deweyClass = sections[4]; return t; }