Sets timeMin and timeMax parsed by stampFormat / void setDateRange(String startDate, String endDate) { if (startDate == null) startDate = times[0]; if (endDate == null) endDate = times[times.length - 1]; try { Date firstDate = stampFormat.parse(startDate); Date lastDate = stampFormat.parse(endDate); timeMin = (long)(firstDate.getTime());// / MILIS_PER_MIN); timeMax = (long)(lastDate.getTime() /*/ MILIS_PER_MIN*/ + 1); //println(timeMin + " " + timeMax); rowMin = 0; while (startDate.compareTo (times[rowMin]) > 0) rowMin++; rowMax = rowCount-1; while (times[rowMax].compareTo (endDate) > 0 ) rowMax--; } catch (ParseException e) { die("Problem while setting up dates", e); } catch (Exception e) { die("Problem while setting up dates", e); } } void showChicagoTemperature() { loadChicagoTemperature(); beginShape(); int hr, month=-1, day=-1, dataCount = 0, year=-1; int yr = 2005; float temp = 0, t=0, x=0, y=0; long time = 0, lastTime = 0; fill(225); textSize(13); text("Chicago", plotX2 - 170, plotY1 + 15); noFill(); strokeWeight(2); stroke(224); //if (chkMonthView.checked || chkAvg[2].checked) strokeWeight(3); // bolder lines line(plotX2 - 140, plotY1 + 15, plotX2 - 120, plotY1 + 15); if (chkMonthView.checked) { for (int i =yearOptions.length-1; i>=0; i--) if (yearOptions[i].selected) { yr += i; break; // draw only for latest year } timeMin = new Date(yr - 1900, selectedMonth, 1).getTime(); timeMax = new Date(yr - 1900, selectedMonth, daysOfMonth, 23, 59).getTime(); } for (int i = 0; i < chicagoDates.length; i++) { time = chicagoDates[i].getTime(); if (time < timeMin || time > timeMax) continue; if (chicagoTempData.isValid(i, 0)) { hr = chicagoDates[i].getHours() ; //println(dayHourLow + " " + hr + " " + dayHourHigh); if (hr < dayHourLow || hr > dayHourHigh) continue; float value = chicagoTempData.getFloat(i, 0); if (value > dataMax) continue; // consider them error if (chkAvg[1].checked) // get daily average { // 1 - 31 if (day != chicagoDates[i].getDate()) // new day beginning { t = value; if (dataCount > 0) // 0 for firsttime, other times plot previous { Date d = new Date(chicagoDates[i].getYear(), month, day); time = d.getTime(); value = temp / dataCount; } dataCount = 1; temp = t; day = chicagoDates[i].getDate(); month = chicagoDates[i].getMonth(); if (time == 0) continue; } else { lastTime = time; temp += value; dataCount++; continue; } } else if (chkAvg[2].checked) // get monthly average { // 0 - 11 if (month != chicagoDates[i].getMonth()) // new day beginning { t = value; if (dataCount > 0) // 0 for firsttime, other times plot previous { Date d = new Date(year, month, getDaysOfMonth(month));//day, 23, 59); time = d.getTime(); value = temp / dataCount; } dataCount = 1; temp = t; year = chicagoDates[i].getYear(); month =chicagoDates[i].getMonth(); if (time == 0) continue; // first time starting with a new date } else { lastTime = time; temp += value; dataCount++; continue; } } else { // normally calcuate time time = chicagoDates[i].getTime();// / MILIS_PER_MIN; } if (value < dataMin) value = dataMin; // clip; continue skips x axis x = map(time, timeMin, timeMax, plotX1, plotX2); y = map(value, dataMin, dataMax, plotY2, plotY1); vertex(x, y); } } if (lastTime != 0) // so date aggregation used, plot the last point, it is not ploted as date has not changed past it. { if (temp/dataCount < dataMin) temp = dataMin*dataCount; // clip; continue skips x axis x = map(lastTime, timeMin, timeMax, plotX1, plotX2); y = map(temp/dataCount, dataMin, dataMax, plotY2, plotY1); vertex(x, y); } endShape(); } void loadChicagoTemperature() // separated to save starting time { if (chicagoTempData != null) return; println("loading chicago temparature..."); //chicago outdoor temp chicagoTempData = new FloatTable("chicagotemp.txt"); String[] ctd_titles = chicagoTempData.getRowNames(); chicagoDates = new Date[ctd_titles.length]; try { for (int i=0; i < ctd_titles.length; i++) { chicagoDates[i] = stampFormat.parse(ctd_titles[i]);//.getTime() ; // / MILIS_PER_MIN; } } catch (ParseException e) { die("Problem while setting up dates", e); } } // sliders void drawSliders() { sliderHoursOfDay.update(); sliderHoursOfDay.display(); fill(#FFFFFF); textSize(13); textLeading(10); textAlign(LEFT, TOP);//, CENTER); text("Hours", sliderHoursOfDay.x-38, sliderHoursOfDay.y); // } /// check boxes void drawCheckBoxes() { chkMultipleRooms.display(); fill(#FFFFFF); textSize(13); textLeading(10); textAlign(LEFT, TOP);//, CENTER); text("Multiple Rooms", chkMultipleRooms.x+15, chkMultipleRooms.y); // chkOutdoor.display(); text("Compare Outdoor", chkOutdoor.x+15, chkOutdoor.y); // chkMonthView.display(); text("Month View", chkMonthView.x+15, chkMonthView.y); chkAvg[0].display(); text("No Average", chkAvg[0].x+15, chkAvg[0].y); chkAvg[1].display(); text("Daily Average", chkAvg[1].x+15, chkAvg[1].y); chkAvg[2].display(); text("Monthly Average", chkAvg[2].x+15, chkAvg[2].y); chkF_C[0].display(); chkF_C[1].display(); text("F", chkF_C[0].x+15, chkF_C[0].y); // text("C", chkF_C[1].x+15, chkF_C[1].y); // textAlign(CENTER); text("Temperature", chkF_C[0].x + 13, chkF_C[0].y - 10); } /// label options void drawOptionLabels() { for (int i=0; i=0; i--) { if (i ==7) fill(#1F1F1F); // boundary else if ((chkMultipleRooms.checked && visibleColumns[i]) || (!chkMultipleRooms.checked && currentColumn == i) ) fill(color_room[i]); else fill(color_room_inactive); rect(roomX1[i], roomY1[i], roomX2[i], roomY2[i]); fill(#F0F0F0); textFont(plotFont); textSize(13); textLeading(15); textAlign(CENTER, CENTER); String title = ""; switch(i) { case 0: title = "meeting room"; break; case 1: title = "main lab"; break; case 2: title = "machine room"; break; case 3: title = "lounge"; break; case 4: title = "proto-\ntype\nspace"; break; case 5: title = "class room"; break; case 6: title = "office"; break; } text(title, (roomX1[i]+roomX2[i])/2, (roomY1[i]+roomY2[i])/2); } } /////////////////////////// void loadData() { dates = new Date[times.length]; try { for (int i=0; i

Source code: evl_temp_history Classes FloatTable

Built with Processing