/** * Heat_of_the_moment * * Load a data file about temperature readings (TR). Each TR has elements separated * with a spance. */ // Manage the values of the file, values are separated by space //Indices for the columns in the file "history.txt" /* 3B00080058124B10 - meeting room - 1 73000800B1D9BD10 - main lab - 2 DB000800B1E8E710 - machine room - 3 F2000800B1D88510 - lounge - 4 35000800B1EC2510 - prototype space - 5 DB00080041634E10 - classroom - 6 FF00080057FB1810 - office space - 7 */ static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; static final long MILLIS_PER_HOUR = 60 * 60 * 1000; static float MULTIPLICATOR_VALUE = 0.5556; color[] roomColor = {#2B60DE,#8D38C9,#FFF380,#43C6DB,#F6358A,#347C2C,#F87431}; color[] buttonColor = {#552233,#993322}; //pos 0 - no pressed, pos 1 - pressed color[] textColor = {#747170,#FFFFFF}; //pos 0 - no pressed, pos 1 - pressed color[] colorSeasons = {#98AFC7,#4AA02C,#FFFC17,#C34A2C}; color colorStrings = #000000; color colorBackground = #FFFFFF; color colorLinesPlot = #FFFFFF; color colorPlot = #000000; color colorIntervals = #FFFFFF; color colorWeather = #556677; int BUTTON_W = 62; int BUTTON_H = 15; int PLOT_X = 50; int PLOT_Y = 300; int PLOT_H = 250; int PLOT_W = 900; //indices that help to access the information in the history file. int DATE = 0; int HOUR_MIN = 1; int AM_PM = 2; int ROOM_SENSOR = 3; int TEMPERATURE =4; //indices that help to access the information in the school calendar file. int SESSION = 0; int START_DATE = 1; int END_DATE = 2; char showData = 'M'; //Could be M = months, D = days, H = hours, to refer which array of data we are going to use. char CorF = 'C'; boolean allRooms = false; boolean allYears = true; boolean showByDay = false; boolean showByMonth = false; boolean showOutside = false; boolean showSeasons = false; boolean showSchoolDates = false; boolean savePredictions = false; int NUM_ROOMS = 7; int MEASURES_DAY = 24; PImage floorImage; float imageX; float imageY; ReadingTable data; WeatherTable chicagoData; String[] schoolDates; //To use in date, month, and year slider long minDate; long maxDate; long plotMinDate; long plotMaxDate; String firstDate; String lastDate; int minDateIndex; int maxDateIndex; int minMonthIndex; int maxMonthIndex; String[] dateLabel; int dateCount; int minYear; int maxYear; String[] yearLabel; String[] monthLabel; int monthCount; int yearCount; int minYearIndex = 0; int maxYearIndex = 0; float dataMin; float dataMax; int currentDateMin, currentDateMax;// keep the index of the array that will be draw. int currentRoom; //int currentColumn; //Variables to determine the position of the year, month & dates selector int yearSelectorX = 25; int yearSelectorY = 40; int yearIndex = 0; int yYearPos = 110; int dateSelectorX = 25; int dateSelectorY = 35; int dateIndex = 0; int yDatePos = 230; int monthSelectorX = 25; int monthSelectorY = 40; int monthIndex = 0; int yMonthPos = 180; DateFormat dateFormat= new SimpleDateFormat("MMM/dd/yyyy"); DateFormat yearFormatToPrint = new SimpleDateFormat ("yyyy"); DateFormat shortYearFormatToPrint = new SimpleDateFormat("yy"); DateFormat monthYearFormat = new SimpleDateFormat("MMM yyyy"); DateFormat readingDateFormat = new SimpleDateFormat("MMM/dd/yyyy hh:mm aa"); DateFormat monthFormatToPrint = new SimpleDateFormat ("MMM"); DateFormat shortMonthFormatToPrint = new SimpleDateFormat ("MM"); DateFormat timeFormatToPrint = new SimpleDateFormat ("hh:mm aa"); DateFormat dayFormatToPrint = new SimpleDateFormat("dd"); int temperatureInterval = 6; int temperatureIntervalMinor = 2; long datesInterval = MILLIS_PER_DAY * 14; boolean changes = true; void setup(){ size(1000, 650); fill(colorBackground); floorImage = loadImage("evl_2nd_floor.jpg"); floorImage.resize(int(floorImage.width/2),int(floorImage.height/2)); imageX = (width-floorImage.width)/2; imageY = 25; data = new ReadingTable("history.txt"); //Load the temperature information detected by the sensors chicagoData = new WeatherTable("ChicagoTemperatures.csv"); // Load the history temperature average of chicago area loadSchoolDates("SchoolCalendar.csv"); // Load the dates of UIC school session minDate = data.getMinDate(); maxDate = data.getMaxDate(); setCorF('F'); setupYears(); setYear(constrain(0, minYearIndex, maxYearIndex)); // set the dates to show in the plot setCurrentDates(minDate,maxDate); /* interpolators = new Integrator[data.getRowCount()]; for (int row = 0; row < data.getRowCount(); row++){ float initialValue = data.getFloat(row,currentRoom); interpolators[row] = new Integrator(initialValue); interpolators[row].attraction = 0.2; }*/ //Define all buttons and check box in the screen. smooth(); // noLoop(); } void draw(){ background(255); //Draw title textSize(20); textAlign(CENTER, TOP); fill(colorStrings);; text("EVL MAP LAYOUT", width * 0.5, 5); textSize(12); if (floorImage != null){ image (floorImage,imageX,imageY); } drawRooms(); rectMode(CORNER); drawYearSelector(); drawMonthSelector(); drawDateSelector(); drawButtons(); //Draw the plot in the screen drawTitle(currentRoom); stroke(colorLinesPlot); strokeWeight(1); noFill(); fill(colorPlot); rect(PLOT_X, PLOT_Y, PLOT_W, PLOT_H); textSize(10); drawTemperatureLabels(); drawDatesLabels(); if (showSchoolDates) drawSchoolDates(); if (showOutside) drawChicagoWeather(); /* for (int row = 0; row < data.getRowCount(); row++){ interpolators[row].update(); } drawDataArea(currentDate,currentRoom); */ if (showSeasons) drawSeasons(); noFill(); if (allRooms){ for (int i = 0; i < data.getColumnCount() ; i++) drawDataLine(currentDateMin,currentDateMax,i); for (int i = 0; i < data.getColumnCount() ; i++) drawDataPoints(currentDateMin,currentDateMax,i); } else{ drawDataLine(currentDateMin,currentDateMax,currentRoom); drawDataPoints(currentDateMin,currentDateMax,currentRoom); } if (showOutside) drawLabelsChicagoWeather(); } void loadSchoolDates(String _filename){ schoolDates = loadStrings("SchoolCalendar.csv"); } void setCorF(char _type){ CorF = _type; setMinMaxValues(); } void setMinMaxValues(){ if (data.getTableMin() < chicagoData.getTableMin()) dataMin = floor(data.getTableMin() / temperatureInterval) * temperatureInterval; else dataMin = floor (chicagoData.getTableMin() / temperatureInterval) * temperatureInterval; if (data.getTableMax() > chicagoData.getTableMax()) dataMax = ceil(data.getTableMax() / temperatureInterval) * temperatureInterval; else dataMax = ceil(chicagoData.getTableMax() / temperatureInterval) * temperatureInterval; } void setupDates() { try { // The years in the middle // Calculate number of days by dividing the total milliseconds // between the first and last dates by the number of milliseconds per day dateCount = (int)(((dateFormat.parse("Dec/31/"+yearLabel[yearIndex])).getTime() - (dateFormat.parse("Jan/01/"+yearLabel[yearIndex])).getTime()) / MILLIS_PER_DAY) + 1; minDateIndex = 0; maxDateIndex = dateCount - 1; dateLabel = new String[dateCount]; for (int i = 0; i < dateCount; i++) { Date date = new Date(dateFormat.parse("Jan/01/"+yearLabel[yearIndex]+" 11:00 PM").getTime() + MILLIS_PER_DAY*i); dateLabel[i] = dateFormat.format(date); if (date.getTime() <= minDate) minDateIndex = i; if (date.getTime() <= maxDate) maxDateIndex = i -1 ; // If this value for 'date' is equal to today, then set the previous // day as the maximum viewable date, because it means the season is // still ongoing. The previous day is used because unless it is late // in the evening, the updated numbers for the day will be unavailable // or incomplete. } } catch (ParseException e) { die("Problem while setting up dates", e); } } void setupYears() { try { Date firstDate = getDateFromMillis(minDate); Date lastDate = getDateFromMillis(maxDate); int firstYear = int(yearFormatToPrint.format(firstDate)); yearCount = int(yearFormatToPrint.format(lastDate)) - firstYear + 1 ; maxYearIndex = yearCount - 1; yearLabel = new String[yearCount]; for (int i = 0; i < yearCount; i++) { yearLabel[i] = str(firstYear + i); } } catch (Exception e) { die("Problem while setting up years", e); } } void setupMonths() { try { monthLabel = new String[] {"January","February","March","April","May","June","July","August","September","October","November","December"}; minMonthIndex = 0; maxMonthIndex = 0; monthCount = monthLabel.length; for (int i = 0; i < monthCount; i++) { println("Setup month " + minDate + ","+maxDate); Date date = new Date( (dateFormat.parse(monthLabel[i].substring(0,3)+"/01/"+yearLabel[yearIndex])).getTime() ); println("Setup month 1 " + minDate + ","+maxDate); if (date.getTime() <= minDate) minMonthIndex = i; date = new Date(readingDateFormat.parse(monthLabel[i].substring(0,3)+"/"+getLastDayXMonth(yearLabel[yearIndex],monthLabel[i])+"/"+yearLabel[yearIndex]+" 11:00 PM").getTime() ); println("Setup month 2" + minDate + ","+maxDate + " , " + date); if (date.getTime() <= maxDate) maxMonthIndex = i ; } } catch (Exception e) { die("Problem while setting up months", e); } } void drawDataLine(int _indexDateMin,int _indexDateMax, int _room) { try { beginShape(); for (int row = _indexDateMin; row<= _indexDateMax; row++){ if (data.isValid(row,_room)){ float value = data.getFloat(row,_room); if (value >= dataMin && value <= dataMax){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); float y = map(value,dataMin,dataMax,PLOT_Y + PLOT_H,PLOT_Y); stroke(roomColor[_room]); if (showData == 'M' || (showData == 'H' && showByDay) || (showData == 'D' && showByMonth)){ strokeWeight((currentRoom==_room)?3:1); curveVertex(x,y); if ((row == _indexDateMin) || (row == _indexDateMax)) curveVertex(x,y); } strokeWeight((currentRoom==_room)?5:2); point(x,y); strokeWeight((currentRoom==_room)?3:1); } } } endShape(); } catch (Exception e) { die("Problem while drawing data points", e); } } void drawChicagoWeather() { noFill(); stroke(colorWeather); strokeWeight(1); beginShape(); float x = 0; float y = 0; boolean entro = false; for (int row = 0; row < chicagoData.getRowCount(); row++){ if (chicagoData.isValid(row,0)){ float value = chicagoData.getFloat(row,0); if (value >= dataMin && value <= dataMax){ long date = chicagoData.getRowName(row); if (date>plotMaxDate) break; x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); y = map(value,dataMin,dataMax,PLOT_Y + PLOT_H,PLOT_Y); if (showData == 'M' ||(showData=='D' && showByMonth)) curveVertex(x,y); if (!entro && showData == 'M' ||(showData=='D' && showByMonth)) curveVertex(x,y); entro = true; strokeWeight(3); point(x,y); strokeWeight(1); } } } if (entro && showData =='M' || (showData=='D' && showByMonth)) curveVertex(x,y); endShape(); } void drawLabelsChicagoWeather() { noFill(); stroke(colorWeather); strokeWeight(1); float x = 0; float y = 0; boolean entro = false; for (int row = 0; row < chicagoData.getRowCount(); row++){ if (chicagoData.isValid(row,0)){ float value = chicagoData.getFloat(row,0); if (value >= dataMin && value <= dataMax){ long date = chicagoData.getRowName(row); if (date>plotMaxDate) break; x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); y = map(value,dataMin,dataMax,PLOT_Y + PLOT_H,PLOT_Y); if (dist(mouseX,mouseY,x,y) < 3){ strokeWeight(2); point(x,y); fill(125); textSize(11); rectMode(CORNERS); rect(((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-182):(x-2),y-40,((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-2):(x+180),y-1); fill(colorStrings);; if (showData == 'M') text("Outside temperature\n AVG = " + nf(value,0,0)+ "°"+((CorF=='C')?"C":"F") +" - "+ monthYearFormat.format(getDateFromMillis(date)),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-182):(x-2),y-40,((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-2):(x+180),y-1); else text("Outside temperature\n AVG = " + nf(value,0,0)+ "°"+((CorF=='C')?"C":"F") +" - "+ dateFormat.format(getDateFromMillis(date)),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-182):(x-2),y-40,((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-2):(x+180),y-1); noFill(); } } } } } void drawSeasons() { try{ textAlign(CENTER); rectMode(CORNERS); if (allYears) textSize(8); else textSize(10); noStroke(); float x1,x2; Date firstDate = getDateFromMillis(plotMinDate); int firstYear = int(yearFormatToPrint.format(firstDate)); int yearCount = int(yearFormatToPrint.format(getDateFromMillis(plotMaxDate))) - firstYear + 1 ; for (int i=0; i < yearCount; i++){ //rect Winter fill(colorSeasons[0],20); x1 = map(constrain((dateFormat.parse("Nov/30/"+str(firstYear-1+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); x2 = map(constrain((dateFormat.parse("Mar/01/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); rect(x1,PLOT_Y,x2,PLOT_Y+PLOT_H+30); fill(colorStrings);; if (x2-x1 > 25) text ("Winter",x1+((x2-x1)/2),PLOT_Y + PLOT_H+30); //rect Spring fill(colorSeasons[1],40); x1 = map(constrain((dateFormat.parse("Mar/01/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); x2 = map(constrain((dateFormat.parse("May/31/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); rect(x1,PLOT_Y,x2,PLOT_Y+PLOT_H+30); fill(colorStrings);; if (x2-x1 > 25) text ("Spring",x1+((x2-x1)/2),PLOT_Y + PLOT_H+30); //rect Summer fill(colorSeasons[2],40); x1 = map(constrain((dateFormat.parse("May/31/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); x2 = map(constrain((dateFormat.parse("Aug/31/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); rect(x1,PLOT_Y,x2,PLOT_Y+PLOT_H+30); fill(colorStrings); if (x2-x1 > 25) text ("Summer",x1+((x2-x1)/2),PLOT_Y + PLOT_H+30); fill(colorSeasons[3],40); x1 = map(constrain((dateFormat.parse("Aug/31/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); x2 = map(constrain((dateFormat.parse("Nov/30/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); rect(x1,PLOT_Y,x2,PLOT_Y+PLOT_H+30); fill(colorStrings);; if (x2-x1 > 25) text ("Fall",x1+((x2-x1)/2),PLOT_Y + PLOT_H+30); if (yearCount == 1){ fill(colorSeasons[0],25); x1 = map(constrain((dateFormat.parse("Nov/30/"+str(firstYear+i))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); x2 = map(constrain((dateFormat.parse("Mar/01/"+str(firstYear+i+1))).getTime(),plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); rect(x1,PLOT_Y,x2,PLOT_Y+PLOT_H+30); fill(colorStrings);; if (x2-x1 > 25) text ("Winter",x1+((x2-x1)/2),PLOT_Y + PLOT_H+30); } } noFill(); } catch (ParseException e) { die("Problem while setting up dates", e); } } Date convertStringToDate(long _date){ Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(_date); return calendar.getTime(); } void drawDataPoints(int _indexDateMin,int _indexDateMax,int _room) { textAlign(CENTER,CENTER); for (int row = _indexDateMin; row<= _indexDateMax; row++){ if (data.isValid(row,_room)){ // float value = interpolators[row].value; float value = data.getFloat(row,_room); if (value >= dataMin && value <= dataMax){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); float y = map(value,dataMin,dataMax,PLOT_Y+PLOT_H,PLOT_Y); stroke(roomColor[_room]); if (dist(mouseX,mouseY,x,y) < 3){ strokeWeight(2); point(x,y); fill(125); textSize(11); rectMode(CORNERS); if (showData =='M' || showData == 'D') rect(((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-182):(x-2),y-20-((allRooms)?20:0),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-2):(x+180),y-1); else rect(((PLOT_X+PLOT_W)<(x+260))?(PLOT_X+PLOT_W-260):(x-2),y-20-((allRooms)?20:0),((PLOT_X+PLOT_W)<(x+260))?(PLOT_X+PLOT_W-2):(x+260),y-1); fill(colorStrings);; if (showData == 'M') text(((!allRooms)?"":(data.getColumnName(_room)+"\n")) + " AVG = " + nf(value,0,0)+ "°"+((CorF=='C')?"C":"F") +" - "+ monthYearFormat.format(getDateFromMillis(date)),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-182):(x-2),y-20-((allRooms)?20:0),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-2):(x+180),y-1); if (showData == 'D') text(((!allRooms)?"":(data.getColumnName(_room)+"\n"))+ " AVG = " + nf(value,0,0)+ "°"+((CorF=='C')?"C":"F") +" - "+ dateFormat.format(getDateFromMillis(date)),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-182):(x-2),y-20-((allRooms)?20:0),((PLOT_X+PLOT_W)<(x+180))?(PLOT_X+PLOT_W-2):(x+180),y-1); if (showData == 'H') text(((!allRooms)?"":(data.getColumnName(_room)+"\n")) + " Reading = " + nf(value,0,0)+ "°"+((CorF=='C')?"C":"F") +" - "+ readingDateFormat.format(getDateFromMillis(date)),((PLOT_X+PLOT_W)<(x+260))?(PLOT_X+PLOT_W-260):(x-2),y-20-((allRooms)?20:0),((PLOT_X+PLOT_W)<(x+260))?(PLOT_X+PLOT_W-2):(x+260),y-1); noFill(); } } } } } // Draw a series of lines for selecting the date void drawDateSelector() { textAlign(LEFT, TOP); int selectColor; if(showByDay) selectColor = 0; else selectColor = 150; fill(selectColor); text("Choose a date:", dateSelectorX, yDatePos-5 ); strokeWeight(1); for (int i = 0; i < dateCount; i++) { int x = 100 + dateSelectorX + i*2; // If this is the currently selected date, draw it differently if (i == dateIndex) { stroke(selectColor); line(x, yDatePos, x, yDatePos + 13); textAlign(CENTER, TOP); text(dateLabel[dateIndex], x, yDatePos + 15); } else { // If this is a viewable date, make the line darker if ((i >= minDateIndex) && (i <= maxDateIndex)) { stroke(150); // Viewable date } else { stroke(225); // Not a viewable date } line(x, yDatePos, x, yDatePos + 7); } } } // Draw a series of lines for selecting the year void drawYearSelector() { textAlign(LEFT, TOP); int selectColor; if(!allYears) selectColor = 0; else selectColor = 150; fill(selectColor); text("Choose a year:", yearSelectorX, yYearPos - 5); strokeWeight(3); for (int i = 0; i < yearCount; i++) { int x = 100 + yearSelectorX + i*8; // If this is the currently selected date, draw it differently if (i == yearIndex) { stroke(selectColor); textAlign(CENTER, TOP); text(yearLabel[yearIndex], x, yYearPos + 25); line(x, yYearPos, x, yYearPos + 20); } else { stroke(150); // Viewable date line(x, yYearPos, x, yYearPos + 15); } } } // Draw a series of lines for selecting the year void drawMonthSelector() { textAlign(LEFT, TOP); int selectColor; if(showByMonth) selectColor = 0; else selectColor = 150; fill(selectColor); text("Choose a month:", monthSelectorX, yMonthPos-5 ); strokeWeight(1); for (int i = 0; i < monthCount; i++) { int x = 100 + monthSelectorX + i*5; // If this is the currently selected date, draw it differently if (i == monthIndex) { stroke(selectColor); line(x, yMonthPos, x, yMonthPos + 13); textAlign(CENTER, TOP); text(monthLabel[monthIndex], x, yMonthPos + 15); } else { // If this is a viewable date, make the line darker if ((i >= minMonthIndex) && (i <= maxMonthIndex)) { stroke(150); // Viewable date } else { stroke(225); // Not a viewable date } line(x, yMonthPos, x, yMonthPos + 7); } } } void drawButton(float _x,float _y, int _w, int _h, String _text, int _indexColor) { fill(buttonColor[_indexColor]); rect(_x,_y, _w,_h); fill(textColor[_indexColor]); text(_text, _x, _y); } void drawButtons(){ textAlign(LEFT,TOP); textSize(11); // At the top of the plot drawButton(PLOT_X + PLOT_W - 80, PLOT_Y - 33,BUTTON_W,BUTTON_H," Show in °C ",(CorF=='C')?1:0); drawButton(PLOT_X + PLOT_W - 145, PLOT_Y - 33,BUTTON_W,BUTTON_H," Show in °F ",(CorF=='F')?1:0); drawButton(PLOT_X + PLOT_W - 245, PLOT_Y - 33,BUTTON_W,BUTTON_H," All rooms ",(allRooms)?1:0); drawButton(PLOT_X + PLOT_W - 310, PLOT_Y - 33,BUTTON_W,BUTTON_H," Per room ",(allRooms)?0:1); drawButton(PLOT_X + PLOT_W - 410, PLOT_Y - 33,BUTTON_W,BUTTON_H," All years ",(allYears)?1:0); drawButton(PLOT_X + PLOT_W - 475, PLOT_Y - 33,BUTTON_W,BUTTON_H," Per year ",(!showByDay && !allYears && !showByMonth )?1:0); drawButton(PLOT_X + PLOT_W - 540, PLOT_Y - 33,BUTTON_W,BUTTON_H," Per month ",(showByMonth)?1:0); drawButton(PLOT_X + PLOT_W - 605, PLOT_Y - 33,BUTTON_W,BUTTON_H," Per date ",(showByDay)?1:0); //At the bottom of the plot fill(colorStrings);; text("Data: ", PLOT_X + PLOT_W - 240,PLOT_Y + PLOT_H + 45); if (!showByDay && !showByMonth){ drawButton(PLOT_X + PLOT_W - 80, PLOT_Y + PLOT_H + 45,BUTTON_W,BUTTON_H," Monthly",(showData=='M')?1:0); } if (!showByDay) { drawButton(PLOT_X + PLOT_W - 145, PLOT_Y + PLOT_H + 45,BUTTON_W,BUTTON_H," Daily",(showData=='D')?1:0); drawButton(PLOT_X + PLOT_W - 370, PLOT_Y + PLOT_H + 45,BUTTON_W+25,BUTTON_H," Outside Temp.",(showOutside)?1:0); } drawButton(PLOT_X + PLOT_W - 210, PLOT_Y + PLOT_H + 45,BUTTON_W,BUTTON_H," Hourly",(showData=='H')?1:0); drawButton(PLOT_X + PLOT_W - 470, PLOT_Y + PLOT_H + 45,BUTTON_W+25,BUTTON_H," Show seasons ",(showSeasons)?1:0); drawButton(PLOT_X + PLOT_W - 570, PLOT_Y + PLOT_H + 45,BUTTON_W+35,BUTTON_H," Show UIC events",(showSchoolDates)?1:0); if (showByMonth){ if (yearIndex == (yearCount - 1) && (monthIndex > maxMonthIndex)){ drawButton(110+monthSelectorX + monthCount*5, yMonthPos - 5,BUTTON_W+35,BUTTON_H," Save prediction",(savePredictions)?1:0); } } } void setDate(int index) { try{ dateIndex = index; if (!showByMonth){ String _month = monthFormatToPrint.format(dateFormat.parse(dateLabel[dateIndex])); for (int i=0;i< monthCount; i++){ if (_month.equals(monthLabel[i].substring(0,3))) setMonth(i); } } }catch (ParseException e) { die("Problem while setting up dates", e); } } void setYear(int index) { yearIndex = index; setupMonths(); setupDates(); } void setMonth(int index){ try{ monthIndex = index; if (!showByDay){ for (int i=0;i< dateCount; i++){ String _month = monthFormatToPrint.format(dateFormat.parse(dateLabel[i])); if (_month.equals(monthLabel[monthIndex].substring(0,3))) setDate(i); } } }catch (ParseException e) { die("Problem while setting up dates", e); } } void setShowData(char _value){ showData = _value; //redraw(); } // Plot Functions void drawTitle(int _room) { fill(colorStrings);; textSize(13); textAlign(LEFT); if (!allRooms && _room >= 0) text("Temperature in °" + ((CorF == 'C') ? "C":"F") + " at "+data.getColumnName(_room), PLOT_X , PLOT_Y - 5); else if (_room >= 0) text("Temperature in °" + ((CorF == 'C') ? "C":"F") + " at EVL - Highlighted "+data.getColumnName(_room), PLOT_X , PLOT_Y - 5); else text("Temperature in °" + ((CorF == 'C') ? "C":"F") + " at EVL", PLOT_X , PLOT_Y - 5); } void drawTemperatureLabels(){ textAlign(RIGHT); stroke(colorStrings); for (float v = dataMin; v <= dataMax; v+= temperatureIntervalMinor){ if (v % temperatureIntervalMinor == 0){ // If a tick mark float y = map(v,dataMin,dataMax,PLOT_Y + PLOT_H,PLOT_Y); if (v % temperatureInterval == 0){ //If a major tick mark text(floor(v),PLOT_X + PLOT_W + 20,y); line(PLOT_X + PLOT_W + 3 ,y,PLOT_X + PLOT_W,y); //Draw major tick text(floor(v),PLOT_X - 3,y); line(PLOT_X - 3,y,PLOT_X,y); //Draw major tick } else{ line(PLOT_X - 1,y,PLOT_X,y);//Draw minor tick line(PLOT_X + PLOT_W + 1,y,PLOT_X + PLOT_W,y);//Draw minor tick } } } } void drawDatesLabels(){ try{ textAlign(CENTER); stroke(colorIntervals); if (allYears ){ if (!showSchoolDates){ int firstYear = int(yearFormatToPrint.format(getDateFromMillis(plotMinDate))); int yearCount = int(yearFormatToPrint.format(getDateFromMillis(plotMaxDate))) - firstYear + 1 ; String printYear = str(firstYear); for (int i=0; i < yearCount; i++){ long date = (dateFormat.parse("Jan/01/"+str(firstYear+i))).getTime(); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); String yearToPrint = str(firstYear+i); if (!yearToPrint.equals(printYear)){ printYear = yearToPrint; text (yearToPrint,x,PLOT_Y+PLOT_H+12); line (x,PLOT_Y,x,PLOT_Y+PLOT_H); } } } } else if (showData == 'H' && showByDay){ if (!showSchoolDates){ String printTime = "00"; for (int row = currentDateMin; row < currentDateMax; row=row+2){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); String timeToPrint = timeFormatToPrint.format(convertStringToDate(date)); if (!timeToPrint.equals(printTime)){ printTime = timeToPrint; text (timeToPrint,x,PLOT_Y+PLOT_H+12); line (x,PLOT_Y,x,PLOT_Y+PLOT_H); } } } else{ String printTime = "00"; for (int row = currentDateMin; row < currentDateMax; row=row+2){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); String timeToPrint = timeFormatToPrint.format(convertStringToDate(date)); if (!timeToPrint.equals(printTime) && !timeToPrint.equals("10:00 AM") && !timeToPrint.equals("12:00 PM")){ printTime = timeToPrint; text (timeToPrint,x,PLOT_Y+PLOT_H+12); line (x,PLOT_Y,x,PLOT_Y+PLOT_H); } } } } else if (showByMonth){ if (!showSchoolDates){ String printDay = "00"; for (int row = currentDateMin; row < currentDateMax; row=row+3){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); String dayToPrint = dayFormatToPrint.format(convertStringToDate(date)); if (!dayToPrint.equals(printDay)){ printDay = dayToPrint; text (dayToPrint,x,PLOT_Y+PLOT_H+12); line (x,PLOT_Y,x,PLOT_Y+PLOT_H); } } } else{ String printDay = "00"; for (int row = currentDateMin; row < currentDateMax; row=row+3){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); String dayToPrint = dayFormatToPrint.format(convertStringToDate(date)); if (!dayToPrint.equals(printDay) && !dayToPrint.equals("10:00 AM") && !dayToPrint.equals("12:00 PM")){ printDay = dayToPrint; text (dayToPrint,x,PLOT_Y+PLOT_H+12); line (x,PLOT_Y,x,PLOT_Y+PLOT_H); } } } } else{ if (!showSchoolDates){ String printMonth = "000"; float x1 = 0; for (int row = currentDateMin; row<= currentDateMax; row++){ long date = data.getRowName(row); float x = map(constrain(date,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); String monthToPrint = monthFormatToPrint.format(convertStringToDate(date))+"'"+shortYearFormatToPrint.format(convertStringToDate(date)); if (!monthToPrint.equals(printMonth)){ printMonth = monthToPrint; if (x-x1 > 30){ text (monthToPrint,x,PLOT_Y+PLOT_H+12); line (x,PLOT_Y,x,PLOT_Y+PLOT_H); } x1 = x; } } } } } catch (ParseException e) { die("Problem while setting up dates", e); } } void drawSchoolDates(){ try{ textAlign(CENTER,CENTER); rectMode(CORNERS); strokeWeight(0.5); stroke(colorWeather); if (allYears) textSize(8); else textSize (10); float x1,x2; boolean entro = false; for(int i = 0; i < schoolDates.length; i++){ String[] dates = split(schoolDates[i],','); long startDate = (dateFormat.parse(trim(dates[START_DATE]))).getTime(); long endDate = (dateFormat.parse(trim(dates[END_DATE]))).getTime(); if (startDate > plotMaxDate) break; if (endDate < plotMinDate) continue; entro = true; x1 = map(constrain(startDate,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); x2 = map(constrain(endDate,plotMinDate,plotMaxDate),plotMinDate,plotMaxDate,PLOT_X,PLOT_X+PLOT_W); //fill(255,30); noFill(); rect(x1,PLOT_Y,x2,PLOT_Y+PLOT_H+20); fill(colorStrings);; if (x2-x1 > 50) text ("UIC " +dates[SESSION] + " " +yearFormatToPrint.format(convertStringToDate(endDate)) ,x1,PLOT_Y + PLOT_H+3,x2,PLOT_Y + PLOT_H+20); else text ( dates[SESSION].substring(0,2) + "'" +shortYearFormatToPrint.format(convertStringToDate(endDate)) ,x1,PLOT_Y + PLOT_H+3,x2,PLOT_Y + PLOT_H+20); } if (showByDay && !entro){ noFill(); rect(PLOT_X,PLOT_Y,PLOT_X+PLOT_W,PLOT_Y+PLOT_H+20); fill(colorStrings);; text ("No classes" ,PLOT_X,PLOT_Y + PLOT_H+3,PLOT_X+PLOT_W,PLOT_Y + PLOT_H+20); } } catch (ParseException e) { die("Problem while setting up dates", e); } } // Mouse and Key handler void mousePressed() { handleMouse(); redraw(); } void mouseDragged() { handleMouse(); } void mouseReleased(){ // To detect if the mouse clic on a room if (mouseX > imageX+147 && mouseY > imageY+15 && mouseX < imageX+246 && mouseY < imageY+72) setCurrentRoom(0); // Room 1; else if (mouseX > imageX+265 && mouseY > imageY+15 && mouseX < imageX+349 && mouseY < imageY+108) setCurrentRoom(1); // Room 2; else if (mouseX > imageX+253 && mouseY > imageY+114 && mouseX < imageX+349 && mouseY < imageY+157) setCurrentRoom(2); // Room 3; else if (mouseX > imageX+199 && mouseY > imageY+99 && mouseX < imageX+247 && mouseY < imageY+155) setCurrentRoom(3); // Room 4; else if (mouseX > imageX+148 && mouseY > imageY+99 && mouseX < imageX+193 && mouseY < imageY+155) setCurrentRoom(4); // Room 5; else if (mouseX > imageX+42 && mouseY > imageY+99 && mouseX < imageX+141 && mouseY < imageY+155) setCurrentRoom(5); // Room 6; else if (mouseX > imageX+42 && mouseY > imageY+15 && mouseX < imageX+143 && mouseY < imageY+72) setCurrentRoom(6); // Room 7; else if (mouseX > imageX && mouseY > imageY && mouseX < imageX+floorImage.width && mouseY < imageY + floorImage.height && allRooms) setCurrentRoom(-1); // To detect if the mouse clic on the buttons at the top if ( mouseY > PLOT_Y - 33 && mouseY < PLOT_Y - 33 + BUTTON_H ){ if (mouseX > PLOT_X + PLOT_W - 80 && mouseX < PLOT_X + PLOT_W - 80 + BUTTON_W)//C Button setCorF('C'); else if (mouseX > PLOT_X + PLOT_W - 145 && mouseX < PLOT_X + PLOT_W - 145 + BUTTON_W) //F Button setCorF('F'); else if (mouseX > PLOT_X + PLOT_W - 245 && mouseX < PLOT_X + PLOT_W - 245 + BUTTON_W){//All rooms allRooms = true; } else if (mouseX > PLOT_X + PLOT_W - 310 && mouseX < PLOT_X + PLOT_W - 310 + BUTTON_W){//Per room allRooms = false; } else if (mouseX > PLOT_X + PLOT_W - 410 && mouseX < PLOT_X + PLOT_W - 410 + BUTTON_W){//All Years allYears = true; showByDay = false; showByMonth = false; setShowData('M'); setMinMaxValues(); setCurrentDates(minDate,maxDate); } else if (mouseX > PLOT_X + PLOT_W - 475 && mouseX < PLOT_X + PLOT_W - 475 + BUTTON_W){//Per year allYears = false; showByDay = false; showByMonth = false; setShowData('M'); setMinMaxValues(); setCurrentDates("Jan/01/"+yearLabel[yearIndex],"Dec/31/"+yearLabel[yearIndex]); } else if (mouseX > PLOT_X + PLOT_W - 540 && mouseX < PLOT_X + PLOT_W - 540 + BUTTON_W){//Per month showByDay = false; allYears = false; showByMonth = true; setShowData('D'); setCurrentDates(monthLabel[monthIndex].substring(0,3)+"/01/"+yearLabel[yearIndex], monthLabel[monthIndex].substring(0,3)+"/"+getLastDayXMonth(yearLabel[yearIndex],monthLabel[monthIndex])+"/"+yearLabel[yearIndex]); setMinMaxValues(); } else if (mouseX > PLOT_X + PLOT_W - 605 && mouseX < PLOT_X + PLOT_W - 605 + BUTTON_W){//Per day showByDay = true; allYears = false; showByMonth = false; setShowData('H'); setCurrentDates(dateLabel[dateIndex]+" 12:00 AM",dateLabel[dateIndex]+" 11:00 PM"); setMinMaxValues(); } } // To detect if the mouse clic on buttons at the bottom if ( mouseY > PLOT_Y + PLOT_H + 45 && mouseY < PLOT_Y + PLOT_H + 45 + BUTTON_H ){ if (mouseX > PLOT_X + PLOT_W - 80 && mouseX < PLOT_X + PLOT_W - 80 + BUTTON_W && (!showByDay || !showByMonth)) { setShowData('M'); setMinMaxValues(); if (allYears) setCurrentDates(minDate,maxDate); else setCurrentDates("Jan/01/"+yearLabel[yearIndex],"Dec/31/"+yearLabel[yearIndex]); } else if (mouseX > PLOT_X + PLOT_W - 145 && mouseX < PLOT_X + PLOT_W - 145 + BUTTON_W && !showByDay) { setShowData('D'); setMinMaxValues(); if(allYears) setCurrentDates(minDate,maxDate); else if (showByMonth) setCurrentDates(monthLabel[monthIndex].substring(0,3)+"/01/"+yearLabel[yearIndex], monthLabel[monthIndex].substring(0,3)+"/"+getLastDayXMonth(yearLabel[yearIndex],monthLabel[monthIndex])+"/"+yearLabel[yearIndex]); else setCurrentDates("Jan/01/"+yearLabel[yearIndex],"Dec/31/"+yearLabel[yearIndex]); } else if (mouseX > PLOT_X + PLOT_W - 210 && mouseX < PLOT_X + PLOT_W - 210 + BUTTON_W){ setShowData('H'); setMinMaxValues(); if (allYears) setCurrentDates(minDate,maxDate); else if (showByMonth) setCurrentDates(monthLabel[monthIndex].substring(0,3)+"/01/"+yearLabel[yearIndex], monthLabel[monthIndex].substring(0,3)+"/"+getLastDayXMonth(yearLabel[yearIndex],monthLabel[monthIndex])+"/"+yearLabel[yearIndex]); else setCurrentDates("Jan/01/"+yearLabel[yearIndex],"Dec/31/"+yearLabel[yearIndex]); } else if ( mouseX > PLOT_X + PLOT_W - 370 && mouseX < PLOT_X + PLOT_W - 370 + BUTTON_W+25 && !showByDay){ showOutside = !showOutside; } else if (mouseX > PLOT_X + PLOT_W - 470 && mouseX < PLOT_X + PLOT_W - 470 + BUTTON_W+25){ showSeasons = !showSeasons; } else if (mouseX > PLOT_X + PLOT_W - 570 && mouseX < PLOT_X + PLOT_W - 570 + BUTTON_W +35){ showSchoolDates = !showSchoolDates; } } // detect if clic on save Predictions if (showByMonth){ if (yearIndex == (yearCount - 1) && (monthIndex > maxMonthIndex)){ if (mouseX > 110+monthSelectorX + monthCount*5 && mouseY > yMonthPos - 5 && mouseX < 110+monthSelectorX + monthCount*5 + BUTTON_W+35 && mouseY < yMonthPos - 5 + BUTTON_H){ savePredictions = false; savePredictions(monthIndex,yearIndex); } } } } //return the last day a the month (28,29,30 or 31) int getLastDayXMonth(String _year, String _month){ int intYear = int(_year); if (_month.equals("January") || _month.equals("March") || _month.equals("May") || _month.equals("July") || _month.equals("August") || _month.equals("October") || _month.equals("December")) return 31; if (_month.equals("February")){ if ((intYear % 4 == 0) && ((intYear % 100 != 0) || (intYear % 400 == 0))) return 29; else return 28; } return 30; } void handleMouse() { // To detect if the mouse clic on the dates, months, or year sliders if(!allYears){ if (mouseY > yYearPos && mouseY < yearSelectorY+yYearPos && mouseX > 100 + yearSelectorX && mouseX < 100 + yearSelectorX + yearCount*8 ) { int year = (mouseX - (yearSelectorX + 100)) / 8; setYear(constrain(year, minYearIndex, maxYearIndex)); if (!showByDay && !showByMonth) setCurrentDates("Jan/01/"+yearLabel[yearIndex],"Dec/31/"+yearLabel[yearIndex]); else if (showByMonth) setCurrentDates(monthLabel[monthIndex].substring(0,3)+"/01/"+yearLabel[yearIndex], monthLabel[monthIndex].substring(0,3)+"/"+getLastDayXMonth(yearLabel[yearIndex],monthLabel[monthIndex])+"/"+yearLabel[yearIndex]); else if (showByDay) setCurrentDates(dateLabel[dateIndex]+" 12:00 AM",dateLabel[dateIndex]+" 11:00 PM"); } if (showByMonth){ if (mouseY > yMonthPos && mouseY < monthSelectorY+yMonthPos && mouseX> 100+monthSelectorX && mouseX < 100+monthSelectorX + monthCount*5) { int date = (mouseX - (monthSelectorX + 100)) / 5; setMonth(constrain(date, 0, monthCount -1)); setCurrentDates(monthLabel[monthIndex].substring(0,3)+"/01/"+yearLabel[yearIndex],monthLabel[monthIndex].substring(0,3)+"/"+getLastDayXMonth(yearLabel[yearIndex],monthLabel[monthIndex])+"/"+yearLabel[yearIndex]); } } if (showByDay){ if (mouseY > yDatePos && mouseY < dateSelectorY+yDatePos && mouseX> 100+dateSelectorX && mouseX < 100+dateSelectorX + dateCount*2) { int date = (mouseX - (dateSelectorX + 100)) / 2; setDate(constrain(date, 0, dateCount -1)); setCurrentDates(dateLabel[dateIndex]+" 12:00 AM",dateLabel[dateIndex]+" 11:00 PM"); } } } // detect if mouse is press over the button save predictions. only to change color if (showByMonth){ if (yearIndex == (yearCount - 1) && (monthIndex >= maxMonthIndex)){ if (mouseX > 110+monthSelectorX + monthCount*5 && mouseY > yMonthPos - 5 && mouseX < 110+monthSelectorX + monthCount*5 + BUTTON_W+35 && mouseY < yMonthPos - 5 + BUTTON_H) savePredictions = true; } } } void keyPressed() { int tmpRoom = currentRoom; if (key == CODED) { if (keyCode == LEFT) { tmpRoom--; if(tmpRoom < 0) setCurrentRoom(data.getColumnCount() - 1); else setCurrentRoom(tmpRoom); } else if (keyCode == RIGHT) { tmpRoom++; if (tmpRoom == data.getColumnCount()) setCurrentRoom(0); else setCurrentRoom(tmpRoom); } } println(currentRoom); } void setCurrentRoom(int _room){ currentRoom = _room; redraw(); /*if (currentRoom >= 0){ for (int row = 0; row < data.getRowCount(); row++){ interpolators[row].target(data.getFloat(row,currentRoom)); } }*/ } Date getDateFromMillis(long _date){ Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(_date); return calendar.getTime(); } void setCurrentDates(String _dateMin,String _dateMax){ try{ println("String " + _dateMin + " " + _dateMax); //Set the current max and min dates in the graph (in terms of index in the array) plotMinDate = (readingDateFormat.parse(_dateMin +" 12:00 AM")).getTime(); if (showByDay) plotMaxDate = (readingDateFormat.parse(_dateMax +" 11:00 PM")).getTime(); else plotMaxDate = (readingDateFormat.parse(_dateMax +" 12:00 AM")).getTime(); currentDateMax = (int)data.getRowMaxIndex(_dateMax); currentDateMin = (int)data.getRowMinIndex(_dateMin); println("new index" + currentDateMax + " " + currentDateMin); // redraw(); } catch (ParseException e) { die("Problem while setting up dates", e); } } void setCurrentDates(long _dateMin,long _dateMax){ println("Long "+readingDateFormat.format(getDateFromMillis(_dateMin)) + " "+readingDateFormat.format(getDateFromMillis(_dateMax))); //Set the current max and min dates in the graph (in terms of index in the array) currentDateMax = (int)data.getRowMaxIndex(_dateMax); currentDateMin = (int)data.getRowMinIndex(_dateMin); plotMinDate = _dateMin; plotMaxDate = _dateMax; } void drawRooms(){ rectMode(CORNERS); noStroke(); //Room 1 - Meeting room fill(roomColor[0],transpActive(0)); rect(imageX+147, imageY+15, imageX+246, imageY+72); //Roon 2 - Main Lab fill(roomColor[1],transpActive(1)); rect (imageX+265,imageY+15,imageX+349,imageY+108); //Room 3 - Machine room fill(roomColor[2],transpActive(2)); rect (imageX+253,imageY+114,imageX+349,imageY+157); //Room 4 - Lounge fill(roomColor[3],transpActive(3)); rect (imageX+199,imageY+99,imageX+247,imageY+155); //Room 5 - Prototype space fill(roomColor[4],transpActive(4)); rect (imageX+148,imageY+99,imageX+193,imageY+155); //Room 6 - Classroom fill(roomColor[5],transpActive(5)); rect (imageX+42,imageY+99,imageX+141,imageY+155); //Room 7 - office space fill(roomColor[6],transpActive(6)); rect (imageX+42,imageY+15,imageX+143,imageY+72); } //set the transparency value for the rooms int transpActive(int _room){ if (_room == currentRoom) return 255; else return 40; } void savePredictions(int _monthIndex, int _yearIndex){ data.savePredictions((_monthIndex+1),yearLabel[_yearIndex]); //as months are in order, the index+1 correspond to its order in the year }