Skip to content
Browse files

Version 3

Multi-house data set capability, new water usage screen
  • Loading branch information...
1 parent 4926e46 commit 82205490e774c15f19e38641442a6833255e871e Larry committed Jan 7, 2013
View
7 README.md
@@ -7,6 +7,13 @@ This app utilizes MySQL, PHP, jQuery, HighCharts and Javascript to view home ene
Working version posted at http://netplusdesign.com/home_performance/monthly.html
+Version 3
+Jan 7, 2013
+
+- Updates to data structure to enable multiple house data sets.
+- New Water usage screen. Calculates watts per gallon of hot water and watts per gallon water pumped (if you have a well and record well power usage.)
+- Other sql bug fixes.
+
Version 2
Dec 30, 2012
View
10 daily.html
@@ -24,6 +24,7 @@
<option value="16">Generation</option>
<option value="17">Usage</option>
<option value="18">Heating Degree Days</option>
+ <option value="20">Water Usage</option>
<option value="19">Base Temp Analysis</option>
</optgroup>
<optgroup label="Daily">
@@ -59,7 +60,7 @@
<div id="chart">Building chart... </div>
<footer>
<p id="instructions">Turn device to toggle between calendar and chart view.</p>
- <p>&copy; netplusdesign 2012</p>
+ <p>&copy; netplusdesign 2012-2013</p>
</footer>
</div>
<script src="js/jquery-1.7.1.min.js"></script>
@@ -92,6 +93,7 @@
}(document));
// global variables
+ var houseId = 0;
var chart = null;
var today, setDay;
var validDateRanges = []; // for base data (0-1) and circuit data (2-3)
@@ -151,7 +153,7 @@
setupCalendar(); // integrate with redraw at some point in future
// get initializing variables
- $.get('get_daily_metadata.php', function(data)
+ $.get('get_daily_metadata.php?house='+houseId, function(data)
{
var lines = data.split('\n'); // splits the file into lines
$.each(lines, function(lineNo, line)
@@ -561,12 +563,12 @@
function getMonthFilename( d )
{
//return "data/" + formatAddZero( (d.getMonth()+1).toString() ) + "-" + d.getFullYear() + "-day-data.csv";
- return "get_daily_data.php?date=" + today.getFullYear() + "-" + formatAddZero( (today.getMonth()+1).toString() ) + "-" + formatAddZero( today.getDate().toString() );
+ return "get_daily_data.php?house=" + houseId + "&date=" + today.getFullYear() + "-" + formatAddZero( (today.getMonth()+1).toString() ) + "-" + formatAddZero( today.getDate().toString() );
}
function getDayFilename( d )
{
- return "get_hourly_data.php?date=" + today.getFullYear() + "-" + formatAddZero( (today.getMonth()+1).toString() ) + "-" + formatAddZero( today.getDate().toString() );
+ return "get_hourly_data.php?house=" + houseId + "&date=" + today.getFullYear() + "-" + formatAddZero( (today.getMonth()+1).toString() ) + "-" + formatAddZero( today.getDate().toString() );
}
function formatAddZero( d )
View
21 get_daily_data.php
@@ -8,28 +8,31 @@
exit();
}
- if (isset($_GET['date']))
+ if ( (isset($_GET['date'])) && isset($_GET['house']) )
{
$date = get_post($link, 'date');
date_default_timezone_set('America/New_York');
+ $house = get_post($link, 'house');
/*
SELECT tu.date, e.adjusted_load, e.solar, e.used, tu.outdoor_deg_min, tu.outdoor_deg_max, th.hdd, e.water_heater, e.ashp, e.water_pump, e.dryer, e.washer, e.dishwasher, e.stove
- FROM (SELECT date, temperature_min AS 'outdoor_deg_min', temperature_max AS 'outdoor_deg_max' FROM temperature_daily WHERE device_id = 0) tu
- LEFT JOIN (SELECT date, hdd FROM hdd_daily) th ON (th.date = tu.date)
- LEFT JOIN energy_daily e ON (e.date = tu.date)
- WHERE YEAR(tu.date) = 2012
+ FROM (SELECT house_id, date, temperature_min AS 'outdoor_deg_min', temperature_max AS 'outdoor_deg_max' FROM temperature_daily WHERE device_id = 0) tu
+ LEFT JOIN (SELECT house_id, date, hdd FROM hdd_daily) th ON th.date = tu.date AND th.house_id = tu.house_id
+ LEFT JOIN energy_daily e ON e.date = tu.date AND e.house_id = tu.house_id
+ WHERE tu.house_id = 0
+ AND YEAR(tu.date) = 2012
AND MONTH(tu.date) = 3;
* */
$query = "SELECT tu.date, e.adjusted_load, e.solar, e.used, ";
$query .= "tu.outdoor_deg_min, tu.outdoor_deg_max, th.hdd, ";
$query .= "e.water_heater, e.ashp, e.water_pump, e.dryer, e.washer, e.dishwasher, e.stove, ";
$query .= "e.used-(e.water_heater+e.ashp+e.water_pump+e.dryer+e.washer+e.dishwasher+e.stove) AS 'All other circuits' ";
- $query .= "FROM (SELECT date, temperature_min AS 'outdoor_deg_min', temperature_max AS 'outdoor_deg_max' FROM temperature_daily WHERE device_id = 0) tu ";
- $query .= "LEFT JOIN (SELECT date, hdd FROM hdd_daily) th ON (th.date = tu.date) ";
- $query .= "LEFT JOIN energy_daily e ON (e.date = tu.date) ";
- $query .= "WHERE YEAR(tu.date) = " . date_format(date_create($date), 'Y') . " ";
+ $query .= "FROM (SELECT house_id, date, temperature_min AS 'outdoor_deg_min', temperature_max AS 'outdoor_deg_max' FROM temperature_daily WHERE device_id = 0) tu ";
+ $query .= "LEFT JOIN (SELECT house_id, date, hdd FROM hdd_daily) th ON th.date = tu.date AND th.house_id = tu.house_id ";
+ $query .= "LEFT JOIN energy_daily e ON e.date = tu.date AND e.house_id = tu.house_id ";
+ $query .= "WHERE tu.house_id = $house ";
+ $query .= "AND YEAR(tu.date) = " . date_format(date_create($date), 'Y') . " ";
$query .= "AND MONTH(tu.date) = " . date_format(date_create($date), 'm');
if ($result = mysqli_query($link, $query))
View
76 get_daily_metadata.php
@@ -8,31 +8,65 @@
exit();
}
- $query = "SELECT MIN(e.date), MAX(e.date) FROM energy_daily e, temperature_daily t where e.date = t.date UNION SELECT MIN(e.date), MAX(e.date) FROM energy_daily e, temperature_daily t WHERE e.date = t.date AND water_heater IS NOT NULL;";
- $query .= "SELECT used_max, solar_min, outdoor_deg_min, outdoor_deg_max, hdd_max FROM limits_hourly;";
-
- if ($result = mysqli_multi_query($link, $query))
+ if ( isset($_GET['house'] ) )
{
- do
+ $house = get_post($link, 'house');
+
+ /*
+ SELECT MIN(e.date), MAX(e.date)
+ FROM energy_daily e, temperature_daily t
+ WHERE e.house_id = 0
+ AND e.date = t.date
+ UNION
+ SELECT MIN(e.date), MAX(e.date)
+ FROM energy_daily e, temperature_daily t
+ WHERE e.house_id = 0
+ AND e.date = t.date
+ AND water_heater IS NOT NULL;
+ * */
+ $query = "SELECT MIN(e.date), MAX(e.date) FROM energy_daily e, temperature_daily t WHERE e.house_id = $house AND e.date = t.date UNION SELECT MIN(e.date), MAX(e.date) FROM energy_daily e, temperature_daily t WHERE e.house_id = $house AND e.date = t.date AND water_heater IS NOT NULL;";
+
+ /*
+ SELECT used_max, solar_min, outdoor_deg_min, outdoor_deg_max, hdd_max
+ FROM limits_hourly
+ WHERE house_id = 0;
+ * */
+ $query .= "SELECT used_max, solar_min, outdoor_deg_min, outdoor_deg_max, hdd_max FROM limits_hourly WHERE house_id = $house;";
+
+ if ($result = mysqli_multi_query($link, $query))
{
- if ($result = mysqli_store_result($link))
+ do
{
- switch($j++)
+ if ($result = mysqli_store_result($link))
{
- case(0):
- $row = mysqli_fetch_row($result);
- echo $row[0] . "," . $row[1] . ",";
- $row = mysqli_fetch_row($result);
- echo $row[0] . "," . $row[1] . "\r\n";
- break;
- case(1):
- $row = mysqli_fetch_row($result);
- echo $row[0] . "," . $row[1] . "," . $row[2] . "," . $row[3] . "," . $row[4] . "\r\n";
+ switch($j++)
+ {
+ case(0):
+ $row = mysqli_fetch_row($result);
+ echo $row[0] . "," . $row[1] . ",";
+ $row = mysqli_fetch_row($result);
+ echo $row[0] . "," . $row[1] . "\r\n";
+ break;
+ case(1):
+ $row = mysqli_fetch_row($result);
+ echo $row[0] . "," . $row[1] . "," . $row[2] . "," . $row[3] . "," . $row[4] . "\r\n";
+ }
+ mysqli_free_result($result);
}
- mysqli_free_result($result);
- }
- } while (mysqli_next_result($link));
- }
+ } while (mysqli_next_result($link));
+ }
- mysqli_close($link);
+ mysqli_close($link);
+ }
+ else
+ {
+ echo "not";
+ }
+
+ function get_post($link, $var)
+ {
+ $temp = mysqli_real_escape_string($link, $_GET[$var]);
+ if ($temp == '') $temp = 'NULL';
+ return $temp;
+ }
?>
View
62 get_hdd_ashp.php
@@ -8,57 +8,69 @@
exit();
}
- if (isset($_GET['base']) && isset($_GET['period']))
+ if (isset($_GET['base']) && isset($_GET['period']) && isset($_GET['house']))
{
$base = get_post($link, 'base');
$period = get_post($link, 'period');
+ $house = get_post($link, 'house');
}
else
{
- // default
- $base = 65.0;
- $period = "hours";
+ echo "failed";
}
/*
- SELECT (54.0 - t.temperature) * 1 / 24 AS 'hdd', e.ashp/1000.0, e.date
- FROM energy_hourly e, (SELECT date, temperature FROM temperature_hourly WHERE device_id = 0) t
- WHERE e.date = t.date
+ SELECT (54.0 - t.temperature) * 1 / 24 AS 'hdd', e.ashp/1000.0, t.temperature, e.date
+ FROM energy_hourly e, (SELECT house_id, date, temperature FROM temperature_hourly WHERE device_id = 0) t
+ WHERE e.house_id = 0
+ AND e.house_id = t.house_id
+ AND e.date = t.date
AND t.temperature < 54
AND e.ashp > 0;
* */
// hourly
- $query['hours'] = "SELECT ($base - t.temperature) * (1 / 24) AS 'hdd', e.ashp/1000.0, e.date ";
- $query['hours'] .= "FROM energy_hourly e, (SELECT date, temperature FROM temperature_hourly WHERE device_id = 0) t ";
- $query['hours'] .= "WHERE e.date = t.date ";
+ $query['hours'] = "SELECT ($base - t.temperature) * (1 / 24) AS 'hdd', e.ashp/1000.0, t.temperature, e.date ";
+ $query['hours'] .= "FROM energy_hourly e, (SELECT house_id, date, temperature FROM temperature_hourly WHERE device_id = 0) t ";
+ $query['hours'] .= "WHERE e.house_id = $house ";
+ $query['hours'] .= "AND e.house_id = t.house_id ";
+ $query['hours'] .= "AND e.date = t.date ";
$query['hours'] .= "AND t.temperature < $base ";
$query['hours'] .= "AND e.ashp > 0";
-
/*
- SELECT e.date, SUM(e.ashp)/1000.0, SUM(t.hdd)
- FROM (SELECT date, IF(((68 - temperature) * 1 / 24) > 0, (68 - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e
- WHERE t.date = e.date
+ SELECT SUM(t.hdd), SUM(e.ashp)/1000.0, t.temperature, e.date
+ FROM (SELECT house_id, date, temperature, IF(((68 - temperature) * 1 / 24) > 0, (68 - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e
+ WHERE e.house_id = 0
+ AND t.house_id = e.house_id
+ AND t.date = e.date
AND CAST(e.date AS DATE) = ANY (SELECT e.date FROM energy_daily e, temperature_daily t WHERE t.device_id = 0 AND e.date = t.date AND t.temperature_min <= 68 AND e.ashp > 0)
GROUP BY CAST(t.date AS DATE);
* */
// daily
- $query['days'] = "SELECT SUM(t.hdd), SUM(e.ashp)/1000.0, e.date ";
- $query['days'] .= "FROM (SELECT date, IF((($base - temperature) * 1 / 24) > 0, ($base - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e ";
- $query['days'] .= "WHERE t.date = e.date ";
+ $query['days'] = "SELECT SUM(t.hdd), SUM(e.ashp)/1000.0, t.temperature, e.date ";
+ $query['days'] .= "FROM (SELECT house_id, date, temperature, IF((($base - temperature) * 1 / 24) > 0, ($base - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e ";
+ $query['days'] .= "WHERE e.house_id = $house ";
+ $query['days'] .= "AND t.house_id = e.house_id ";
+ $query['days'] .= "AND t.date = e.date ";
$query['days'] .= "AND CAST(e.date AS DATE) = ANY (SELECT e.date FROM energy_daily e, temperature_daily t WHERE t.device_id = 0 AND e.date = t.date AND t.temperature_min <= $base AND e.ashp > 0) ";
$query['days'] .= "GROUP BY CAST(t.date AS DATE)";
/*
- SELECT e.date, SUM(e.ashp)/1000.0, SUM(t.hdd)
- FROM (SELECT date, IF(((68 - temperature) * 1 / 24) > 0, (68 - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e
- WHERE t.date = e.date
- AND e.date > DATE('2012-03-15') AND ( MONTH(e.date) < 6 OR MONTH(e.date) > 8 )
+ SELECT SUM(t.hdd), SUM(e.ashp)/1000.0, t.temperature, e.date
+ FROM (SELECT house_id, date, temperature, IF(((68 - temperature) * 1 / 24) > 0, (68 - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e
+ WHERE e.house_id = 0
+ AND t.house_id = e.house_id
+ AND t.date = e.date
+ AND e.date > DATE('2012-03-15')
+ AND ( MONTH(e.date) < 6
+ OR MONTH(e.date) > 8 )
GROUP BY MONTH(t.date);
*/
// monthly
- $query['months'] = "SELECT SUM(t.hdd), SUM(e.ashp)/1000.0, e.date ";
- $query['months'] .= "FROM (SELECT date, IF((($base - temperature) * 1 / 24) > 0, ($base - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e ";
- $query['months'] .= "WHERE t.date = e.date ";
+ $query['months'] = "SELECT SUM(t.hdd), SUM(e.ashp)/1000.0, t.temperature, e.date ";
+ $query['months'] .= "FROM (SELECT house_id, date, temperature, IF((($base - temperature) * 1 / 24) > 0, ($base - temperature) * 1 / 24, 0) AS 'hdd' FROM temperature_hourly WHERE device_id = 0) t, energy_hourly e ";
+ $query['months'] .= "WHERE e.house_id = $house ";
+ $query['months'] .= "AND t.house_id = e.house_id ";
+ $query['months'] .= "AND t.date = e.date ";
$query['months'] .= "AND e.date > DATE('2012-03-15') ";
$query['months'] .= "AND (MONTH(e.date) < 6 ";
$query['months'] .= "OR MONTH(e.date) > 8) ";
@@ -68,7 +80,7 @@
{
while ($row = mysqli_fetch_row($result))
{
- echo $row[0] . "," . $row[1] . "," . $row[2] . "\r\n";
+ echo $row[0] . "," . $row[1] . "," . $row[2] . "," . $row[3] . "\r\n";
}
mysqli_free_result($result);
}
View
29 get_hourly_data.php
@@ -7,30 +7,33 @@
exit();
}
- if (isset($_GET['date']))
+ if (isset($_GET['date']) && isset($_GET['house']))
{
$date = get_post($link, 'date');
date_default_timezone_set('America/New_York');
+ $house = get_post($link, 'house');
/*
- SELECT ti.date, e.adjusted_load, ti.indoor_deg, tu.outdoor_deg, th.hdd, e.water_heater, e.ashp, e.water_pump, e.dryer, e.washer, e.dishwasher, e.stove,
- e.used-(e.water_heater+e.ashp+e.water_pump+e.dryer+e.washer+e.dishwasher+e.stove) AS 'All other circuits'
- FROM (SELECT date, temperature AS 'indoor_deg' FROM temperature_hourly WHERE device_id = 1) ti
- LEFT JOIN (SELECT date, temperature AS 'outdoor_deg' FROM temperature_hourly WHERE device_id = 0) tu ON (tu.date = ti.date)
- LEFT JOIN (SELECT date, hdd FROM hdd_hourly) th ON (th.date = ti.date)
- LEFT JOIN energy_hourly e ON (e.date = ti.date)
- WHERE CAST(ti.date AS DATE) = DATE('2012-03-12');
+SELECT ti.date, e.adjusted_load, ti.indoor_deg, tu.outdoor_deg, th.hdd, e.water_heater, e.ashp, e.water_pump, e.dryer, e.washer, e.dishwasher, e.stove,
+ e.used-(e.water_heater+e.ashp+e.water_pump+e.dryer+e.washer+e.dishwasher+e.stove) AS 'All other circuits'
+FROM (SELECT house_id, date, temperature AS 'indoor_deg' FROM temperature_hourly WHERE device_id = 1) ti
+ LEFT JOIN (SELECT house_id, date, temperature AS 'outdoor_deg' FROM temperature_hourly WHERE device_id = 0) tu ON tu.date = ti.date AND tu.house_id = ti.house_id
+ LEFT JOIN (SELECT house_id, date, hdd FROM hdd_hourly) th ON th.date = ti.date AND th.house_id = ti.house_id
+ LEFT JOIN energy_hourly e ON e.date = ti.date AND e.house_id = ti.house_id
+WHERE CAST(ti.date AS DATE) = DATE('2012-03-12')
+ AND ti.house_id = 0;
* */
$query = "SELECT ti.date, e.adjusted_load, e.solar, e.used, ";
$query .= "ti.indoor_deg, tu.outdoor_deg, th.hdd, ";
$query .= "e.water_heater, e.ashp, e.water_pump, e.dryer, e.washer, e.dishwasher, e.stove, ";
$query .= "e.used-(e.water_heater+e.ashp+e.water_pump+e.dryer+e.washer+e.dishwasher+e.stove) AS 'All other' ";
- $query .= "FROM (SELECT date, temperature AS 'indoor_deg' FROM temperature_hourly WHERE device_id = 1) ti ";
- $query .= "LEFT JOIN (SELECT date, temperature AS 'outdoor_deg' FROM temperature_hourly WHERE device_id = 0) tu ON (tu.date = ti.date) ";
- $query .= "LEFT JOIN (SELECT date, hdd FROM hdd_hourly) th ON (th.date = ti.date) ";
- $query .= "LEFT JOIN energy_hourly e ON (e.date = ti.date) ";
- $query .= "WHERE CAST(ti.date AS DATE) = DATE('" . date_format(date_create($date), 'Y-m-d') . "')";
+ $query .= "FROM (SELECT house_id, date, temperature AS 'indoor_deg' FROM temperature_hourly WHERE device_id = 1) ti ";
+ $query .= "LEFT JOIN (SELECT house_id, date, temperature AS 'outdoor_deg' FROM temperature_hourly WHERE device_id = 0) tu ON tu.date = ti.date AND tu.house_id = ti.house_id ";
+ $query .= "LEFT JOIN (SELECT house_id, date, hdd FROM hdd_hourly) th ON th.date = ti.date AND th.house_id = ti.house_id ";
+ $query .= "LEFT JOIN energy_hourly e ON e.date = ti.date AND e.house_id = ti.house_id ";
+ $query .= "WHERE CAST(ti.date AS DATE) = DATE('" . date_format(date_create($date), 'Y-m-d') . "') ";
+ $query .= "AND ti.house_id = $house;";
if ($result = mysqli_query($link, $query))
{
View
34 get_monthly_generation.php
@@ -10,39 +10,41 @@
}
date_default_timezone_set('America/New_York');
- if (isset($_GET['date']))
+ if (isset($_GET['date']) && isset($_GET['house']))
{
$date = get_post($link, 'date');
$year = date_format(date_create($date), 'Y');
+ $house = get_post($link, 'house');
}
else
{
- $year = '2012'; // default
+ echo "failed";
}
// 0) total generated
- $query .= "SELECT SUM(solar) FROM energy_monthly;";
+ $query .= "SELECT SUM(solar) FROM energy_monthly WHERE house_id = $house;";
// 1 and 2) max solar hour and day
- $query .= "SELECT solar, date FROM energy_hourly WHERE solar = (SELECT MIN(solar) FROM energy_hourly);";
- $query .= "SELECT solar, date FROM energy_daily WHERE solar = (SELECT MIN(solar) FROM energy_daily);";
+ $query .= "SELECT solar, date FROM energy_hourly WHERE solar = (SELECT MIN(solar) FROM energy_hourly) AND house_id = 0;";
+ $query .= "SELECT solar, date FROM energy_daily WHERE solar = (SELECT MIN(solar) FROM energy_daily) AND house_id = 0;";
// 3 and 4) list by month
/*
SELECT SUM(en.solar), SUM(es.solar)
FROM energy_monthly en
- LEFT JOIN estimated_monthly es ON en.date = es.date
- WHERE YEAR(en.date) = 2012
- ORDER BY en.date;
+ LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id
+ WHERE en.house_id = 0
+ AND YEAR(en.date) = 2012;
* */
- $query .= "SELECT SUM(en.solar), SUM(es.solar) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date WHERE YEAR(en.date) = $year ORDER BY en.date;";
+ $query .= "SELECT SUM(en.solar), SUM(es.solar) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id WHERE en.house_id = $house AND YEAR(en.date) = $year;";
/*
- SELECT en.date, SUM(en.solar), SUM(es.solar)
- FROM energy_monthly en
- LEFT JOIN estimated_monthly es ON en.date = es.date
- WHERE YEAR(en.date) = 2012
- GROUP BY MONTH(en.date)
- ORDER BY en.date;
+SELECT en.date, SUM(en.solar), SUM(es.solar)
+FROM energy_monthly en
+ LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id
+WHERE en.house_id = 0
+ AND YEAR(en.date) = 2012
+GROUP BY MONTH(en.date)
+ORDER BY en.date;
* */
- $query .= "SELECT en.date, SUM(en.solar), SUM(es.solar) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date WHERE YEAR(en.date) = $year GROUP BY MONTH(en.date) ORDER BY en.date";
+ $query .= "SELECT en.date, SUM(en.solar), SUM(es.solar) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id WHERE en.house_id = $house AND YEAR(en.date) = $year GROUP BY MONTH(en.date) ORDER BY en.date;";
$output = array(
"max_solar_hour" => array(),
View
60 get_monthly_hdd.php
@@ -10,58 +10,72 @@
}
date_default_timezone_set('America/New_York');
- if (isset($_GET['date']))
+ if (isset($_GET['date']) && isset($_GET['house']))
{
$date = get_post($link, 'date');
$year = date_format(date_create($date), 'Y');
+ $house = get_post($link, 'house');
}
else
{
- $year = '2012'; // default
+ echo "failed";
}
/*
- SELECT t.hdd, e.ashp
- FROM (SELECT date, SUM(hdd) AS 'hdd' FROM hdd_monthly WHERE YEAR(date) = 2012) t,
- (SELECT date, SUM(ashp) AS 'ashp' FROM energy_monthly WHERE YEAR(date) = 2012 AND date < DATE('2012-05-21') OR date > DATE('2012-09-21')) e;
+SELECT t.hdd, e.ashp
+FROM (SELECT SUM(hdd) AS 'hdd' FROM hdd_daily WHERE house_id = 0 AND YEAR(date) = 2012 AND date > DATE('2012-03-15')) t,
+ (SELECT SUM(ashp) AS 'ashp' FROM energy_monthly WHERE house_id = 0 AND YEAR(date) = 2012 AND (date < DATE('2012-05-21') OR date > DATE('2012-09-21'))) e;
* */
// 0) returns total HDD and total kWh used in heating season
- $query .= "SELECT t.hdd, e.ashp FROM (SELECT date, SUM(hdd) AS 'hdd' FROM hdd_monthly WHERE YEAR(date) = $year) t, (SELECT date, SUM(ashp) AS 'ashp' FROM energy_monthly WHERE YEAR(date) = $year AND date < DATE('$year-05-21') OR date > DATE('$year-09-21')) e;";
+ if ($year == 2012)
+ {
+ $query = "SELECT t.hdd, e.ashp FROM (SELECT SUM(hdd) AS 'hdd' FROM hdd_daily WHERE house_id = $house AND YEAR(date) = $year AND date > DATE('2012-03-15')) t, (SELECT SUM(ashp) AS 'ashp' FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND (date < DATE('$year-05-21') OR date > DATE('$year-09-21'))) e;";
+ }
+ else
+ {
+ $query = "SELECT t.hdd, e.ashp FROM (SELECT SUM(hdd) AS 'hdd' FROM hdd_monthly WHERE house_id = $house AND YEAR(date) = $year) t, (SELECT SUM(ashp) AS 'ashp' FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND (date < DATE('$year-05-21') OR date > DATE('$year-09-21'))) e;";
+ }
// 1 and 2) coldest temp and date, coldest day hdd and date
/*
- * 1) SELECT temperature, date FROM temperature_hourly where temperature = (SELECT MIN(temperature) FROM temperature_hourly WHERE YEAR(date) = 2012);
- * 2) SELECT hdd, date FROM hdd_daily WHERE hdd = (SELECT MAX(hdd) FROM hdd_daily WHERE YEAR(date) = 2012);
+ * 1) SELECT temperature, date FROM temperature_hourly WHERE temperature = (SELECT MIN(temperature) FROM temperature_hourly WHERE YEAR(date) = 2012) AND house_id = 0;
+ * 2) SELECT hdd, date FROM hdd_daily WHERE hdd = (SELECT MAX(hdd) FROM hdd_daily WHERE YEAR(date) = 2012) AND house_id = 0;
* */
- $query .= "SELECT temperature, date FROM temperature_hourly where temperature = (SELECT MIN(temperature) FROM temperature_hourly WHERE YEAR(date) = $year);";
- $query .= "SELECT hdd, date FROM hdd_daily WHERE hdd = (SELECT MAX(hdd) FROM hdd_daily WHERE YEAR(date) = $year);";
+ $query .= "SELECT temperature, date FROM temperature_hourly WHERE temperature = (SELECT MIN(temperature) FROM temperature_hourly WHERE YEAR(date) = $year) AND house_id = $house;";
+ $query .= "SELECT hdd, date FROM hdd_daily WHERE hdd = (SELECT MAX(hdd) FROM hdd_daily WHERE YEAR(date) = $year) AND house_id = $house;";
/*
SELECT SUM(td.hdd), SUM(es.hdd)
- FROM (SELECT date, hdd FROM hdd_monthly WHERE YEAR(date) = 2012 AND MONTH(date) < 6 OR MONTH(date) > 8) td,
- (SELECT date, hdd FROM estimated_monthly WHERE YEAR(date) = 2012 AND MONTH(date) < 6 OR MONTH(date) > 8) es
- WHERE td.date = es.date;
+ FROM (SELECT house_id, date, hdd FROM hdd_monthly WHERE YEAR(date) = 2012 AND MONTH(date) < 6 OR MONTH(date) > 8) td,
+ (SELECT house_id, date, hdd FROM estimated_monthly WHERE YEAR(date) = 2012 AND MONTH(date) < 6 OR MONTH(date) > 8) es
+ WHERE td.house_id = 0
+ AND td.house_id = es.house_id
+ AND td.date = es.date;
* */
// 3) total hdd and total estimated hdd during heating season
- $query .= "SELECT SUM(td.hdd), SUM(es.hdd) FROM (SELECT date, hdd FROM hdd_monthly WHERE YEAR(date) = $year AND MONTH(date) < 6 OR MONTH(date) > 8) td, (SELECT date, hdd FROM estimated_monthly WHERE YEAR(date) = $year AND MONTH(date) < 6 OR MONTH(date) > 8) es WHERE td.date = es.date;";
+ $query .= "SELECT SUM(td.hdd), SUM(es.hdd) FROM (SELECT house_id, date, hdd FROM hdd_monthly WHERE YEAR(date) = $year AND MONTH(date) < 6 OR MONTH(date) > 8) td, (SELECT house_id, date, hdd FROM estimated_monthly WHERE YEAR(date) = $year AND MONTH(date) < 6 OR MONTH(date) > 8) es WHERE td.house_id = $house AND td.house_id = es.house_id AND td.date = es.date;";
/*
SELECT SUM(td.hdd), SUM(es.hdd)
FROM hdd_monthly td, estimated_monthly es
- WHERE YEAR(es.date) = 2012
- AND td.date = es.date;
+ WHERE td.house_id = 0
+ AND td.house_id = es.house_id
+ AND td.date = es.date
+ AND YEAR(es.date) = 2012;
* */
// 4) total hdd and total estimated hdd
- $query .= "SELECT SUM(td.hdd), SUM(es.hdd) FROM hdd_monthly td, estimated_monthly es WHERE td.date = es.date AND YEAR(es.date) = $year;";
+ $query .= "SELECT SUM(td.hdd), SUM(es.hdd) FROM hdd_monthly td, estimated_monthly es WHERE td.house_id = $house AND td.house_id = es.house_id AND td.date = es.date AND YEAR(es.date) = $year;";
/*
- SELECT es.date, td.hdd, es.hdd
- FROM hdd_monthly td, estimated_monthly es
- WHERE YEAR(td.date) = 2012
- AND td.date = es.date
- ORDER BY td.date;
+SELECT es.date, td.hdd, es.hdd
+FROM hdd_monthly td, estimated_monthly es
+WHERE td.house_id = 0
+ AND td.house_id = es.house_id
+ AND td.date = es.date
+ AND YEAR(td.date) = 2012
+ORDER BY td.date;
* */
// 5) list by month
- $query .= "SELECT es.date, td.hdd, es.hdd FROM hdd_monthly td, estimated_monthly es WHERE YEAR(td.date) = $year AND td.date = es.date ORDER BY td.date;";
+ $query .= "SELECT es.date, td.hdd, es.hdd FROM hdd_monthly td, estimated_monthly es WHERE td.house_id = $house AND td.house_id = es.house_id AND td.date = es.date AND YEAR(td.date) = $year ORDER BY td.date;";
$output = array(
"coldest_hour" => array(),
View
20 get_monthly_metadata.php
@@ -8,10 +8,19 @@
exit();
}
+ if (isset($_GET['house']))
+ {
+ $house = get_post($link, 'house');
+ }
+ else
+ {
+ echo "failed";
+ }
+
// 0) list of years
- $query = "SELECT YEAR(date) from energy_monthly GROUP BY YEAR(date) ORDER BY date;";
+ $query = "SELECT YEAR(date) FROM energy_monthly WHERE house_id = $house GROUP BY YEAR(date) ORDER BY date;";
// 0) as of date
- $query .= "SELECT date from energy_hourly ORDER BY date DESC LIMIT 1;";
+ $query .= "SELECT date FROM energy_hourly WHERE house_id = $house ORDER BY date DESC LIMIT 1;";
$output = array(
"years" => array()
@@ -52,4 +61,11 @@
mysqli_close($link);
echo json_encode( $output );
+
+ function get_post($link, $var)
+ {
+ $temp = mysqli_real_escape_string($link, $_GET[$var]);
+ if ($temp == '') $temp = 'NULL';
+ return $temp;
+ }
?>
View
19 get_monthly_summary.php
@@ -10,35 +10,38 @@
}
date_default_timezone_set('America/New_York');
- if (isset($_GET['date']))
+ if (isset($_GET['date']) && isset($_GET['house']))
{
$date = get_post($link, 'date');
$year = date_format(date_create($date), 'Y');
+ $house = get_post($link, 'house');
}
else
{
- $year = '2012'; // default
+ echo "failed";
}
/*
SELECT SUM(e.solar), SUM(e.used), SUM(e.adjusted_load), SUM(t.hdd)
FROM energy_monthly e
- LEFT JOIN hdd_monthly t ON e.date = t.date
- WHERE YEAR(e.date) = 2012;
+ LEFT JOIN hdd_monthly t ON e.date = t.date AND e.house_id = t.house_id
+ WHERE e.house_id = 0
+ AND YEAR(e.date) = 2012;
* */
// 0) table totals
- $query = "SELECT SUM(e.used), SUM(e.solar), SUM(e.adjusted_load), SUM(t.hdd) FROM energy_monthly e LEFT JOIN hdd_monthly t ON e.date = t.date WHERE YEAR(e.date) = $year;";
+ $query = "SELECT SUM(e.used), SUM(e.solar), SUM(e.adjusted_load), SUM(t.hdd) FROM energy_monthly e LEFT JOIN hdd_monthly t ON e.date = t.date AND e.house_id = t.house_id WHERE e.house_id = $house AND YEAR(e.date) = $year;";
/*
SELECT e.date, SUM(e.solar), SUM(e.used), SUM(e.adjusted_load), SUM(t.hdd)
FROM energy_monthly e
- LEFT JOIN hdd_monthly t ON e.date = t.date
- WHERE YEAR(e.date) = 2012
+ LEFT JOIN hdd_monthly t ON e.date = t.date AND e.house_id = t.house_id
+ WHERE e.house_id = 0
+ AND YEAR(e.date) = 2012
GROUP BY MONTH(e.date)
ORDER BY date;
* */
// 1) table data
- $query .= "SELECT e.date, SUM(e.used), SUM(e.solar), SUM(e.adjusted_load), SUM(t.hdd) FROM energy_monthly e LEFT JOIN hdd_monthly t ON e.date = t.date WHERE YEAR(e.date) = $year GROUP BY MONTH(e.date) ORDER BY e.date;";
+ $query .= "SELECT e.date, SUM(e.used), SUM(e.solar), SUM(e.adjusted_load), SUM(t.hdd) FROM energy_monthly e LEFT JOIN hdd_monthly t ON e.date = t.date AND e.house_id = t.house_id WHERE e.house_id = $house AND YEAR(e.date) = $year GROUP BY MONTH(e.date) ORDER BY e.date;";
$output = array(
"columns" => array( "Used", "Solar", "Net", "HDD" ),
View
66 get_monthly_usage.php
@@ -10,27 +10,29 @@
}
date_default_timezone_set('America/New_York');
- if (isset($_GET['date']))
+ if (isset($_GET['date']) && isset($_GET['house']))
{
$date = get_post($link, 'date');
$year = date_format(date_create($date), 'Y');
+ $house = get_post($link, 'house');
}
else
{
- $year = '2012'; // default
+ echo "failed";
}
// 0) total used
- $query = "SELECT SUM(used) FROM energy_monthly;";
+ $query = "SELECT SUM(used) FROM energy_monthly WHERE house_id = $house;";
// 1) list by circuit, 2012 query must exclude 1/1 through 3/15
/*
- SELECT SUM(used), SUM(water_heater), SUM(ashp), SUM(water_pump), SUM(dryer), SUM(washer), SUM(dishwasher), SUM(stove), SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) AS 'Other'
- FROM energy_monthly
- WHERE YEAR(date) = 2012
- AND device_id = 5;
+SELECT SUM(used), SUM(water_heater), SUM(ashp), SUM(water_pump), SUM(dryer), SUM(washer), SUM(dishwasher), SUM(stove), SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) AS 'Other'
+FROM energy_monthly
+WHERE house_id = 0
+ AND YEAR(date) = 2012
+ AND device_id = 5;
* */
- $query .= "SELECT SUM(used), SUM(water_heater), SUM(ashp), SUM(water_pump), SUM(dryer), SUM(washer), SUM(dishwasher), SUM(stove), SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) FROM energy_monthly WHERE YEAR(date) = $year AND device_id = 5;";
+ $query .= "SELECT SUM(used), SUM(water_heater), SUM(ashp), SUM(water_pump), SUM(dryer), SUM(washer), SUM(dishwasher), SUM(stove), SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND device_id = 5;";
// break down values monthly
$circuit = null;
@@ -52,18 +54,21 @@
/*
SELECT SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove))
FROM energy_monthly
- WHERE YEAR(date) = 2012
+ WHERE house_id = 0
+ AND YEAR(date) = 2012
AND device_id = 5;
* */
- $query .= "SELECT SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) FROM energy_monthly WHERE YEAR(date) = $year AND device_id = 5;";
+ $query .= "SELECT SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND device_id = 5;";
/*
SELECT date, SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove))
FROM energy_monthly
- WHERE YEAR(date) = 2012
- AND device_id = 5 GROUP BY MONTH(date);
+ WHERE house_id = 0
+ AND YEAR(date) = 2012
+ AND device_id = 5
+ GROUP BY MONTH(date);
* */
// 4) circuit by month
- $query .= "SELECT date, SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) FROM energy_monthly WHERE YEAR(date) = $year AND device_id = 5 GROUP BY MONTH(date);";
+ $query .= "SELECT date, SUM(used)-(SUM(water_heater)+SUM(ashp)+SUM(water_pump)+SUM(dryer)+SUM(washer)+SUM(dishwasher)+SUM(stove)) FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND device_id = 5 GROUP BY MONTH(date);";
}
else if ($circuit == 'total')
{
@@ -73,44 +78,47 @@
/*
SELECT SUM(en.used), SUM(es.used)
FROM energy_monthly en
- LEFT JOIN estimated_monthly es ON en.date = es.date
- WHERE YEAR(en.date) = 2012;
+ LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id
+ WHERE en.house_id = 0
+ AND YEAR(en.date) = 2012;
* */
- $query .= "SELECT SUM(en.used), SUM(es.used) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date WHERE YEAR(en.date) = $year;";
+ $query .= "SELECT SUM(en.used), SUM(es.used) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id WHERE en.house_id = $house AND YEAR(en.date) = $year;";
/*
SELECT en.date, SUM(en.used), SUM(es.used)
FROM energy_monthly en
- LEFT JOIN estimated_monthly es ON en.date = es.date
- WHERE YEAR(en.date) = 2012
+ LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id
+ WHERE en.house_id = 0
+ AND YEAR(en.date) = 2012
GROUP BY MONTH(en.date)
ORDER BY en.date;
* */
- $query .= "SELECT en.date, SUM(en.used), SUM(es.used) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date WHERE YEAR(en.date) = $year GROUP BY MONTH(en.date) ORDER BY en.date";
+ $query .= "SELECT en.date, SUM(en.used), SUM(es.used) FROM energy_monthly en LEFT JOIN estimated_monthly es ON en.date = es.date AND en.house_id = es.house_id WHERE en.house_id = $house AND YEAR(en.date) = $year GROUP BY MONTH(en.date) ORDER BY en.date";
}
else
{
if ($circuit == 'ashp')
{
// 2) get data to calculate projected values --- the reason for all the dummy queries above
/*
- SELECT SUM((65.0 - temperature) * 1 / 24)
- FROM temperature_hourly
- WHERE device_id = 0
- AND YEAR(date) = 2012
- AND temperature <= 65.0
- GROUP BY MONTH(date);
+ SELECT SUM(hdd), date
+ FROM (SELECT IF( ((50 - temperature) * 1 / 24) > 0, ((50 - temperature) * 1 / 24), 0) AS 'hdd', date
+ FROM temperature_hourly
+ WHERE house_id = 0
+ AND device_id = 0
+ AND YEAR(date) = 2012) t
+ GROUP BY MONTH(date);
* */
- $base = 58.0;
- $query .= "SELECT SUM(($base - temperature) * 1 / 24) FROM temperature_hourly WHERE device_id = 0 AND YEAR(date) = $year AND temperature <= $base GROUP BY MONTH(date);";
+ $base = 50.0;
+ $query .= "SELECT SUM(hdd) FROM (SELECT IF( (($base - temperature) * 1 / 24) > 0, (($base - temperature) * 1 / 24), 0) AS 'hdd', date FROM temperature_hourly WHERE house_id = $house AND device_id = 0 AND YEAR(date) = $year) t GROUP BY MONTH(date);";
}
else
{
$query .= "SELECT 1+1;";
}
// 3) circuit total
- $query .= "SELECT SUM($circuit) FROM energy_monthly WHERE YEAR(date) = $year AND device_id = 5;";
+ $query .= "SELECT SUM($circuit) FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND device_id = 5;";
// 4) circuit by month
- $query .= "SELECT date, $circuit FROM energy_monthly WHERE YEAR(date) = $year AND device_id = 5 GROUP BY MONTH(date);";
+ $query .= "SELECT date, $circuit FROM energy_monthly WHERE house_id = $house AND YEAR(date) = $year AND device_id = 5 GROUP BY MONTH(date);";
}
$output = array(
View
103 get_monthly_water.php
@@ -0,0 +1,103 @@
+<?php
+ // monthly_water
+
+ require_once 'login.php';
+ $link = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);
+
+ if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+ }
+
+ date_default_timezone_set('America/New_York');
+ if (isset($_GET['date']) && isset($_GET['house']))
+ {
+ $date = get_post($link, 'date');
+ $year = date_format(date_create($date), 'Y');
+ $house = get_post($link, 'house');
+ }
+ else
+ {
+ echo "failed";
+ }
+
+ // 0 totals and 1) list by month
+ /*
+ SELECT SUM(main.gallons)-SUM(hot.gallons), SUM(hot.gallons), SUM(main.gallons), SUM(e.water_heater), SUM(e.water_pump)
+ FROM energy_monthly e
+ LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 6) main ON e.date = main.date AND main.house_id = e.house_id
+ LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 7) hot ON e.date = hot.date AND hot.house_id = e.house_id
+ WHERE e.house_id = 0
+ AND YEAR(e.date) = 2012;
+ * */
+ $query = "SELECT SUM(main.gallons)-SUM(hot.gallons), SUM(hot.gallons), SUM(main.gallons), SUM(e.water_heater), SUM(e.water_pump) ";
+ $query .= "FROM energy_monthly e ";
+ $query .= "LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 6) main ON e.date = main.date AND main.house_id = e.house_id ";
+ $query .= "LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 7) hot ON e.date = hot.date AND hot.house_id = e.house_id ";
+ $query .= "WHERE e.house_id = $house ";
+ $query .= "AND YEAR(e.date) = $year;";
+ /*
+ SELECT e.date, SUM(main.gallons)-SUM(hot.gallons), SUM(hot.gallons), SUM(main.gallons), SUM(e.water_heater), SUM(e.water_pump)
+ FROM energy_monthly e
+ LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 6) main ON e.date = main.date AND main.house_id = e.house_id
+ LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 7) hot ON e.date = hot.date AND hot.house_id = e.house_id
+ WHERE e.house_id = 0
+ AND YEAR(e.date) = 2012
+ GROUP BY MONTH(e.date)
+ ORDER BY date;
+ * */
+ $query .= "SELECT e.date, SUM(main.gallons)-SUM(hot.gallons), SUM(hot.gallons), SUM(main.gallons), SUM(e.water_heater), SUM(e.water_pump) ";
+ $query .= "FROM energy_monthly e ";
+ $query .= "LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 6) main ON e.date = main.date AND main.house_id = e.house_id ";
+ $query .= "LEFT JOIN (SELECT house_id, date, gallons FROM water_monthly WHERE device_id = 7) hot ON e.date = hot.date AND hot.house_id = e.house_id ";
+ $query .= "WHERE e.house_id = $house ";
+ $query .= "AND YEAR(e.date) = $year ";
+ $query .= "GROUP BY MONTH(e.date) ";
+ $query .= "ORDER BY e.date;";
+
+ $output = array(
+ "columns" => array( "Cold", "Hot", "Total", "Hot Water Wh/g", "Water Pump Wh/g" ),
+ "totals" => array(),
+ "months" => array()
+ );
+
+ if (mysqli_multi_query($link, $query))
+ {
+ $j = 0;
+ do
+ {
+ if ($result = mysqli_store_result($link))
+ {
+ switch($j)
+ {
+ case(0):
+ $output[ "totals" ] = mysqli_fetch_row($result);
+ break;
+ case(1):
+ $aRow = array();
+ while ($row = mysqli_fetch_row($result))
+ {
+ $aRow[] = $row;
+ }
+ $output[ "months" ] = $aRow;
+ }
+ }
+ /* print divider */
+ if (mysqli_more_results($link))
+ {
+ $j++;
+ }
+ } while (mysqli_next_result($link));
+ }
+
+ mysqli_close($link);
+
+ echo json_encode( $output );
+
+ function get_post($link, $var)
+ {
+ $temp = mysqli_real_escape_string($link, $_GET[$var]);
+ if ($temp == '') $temp = 'NULL';
+ return $temp;
+ }
+?>
View
127 interactive_base_temp.html
@@ -30,6 +30,7 @@
<option value="16">Generation</option>
<option value="17">Usage</option>
<option value="18">Heating Degree Days</option>
+ <option value="20">Water Usage</option>
<option value="19" selected="selected">Base Temp Analysis</option>
</optgroup>
<optgroup label="Daily">
@@ -56,7 +57,8 @@
</nav>
<p>Sample detail:</p>
<ul>
- <li><input type="radio" id="hours" name="period" checked="checked" value="hours" /><label for="hours">Hours</label></li>
+ <li><input type="radio" id="hours" name="period" value="hours" checked="checked" /><label for="hours">Hours</label> <a id="optionButton" href="#" style="display: none;">Options</a></li>
+ <li id="options" style="display: none;"><input type="checkbox" id="seriesOption" name="series" value="series" /><label for="seriesOption">Multi-series</label> <input type="radio" id="pointOption" name="options" value="scatter" checked="checked" /><label for="pointOption">Points</label> <input type="radio" id="lineOption" name="options" value="line" /><label for="lineOption">Lines</label></li>
<li><input type="radio" id="days" name="period" value="days" /><label for="days">Days</label></li>
<li><input type="radio" id="months" name="period" value="months" /><label for="months">Months</label></li>
</ul>
@@ -74,11 +76,11 @@
</ul>
<p id="reporting"></p>
</div>
- <div id="chart"></div>
+ <div id="chart">Loading...</div>
<footer>
<p id="instructions">Turn device to toggle between form and chart view.</p>​
- <p>&copy; netplusdesign 2012</p>
+ <p>&copy; netplusdesign 2012-2013</p>
</footer>
</div>
<script src="js/jquery-1.7.1.min.js"></script>
@@ -110,13 +112,13 @@
}
}(document));
- var chart = null;
- var options;
- var series = [];
- var xr = [];
- var yr = [];
+ var houseId = 0;
+ var chart = null;
var currentOption = 'hours';
var previousOption = 'hours';
+ var chartOption = new Object();
+ chartOption.type = 'scatter';
+ chartOption.series = 'single';
var today;
plot();
@@ -150,16 +152,27 @@
event.preventDefault();
});
- $('input:radio').change( function() {
+ $('input:radio[name=period]').change( function() {
currentOption = $('input:radio[name=period]:checked').val();
- })
-
+ });
+
+ /* Not finished yet
+ $('a#optionButton').click( function () {
+ $('li#options').show();
+ });
+ $('input:checkbox').change( function() {
+ chartOption.option = $('input:checkbox').val();
+ });
+ $('input:radio[name=options]').change( function() {
+ chartOption.type = $('input:radio[name=options]:checked').val();
+ }).prop('disabled', true);
+ */
function plot()
{
if (chart) chart.showLoading('Loading data...');
var base = $('input#base').val();
var period = $('input:radio[name=period]:checked').val();
- var dfile = "get_hdd_ashp.php?base=" + base + "&period=" + period;
+ var dfile = "get_hdd_ashp.php?base=" + base + "&period=" + period + "&house=" + houseId;
series = [];
xr = [];
yr = [];
@@ -199,12 +212,22 @@
point: {
events: {
mouseOver: function() {
- $('p#reporting').html('HDD: '+ Math.round(this.x*1000)/1000 +'<br />kWh: '+ this.y + '<br />Date: ' + this['config'][2]);
+ if (this['date'])
+ {
+ d = Date.parse( this['date'] );
+ if (currentOption == 'hours') dt = d.toString('MMM d, yyyy h tt');
+ if (currentOption == 'days') dt = d.toString('MMM d, yyyy');
+ if (currentOption == 'months') dt = d.toString('MMM, yyyy');
+ $('p#reporting').html("HDD: " + Math.round(this.x*1000)/1000 + "<br />kWh: " + this.y + "<br />Temperature: " + this['temp'] + "&deg;F<br />Date: " + dt );
+ }
},
click: function() {
- dt = this['config'][2].split(' ');
- tm = (previousOption == 'hours') ? '&time=' + dt[1].split(':')[0] : '';
- location.href = 'daily.html?option=8&date=' + dt[0] + tm;
+ if (this['date'])
+ {
+ dt = this['date'].split(' ');
+ tm = (previousOption == 'hours') ? '&time=' + dt[1].split(':')[0] : '';
+ location.href = 'daily.html?option=8&date=' + dt[0] + tm;
+ }
}
}
},
@@ -235,11 +258,11 @@
}; // end set options
var lines = data.split('\n'); // splits the file into lines
- series[0] = new Object();
- series[0].name = 'Data point';
- series[0].type = 'scatter';
- series[0].color = 'rgba(223, 83, 83, .5)';
- series[0].data = [];
+
+ var i = 0;
+ var series = [];
+ var points = [];
+ points[i] = [];
$.each(lines, function(lineNo, line)
{
@@ -248,45 +271,57 @@
// hdd, ashp
xr[lineNo] = parseFloat(items[0]);
yr[lineNo] = parseFloat(items[1]);
- series[0].data.push( Array( parseFloat(items[0]), parseFloat(items[1]), items[2] ) ); // why do I need items[2] here?
- //series[0].data[series[0].data.length-1] = new Object();
- series[0].data[series[0].data.length-1].name = items[2];
+
+ points[i].push( { temp : items[2], date: items[3], x : parseFloat(items[0]), y : parseFloat(items[1]) } );
+ if ((currentOption == 'hours') && (chartOption.series == 'multiple'))
+ {
+ d = Date.parse( items[3] );
+ nextDay = d.getDate();
+ if ((lineNo > 0) && (nextDay != previousDay ))
+ {
+ // if next day, then increment series
+ series.push( { name : d.toString('yy-MM-dd'), type : chartOption.type, data : points[i] } );
+ points[++i] = [];
+ }
+ previousDay = nextDay;
+ }
+
});
+ if ((currentOption != 'hours') || (chartOption != 'multiple'))
+ {
+ series.push( { name : 'Data point', type : 'scatter', color : 'rgba(223, 83, 83, .5)', data : points[i] } );
+ }
var lr = linearRegression(yr,xr);
- $('span#slope').text(Math.round(lr.slope*10000)/10000);
- $('span#intercept').text(Math.round(lr.intercept*10000)/10000);
- $('span#r2').text(Math.round(lr.r2*10000)/10000);
+ $('span#slope').text( lr.slope.toFixed(4) );
+ $('span#intercept').text( lr.intercept.toFixed(3) );
+ $('span#r2').text( lr.r2.toFixed(4) );
lr.intercept > 0 ? $('span#plus').text(' + ') : $('span#plus').text('');
- series[1] = new Object();
- series[1].name = 'Regression Line';
- series[1].type = 'line';
- series[1].color = '#336699';
- series[1].data = [];
-
start_x = Math.min.apply(Math, xr);
start_y = lr.slope * start_x + lr.intercept;
end_x = Math.max.apply(Math, xr);
end_y = lr.slope * end_x + lr.intercept;
- series[1].data.push( Array(start_x, start_y) );
- series[1].data.push( Array(end_x, end_y) );
+ series.push( { name : 'Regression Line', type : 'line', color : '#336699', data : [ Array(start_x, start_y), Array(end_x, end_y) ] } );
- options.series.push(series[0]);
- options.series.push(series[1]);
-
- if (chart == null)
- {
- chart = new Highcharts.Chart(options);
- }
- else
+ for (i=0; i < series.length; i++)
{
- chart.series[0].setData(series[0].data);
- chart.series[1].setData(series[1].data);
+ options.series.push(series[i]);
}
- chart.hideLoading();
+ chart = new Highcharts.Chart(options);
+
+ if ((currentOption == 'hours') && (chartOption.series == 'multiple'))
+ { // hide each series except for first and last.
+ // Makes it easier to show / hide individual series.
+ // unfortunately also makes it work incredibly slow...
+ for (i=1; i<chart.series.length-1; i++)
+ {
+ chart.series[i].hide();
+ }
+ }
+ chart.hideLoading();
}); // end get
} // end function plot_init();
View
308 js/monthly.js
@@ -26,7 +26,7 @@ $(document).ready(function()
}(document));
// global variables
- //var chart = null;
+ var houseId = 0;
var today, asofDate;
getMetaData();
@@ -88,15 +88,18 @@ $(document).ready(function()
case 18:
getHddData();
break;
+ case 20:
+ getWaterData();
+ break;
}
}
// =======================================================================================================
function getMetaData()
{ // get initializing variables
- $.getJSON("get_monthly_metadata.php", function( json )
+ $.getJSON("get_monthly_metadata.php", { house: houseId }, function( json )
{
- asofDate = makeDate( json['asof'] )
+ asofDate = Date.parse( json['asof'] )
setToday();
showAsofDate();
showYearSelector( json['years'] );
@@ -112,8 +115,8 @@ $(document).ready(function()
}
else
{
- today = new Date( asofDate );
- today.setDate( 1 ); // first day of most recent month of data
+ today = asofDate.clone();
+ today.moveToFirstDayOfMonth();
}
}
function showAsofDate()
@@ -132,7 +135,7 @@ $(document).ready(function()
// =======================================================================================================
function getSummaryData()
{
- $.getJSON("get_monthly_summary.php", { date: today.toString('yyyy-MM-dd') }, function( json )
+ $.getJSON("get_monthly_summary.php", { date: today.toString('yyyy-MM-dd'), house: houseId }, function( json )
{ // date : "2012-11-01"
showSummaryTable( json );
setupChartTabs("Usage vs. Solar","Monthly");
@@ -144,16 +147,14 @@ $(document).ready(function()
}
function showSummaryTable( data )
{
- var newYears = new Date(today.getFullYear()-1,11,DaysInMonth(new Date(today.getFullYear()-1,11))); // Get the date of last day of last year
- var days = asofDate - newYears;
- days = days / (1000*60*60*24);
+ var days = asofDate.getDayOfYear() + 1;
// console.log( "days = " + Math.floor(days) );
$('div#data').append( makeTags('table', 1) );
$('div#data table').append( "<tr><th></th><th class='lable usage'>Usage</th><th class='lable solar'>Solar</th><th class='lable net'>Net</th><th>Avg.<br/>daily<br/>usage</th><th class='lable hdd'>HDD</th></tr>" );
- $('div#data table').append( "<tr><th class='name'>Total</th><th class='total'>" + round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th class='total'>" + Math.round(data['totals'][2]) + "</th><th>" + round( data['totals'][0] / days, 1 ) + "</th><th class='hdd'>" + round(data['totals'][3]) + "</th></tr>" );
+ $('div#data table').append( "<tr><th class='name'>Total</th><th class='total'>" + Math.round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th class='total'>" + Math.round(data['totals'][2]) + "</th><th>" + ( data['totals'][0] / days ).toFixed(1) + "</th><th class='hdd'>" + Math.round(data['totals'][3]) + "</th></tr>" );
for ( i=0; i<data['months'].length; i++ )
{
- $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ) ) + "</td><td class='usage'>" + round(parseFloat(data['months'][i][1])) + "</td><td class='solar'>" + round(data['months'][i][2]) + "</td><td class='net'>" + round( data['months'][i][3] ) + "</td><td>" + round( data['months'][i][1] / Date.parse(data['months'][i][0]).getDaysInMonth(), 1) + "</td><td class='hdd'>" + round(data['months'][i][4]) + "</td></tr>" );
+ $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ) ) + "</td><td class='usage'>" + Math.round(data['months'][i][1]) + "</td><td class='solar'>" + Math.round(data['months'][i][2]) + "</td><td class='net'>" + Math.round( data['months'][i][3] ) + "</td><td>" + ( data['months'][i][1] / Date.parse( data['months'][i][0] ).getDaysInMonth() ).toFixed(1) + "</td><td class='hdd'>" + Math.round(data['months'][i][4]) + "</td></tr>" );
}
}
function setupChartTabs( tab1, tab2 )
@@ -270,8 +271,8 @@ $(document).ready(function()
}
for (i=0; i<2; i++)
{
- series[0].data.push( { y : Math.round(Math.abs(parseFloat( data['totals'][i] ))),
- color : ((i > 0) && (Math.abs(parseFloat( data['totals'][0])) > Math.abs(parseFloat( data['totals'][1])))) ? colors[2] : colors[i] });
+ series[0].data.push( { y : Math.round( Math.abs( data['totals'][i] ) ),
+ color : ((i > 0) && ( Math.abs( data['totals'][0] ) > Math.abs( data['totals'][1] ) )) ? colors[2] : colors[i] });
// if usage is > solar then danger, danger! (change color of usage to red)
}
// Create the chart
@@ -358,7 +359,7 @@ $(document).ready(function()
var d = [];
for (j=0; j < data['months'].length ;j++ )
{
- d.push( parseFloat( round(data['months'][j][i+1]) ));
+ d.push( Math.round( data['months'][j][i+1] ) );
}
if (i == (data['columns'].length-1))
{
@@ -379,32 +380,29 @@ $(document).ready(function()
// ===========================================================================================
function getGenerationData()
{
- $.getJSON("get_monthly_generation.php", { date: today.toString('yyyy-MM-dd') }, function( json )
+ $.getJSON("get_monthly_generation.php", { date: today.toString('yyyy-MM-dd'), house: houseId }, function( json )
{
showGenerationTable( json );
showGenerationYTD( json );
});
}
function showGenerationTable( data )
{
- var newYears = new Date( today.getFullYear()-1, 11, new Date(today.getFullYear()-1,11).getDaysInMonth() ); // Get the date of last day of last year
- var days = asofDate - newYears;
- days = days / (1000*60*60*24);
- // console.log( "days = " + Math.floor(days) );
- $('div#data').append( "<p><b>Since Jan 2012</b> : " + round(data['total_generated']) + "</p>" );
- $('div#data').append( "<p><b>kWh / day</b> : " + round( (data['total_generated'] / days), 1) + "</p>" );
+ var days = asofDate.getDayOfYear() + 1;
+ $('div#data').append( "<p><b>Since Jan 2012</b> : " + Math.round(data['total_generated']) + "</p>" );
+ $('div#data').append( "<p><b>kWh / day</b> : " + ( data['total_generated'] / days ).toFixed(1) + "</p>" );
$('div#data').append( "<p><b>Max Wh</b> : " + data['max_solar_hour'][0] + ", Date: " + Date.parse( data['max_solar_hour'][1] ).toString('M/d htt') + "</p>" );
- $('div#data').append( "<p><b>Max kWh day</b> : " + round( data['max_solar_day'][0], 1) + ", Date: " + Date.parse( data['max_solar_day'][1] ).toString('M/d') + "</p>" );
+ $('div#data').append( "<p><b>Max kWh day</b> : " + Number( data['max_solar_day'][0] ).toFixed(1) + ", Date: " + Date.parse( data['max_solar_day'][1] ).toString('M/d') + "</p>" );
$('div#data').append( makeTags('table', 1) );
$('div#data table').append( "<tr><th></th><th class='lable usage'>Actual</th><th class='lable budget'>Estimated</th><th>Diff(%)<span class='net'>Net</span></th></tr>" );
- var percChange = round( (((data['totals'][0])-data['totals'][1]) / data['totals'][1] ) * 100);
+ var percChange = Math.round( (((data['totals'][0])-data['totals'][1]) / data['totals'][1] ) * 100 );
style = (percChange >= 0) ? "positive" : "negative";
- $('div#data table').append( "<tr><th class='name'>YTD</th><th class='total'>" + round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th class='" + style + "'>" + percChange + "</th></tr>" );
+ $('div#data table').append( "<tr><th class='name'>YTD</th><th class='total'>" + Math.round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th class='" + style + "'>" + percChange + "</th></tr>" );
for ( i=0; i<data['months'].length; i++ )
{
- percChange = round( (((data['months'][i][1])-data['months'][i][2]) / data['months'][i][2] ) * 100);
+ percChange = Math.round( (((data['months'][i][1])-data['months'][i][2]) / data['months'][i][2] ) * 100);
style = (percChange >= 0) ? "positive" : "negative";
- $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ), 2 ) + "</td><td class='usage'>" + round(parseFloat(data['months'][i][1])) + "</td><td class='budget'>" + round(data['months'][i][2]) + "</td><td class='" + style + "'>" + percChange + "<span class='net'>" + round(data['months'][i][1]-data['months'][i][2]) + "</span></td></tr>" );
+ $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ), 2 ) + "</td><td class='usage'>" + Math.round(data['months'][i][1]) + "</td><td class='budget'>" + Math.round(data['months'][i][2]) + "</td><td class='" + style + "'>" + percChange + "<span class='net'>" + Math.round(data['months'][i][1]-data['months'][i][2]) + "</span></td></tr>" );
}
}
function showGenerationYTD( data )
@@ -463,7 +461,7 @@ $(document).ready(function()
// Iterate over the lines and add series names or data
for (i=0; i<data['months'].length; i++)
{
- options.xAxis.categories.push( Date.parse(data['months'][i][0]).toString('MMM') );
+ options.xAxis.categories.push( Date.parse( data['months'][i][0] ).toString('MMM') );
}
data['columns'].push('Net');
for (i = 0 ; i < data['columns'].length ; i++)
@@ -473,11 +471,11 @@ $(document).ready(function()
{
if (i < data['columns'].length-1)
{
- d.push( parseFloat( round(data['months'][j][i+1]) ));
+ d.push( Math.round(data['months'][j][i+1]) );
}
else
{
- d.push( parseFloat( round(data['months'][j][2]) - round(data['months'][j][1]) ));
+ d.push( Math.round( data['months'][j][2] - data['months'][j][1] ) );
}
}
options.series.push( { name : data['columns'][i], data : d } );
@@ -494,7 +492,7 @@ $(document).ready(function()
function getUsageData( circuit )
{
if (!circuit) circuit = "";
- $.getJSON("get_monthly_usage.php", { date: today.toString('yyyy-MM-dd'), circuit : circuit }, function( json )
+ $.getJSON("get_monthly_usage.php", { date: today.toString('yyyy-MM-dd'), circuit : circuit, house: houseId }, function( json )
{
var circuits = {
"total" : { "name" : "Total", "index" : 3 },
@@ -519,17 +517,15 @@ $(document).ready(function()
}
function showUsageTable( data )
{
- var newYears = new Date( today.getFullYear()-1, 11, new Date(today.getFullYear()-1,11).getDaysInMonth() ); // Get the date of last day of last year
- var days = asofDate - newYears;
- days = days / (1000*60*60*24);
- $('div#data').append( "<p><b>Since Jan 2012</b> : " + round(data['total_used']) + "</p>" );
- $('div#data').append( "<p><b>kWh / day</b> : " + round( (data['total_used'] / days), 1) + "</p>" );
+ var days = asofDate.getDayOfYear() + 1;
+ $('div#data').append( "<p><b>Since Jan 2012</b> : " + Math.round(data['total_used']) + "</p>" );
+ $('div#data').append( "<p><b>kWh / day</b> : " + (data['total_used'] / days).toFixed(1) + "</p>" );
$('div#data').append( makeTags('table', 1) );
$('div#data table').append( "<tr><th></th><th class='lable'>YTD&sup1;</th><th class='lable'>% of total</th><th></th></tr>" );
var i = 0;
for ( circuit in data.meta )
{
- $('div#data table').append( "<tr class='circuits'><td class='circuit name'><a id='" + circuit + "' href='#'>" + data.meta[circuit]['name'] + " &darr;</a></td><td class='kwh'>" + round(parseFloat(data['circuits'][i])) + "</td><td class='perc'>" + round((data['circuits'][i] / data['circuits'][0])*100) + "</td><td></td></tr>" );
+ $('div#data table').append( "<tr class='circuits'><td class='circuit name'><a id='" + circuit + "' href='#'>" + data.meta[circuit]['name'] + " &darr;</a></td><td class='kwh'>" + Math.round(data['circuits'][i]) + "</td><td class='perc'>" + Math.round((data['circuits'][i] / data['circuits'][0])*100) + "</td><td></td></tr>" );
i++;
}
$('div#data table tr.circuits td a').on( "click", function(event) {
@@ -584,14 +580,14 @@ $(document).ready(function()
var projected = getProjectedHeatEnergy( data['hdds'][i] );
var percChange = ((projected - data['months'][i][1]) / data['months'][i][1] ) * 100;
style = (percChange >= 0) ? "positive" : "negative";
- column.push( parseFloat( data['months'][i][1] ).toFixed(1) ); // total kWh for circuit for month
- column.push( projected.toFixed(1) );
+ column.push( data['months'][i][1] ); // total kWh for circuit for month
+ column.push( projected.toFixed(3) );
column.push( percChange.toFixed() );
column.push( projected - data['months'][i][1] ); // net
}
else
{
- column.push( parseFloat( data['months'][i][1] ).toFixed(1) ); // total kWh for circuit for month
+ column.push( data['months'][i][1] ); // total kWh for circuit for month
column.push( "0" );
column.push( "0" );
column.push( "0" );
@@ -601,12 +597,15 @@ $(document).ready(function()
((data['circuit'] != 'total') && (data['circuit'] != 'ashp')) ? $('.dh').hide() : $('.dh').show();
// $('th.budget,td.budget').hide();
$('div#data').append("<p class='notes'>1. Circuit level data starts March 16, 2012.</p>");
- if (data['circuit'] == 'ashp') $('div#data').append("<p class='notes'>2. Projection based on HDD base 58&deg;</p>");
+ if (data['circuit'] == 'ashp') $('div#data').append("<p class='notes'>2. Projection based on HDD base 50&deg;</p>");
}
function getProjectedHeatEnergy( hdd )
{
// makes it easier to adjust the formula in the future, returns kWh
- return hdd * 0.0769 + 4.7596; // HDD 58F base
+ // return hdd * 0.0769 + 4.7596; // HDD 58F base
+ console.log('hdd = ' + hdd);
+ // return hdd * 4.0015 + 17.0838; // HDD 27F base
+ return hdd * 0.2261 + 0.7565; // HDD 50F base
}
function showUsageYTD( data )
{
@@ -790,33 +789,33 @@ $(document).ready(function()
// ===========================================================================================
function getHddData()
{
- $.getJSON("get_monthly_hdd.php", { date: today.toString('yyyy-MM-dd') }, function( json )
+ $.getJSON("get_monthly_hdd.php", { date: today.toString('yyyy-MM-dd'), house: houseId }, function( json )
{
showHddTable( json );
showHddYTD( json );
});
}
function showHddTable( data )
{
- $('div#data').append( "<p><b>HDD (base 65&deg;)</b> : " + round(data['total_hdd']) + "</p>" );
- $('div#data').append( "<p><b>BTU/SF/HDD</b> : " + round( (data['total_ashp'] * 3412.14163) / 1408 / data['total_hdd'], 3) + "</p>" ); // round(($row[1]*3412.14163)/1408/$row[0],3)
+ // $('div#data').append( "<p><b>HDD (base 65&deg;)</b> : " + Math.round(data['total_hdd']) + "</p>" );
+ $('div#data').append( "<p><b>BTU/SF/HDD</b> : " + ((data['total_ashp'] * 3412.14163) / 1408 / data['total_hdd']).toFixed(3) + "</p>" );
var d = Date.parse(data['coldest_hour'][1]);
$('div#data').append( "<p><b>Coldest temp.</b> : " + data['coldest_hour'][0] + "&deg;, Date: <a href='daily.html?option=4&date=" + d.toString('yyyy-MM-dd') + "&time=" + d.toString('HH') + "'>" + d.toString('M/d htt') + "</a></p>" );
d = Date.parse(data['coldest_day'][1]);
- $('div#data').append( "<p><b>Coldest day</b> : " + round( data['coldest_day'][0], 1) + " HDD, Date: <a href='daily.html?option=4&date=" + d.toString('yyyy-MM-dd') + "'>" + d.toString('M/d') + "</a></p>" );
+ $('div#data').append( "<p><b>Coldest day</b> : " + Number( data['coldest_day'][0] ).toFixed(1) + " HDD, Date: <a href='daily.html?option=4&date=" + d.toString('yyyy-MM-dd') + "'>" + d.toString('M/d') + "</a></p>" );
$('div#data').append( makeTags('table', 1) );
$('div#data table').append( "<tr><th></th><th class='lable usage'>Actual</th><th class='lable budget'>Estimated</th><th>Diff(%)<span class='net'>Net</span></th></tr>" );
- var percChange = round( (((data['totals_heating_season'][0])-data['totals_heating_season'][1]) / data['totals_heating_season'][1] ) * 100);
+ var percChange = Math.round( (((data['totals_heating_season'][0])-data['totals_heating_season'][1]) / data['totals_heating_season'][1] ) * 100);
style = (percChange >= 0) ? "positive" : "negative";
- $('div#data table').append( "<tr><th class='name'>Heating season</th><th class='total'>" + round(data['totals_heating_season'][0]) + "</th><th class='total'>" + Math.round(data['totals_heating_season'][1]) + "</th><th class='" + style + "'>" + percChange + "</th></tr>" );
- var percChange = round( (((data['totals'][0])-data['totals'][1]) / data['totals'][1] ) * 100);
+ $('div#data table').append( "<tr><th class='name'>Heating season</th><th class='total'>" + Math.round(data['totals_heating_season'][0]) + "</th><th class='total'>" + Math.round(data['totals_heating_season'][1]) + "</th><th class='" + style + "'>" + percChange + "</th></tr>" );
+ var percChange = Math.round( (((data['totals'][0])-data['totals'][1]) / data['totals'][1] ) * 100);
style = (percChange >= 0) ? "positive" : "negative";
- $('div#data table').append( "<tr><th class='name'>YTD</th><th class='total'>" + round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th class='" + style + "'>" + percChange + "</th></tr>" );
+ $('div#data table').append( "<tr><th class='name'>YTD</th><th class='total'>" + Math.round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th class='" + style + "'>" + percChange + "</th></tr>" );
for ( i=0; i<data['months'].length; i++ )
{
- percChange = round( (((data['months'][i][1])-data['months'][i][2]) / data['months'][i][2] ) * 100);
+ percChange = Math.round( (((data['months'][i][1])-data['months'][i][2]) / data['months'][i][2] ) * 100);
style = (percChange >= 0) ? "positive" : "negative";
- $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ), 6 ) + "</td><td class='usage'>" + round(parseFloat(data['months'][i][1])) + "</td><td class='budget'>" + round(data['months'][i][2]) + "</td><td class='" + style + "'>" + percChange + "<span class='net'>" + round(data['months'][i][1]-data['months'][i][2]) + "</span></td></tr>" );
+ $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ), 6 ) + "</td><td class='usage'>" + Math.round(data['months'][i][1]) + "</td><td class='budget'>" + Math.round(data['months'][i][2]) + "</td><td class='" + style + "'>" + percChange + "<span class='net'>" + Math.round(data['months'][i][1]-data['months'][i][2]) + "</span></td></tr>" );
}
}
function showHddYTD( data )
@@ -885,11 +884,11 @@ $(document).ready(function()
{
if (i < data['columns'].length-1)
{
- d.push( parseFloat( round(data['months'][j][i+1]) ));
+ d.push( Math.round( data['months'][j][i+1] ) );
}
else
{
- d.push( parseFloat( round(data['months'][j][1]) - round(data['months'][j][2]) ));
+ d.push( Math.round( data['months'][j][1] - data['months'][j][2] ) );
}
}
options.series.push( { name : data['columns'][i], data : d } );
@@ -902,6 +901,58 @@ $(document).ready(function()
chart = new Highcharts.Chart(options);
}
+ // ===========================================================================================
+ function getWaterData()
+ {
+ $.getJSON("get_monthly_water.php", { date: today.toString('yyyy-MM-dd'), house: houseId }, function( json )
+ {
+ showWaterTable( json );
+ showWaterYTD( json );
+ });
+ }
+ function showWaterTable( data )
+ {
+ $('div#data').append( makeTags('table', 1) );
+ $('div#data table').append( "<tr><th></th><th class='lable usage' colspan='3' style='text-align: center;'>Gallons</th><th colspan='2'>Watt hours / gallon</th></tr>" );
+ $('div#data table').append( "<tr><th></th><th class='lable usage'>Cold</th><th class='lable budget'>Hot</th><th>Total</th><th>Hot<br/>Water</th><th>Water<br/>Pump</th></tr>" );
+ var water_heater_efficiency, water_pump_efficiency;
+ if (today.getFullYear() == 2012)
+ {
+ // 2012 circuit level data ddn't start till 3/16
+ // so need to subtract Jan-Mar water vales for main and hot
+ // and subtract kWh for March
+ var hot_water = 0;
+ var main_water = 0;
+ var water_heater_kwh = 0;
+ var water_pump_kwh = 0;
+ for (i=3; i<data['months'].length; i++)
+ {
+ hot_water += parseFloat(data['months'][i][2]);
+ main_water += parseFloat(data['months'][i][3]);
+ water_heater_kwh += parseFloat(data['months'][i][4]);
+ water_pump_kwh += parseFloat(data['months'][i][5]);
+ }
+ water_heater_efficiency = ( water_heater_kwh * 1000 / hot_water ).toFixed(1);
+ water_pump_efficiency = ( water_pump_kwh * 1000 / main_water ).toFixed(3);
+ }
+ else
+ {
+ water_heater_efficiency = ( data['totals'][3] * 1000 / data['totals'][1] ).toFixed(1);
+ water_pump_efficiency = ( data['totals'][4] * 1000 / data['totals'][2] ).toFixed(3);
+ }
+ $('div#data table').append( "<tr><th class='name'>Total</th><th class='total'>" + Math.round(data['totals'][0]) + "</th><th class='total'>" + Math.round(data['totals'][1]) + "</th><th>" + Math.round(data['totals'][2]) + "</th><th>" + water_heater_efficiency + "</th><th>" + water_pump_efficiency + "</th></tr>" );
+ for ( i=0; i<data['months'].length; i++ )
+ {
+ water_heater_efficiency = ( data['months'][i][4] * 1000 / data['months'][i][2] ).toFixed(1);
+ water_pump_efficiency = ( data['months'][i][5] * 1000 / data['months'][i][3] ).toFixed(3);
+ $('div#data table').append( "<tr><td class='month name'>" + addDateAnchor( Date.parse( data['months'][i][0] ) ) + "</td><td class='usage'>" + Math.round(data['months'][i][1]) + "</td><td class='budget'>" + Math.round(data['months'][i][2]) + "</td><td>" + Math.round(data['months'][i][3]) + "</td><td>" + water_heater_efficiency + "</td><td>" + water_pump_efficiency + "</td></tr>" );
+ }
+ }
+ function showWaterYTD( data )
+ {
+
+ }
+
function addDateAnchor( d, option )
{
// date is a date
@@ -915,11 +966,6 @@ $(document).ready(function()
return d.toString('MMM');
}
}
- function round(value, precision)
- {
- precision = (precision && precision != 0) ? Math.pow(10, precision) : 1 ;
- return Math.round( (value*precision) ) / precision;
- }
function setupCalendar()
{
$('table').append( makeTags('tr', 6) );
@@ -931,150 +977,4 @@ $(document).ready(function()
for (i=0; i<n; i++) { fstr = fstr + str; }
return fstr;
}
-
- function getMonthFilename( d )
- {
- //return "data/" + formatAddZero( (d.getMonth()+1).toString() ) + "-" + d.getFullYear() + "-day-data.csv";
- return "get_daily_data.php?date=" + today.getFullYear() + "-" + formatAddZero( (today.getMonth()+1).toString() ) + "-" + formatAddZero( today.getDate().toString() );
- }
-
- function getDayFilename( d )
- {
- return "get_hourly_data.php?date=" + today.getFullYear() + "-" + formatAddZero( (today.getMonth()+1).toString() ) + "-" + formatAddZero( today.getDate().toString() );
- }
-
- function formatAddZero( d )
- {
- if (d.length == 1) return d = "0" + d;
- else return d;
- }
-
- function Color(space, a, b, c)
- {
- // Color.prototype.rgb_to_hsv = function()
- Color.prototype.rgb_to_hsv = function()
- {
- maxc = Math.max(this.r, this.g, this.b);
- minc = Math.min(this.r, this.g, this.b);
- this.v = maxc;
- if (minc == maxc)
- {
- this.h = 0;
- this.s = 0;
- //this.v = v;
- }
- diff = maxc - minc;
- this.s = diff / maxc;
- rc = (maxc - this.r) / diff;
- gc = (maxc - this.g) / diff;
- bc = (maxc - this.b) / diff;
- if (this.r == maxc)
- {
- this.h = bc - gc;
- }
- else if (this.g == maxc)
- {
- this.h = 2.0 + rc - bc;
- }
- else
- {
- this.h = 4.0 + gc - rc;
- }
- this.h = (this.h / 6.0) % 1.0; //comment: this calculates only the fractional part of h/6
- }
- Color.prototype.hsv_to_rgb = function()
- {
- if (this.s == 0.0)
- {
- this.r = this.g = this.b = this.v;
- }
- i = Math.floor(this.h*6.0); //comment: floor() should drop the fractional part
- f = (this.h*6.0) - i;
- p = this.v*(1.0 - this.s);
- q = this.v*(1.0 - this.s*f);
- t = this.v*(1.0 - this.s*(1.0 - f));
- if ((i % 6) == 0)
- {
- this.r = this.v;
- this.g = t;
- this.b = p;
- }
- if (i == 1)
- {
- this.r = q;
- this.g = this.v;
- this.b = p;
- }
- if (i == 2)
- {
- this.r = p;
- this.g = this.v;
- this.b = t;
- }
- if (i == 3)
- {
- this.r = p;
- this.g = q;
- this.b = this.v;
- }
- if (i == 4)
- {
- this.r = t;
- this.g = p;
- this.b = this.v;
- }
- if (i == 5)
- {
- this.r = this.v;
- this.g = p;
- this.b = q;
- }
- }
- this.space = space;
- if (space == 'RGB')
- {
- this.r = a;
- this.g = b;
- this.b = c;
- this.rgb_to_hsv();
- }
- else if (space == 'HSV')
- {
- this.h = a;
- this.s = b;
- this.v = c;
- this.hsv_to_rgb();
- }
- }
- function transition(value, maximum, start_point, end_point)
- {
- return start_point + (end_point - start_point)*value/maximum;
- }
- function transition3(value, maximum, startColor, endColor)
- {
- r1 = transition(value, maximum, startColor.h, endColor.h);
- r2 = transition(value, maximum, startColor.s, endColor.s);
- r3 = transition(value, maximum, startColor.v, endColor.v);
- return new Color( 'HSV', r1, r2, r3);
- }
- function makeDate( dstring )
- {
- // take date string in format "2012-11-01" and returns a date
- var date = dstring.split(' '); // if has time
- var ymd = date[0].split('-');
- if (ymd.length < 3) ymd.push(1); // if missing day
- return (dstring.indexOf(' ') > -1) ? new Date(ymd[0], ymd[1]-1, ymd[2], date[1].split(':')[0]) : new Date(ymd[0], ymd[1]-1, ymd[2] );
- }
- $.expr[":"].econtains = function(obj, index, meta, stack)
- {
- return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
- }
- function DaysInMonth( d )
- {
- return new Date(d.getFullYear(),d.getMonth()+1,0).getDate();
- }
- function getStartDay( d )
- {
- return new Date(d.getFullYear(), d.getMonth(), 1).getDay();
- }
});
View
3 monthly.html
@@ -25,6 +25,7 @@
<option value="16">Generation</option>
<option value="17">Usage</option>
<option value="18">Heating Degree Days</option>
+ <option value="20">Water Usage</option>
<option value="19">Base Temp Analysis</option>
</optgroup>
<optgroup label="Daily">
@@ -54,7 +55,7 @@
<div id="chart"></div>
<footer>
<p id="instructions">Turn device to toggle between calendar and chart view.</p>
- <p>&copy; netplusdesign 2012</p>
+ <p>&copy; netplusdesign 2012-2013</p>
</footer>
</div>
<script src="js/jquery-1.7.1.min.js"></script>
View
23 sql/create_home_performance_tbl.sql
@@ -1,5 +1,6 @@
CREATE TABLE energy_hourly
(
+ house_id TINYINT NOT NULL,
device_id TINYINT NOT NULL,
date DATETIME NOT NULL,
adjusted_load DECIMAL(4),
@@ -16,6 +17,7 @@ CREATE TABLE energy_hourly
CREATE TABLE energy_daily
(
+ house_id TINYINT NOT NULL,
device_id TINYINT NOT NULL,
date DATE NOT NULL,
adjusted_load DECIMAL(5,3),
@@ -32,6 +34,7 @@ CREATE TABLE energy_daily
CREATE TABLE energy_monthly
(
+ house_id TINYINT NOT NULL,
device_id TINYINT NOT NULL,
date DATE NOT NULL,
adjusted_load DECIMAL(7,3),
@@ -48,6 +51,7 @@ CREATE TABLE energy_monthly
CREATE TABLE temperature_hourly
(
+ house_id TINYINT NOT NULL,
device_id TINYINT NOT NULL,
date DATETIME NOT NULL,
temperature DECIMAL(6,3),
@@ -56,24 +60,28 @@ CREATE TABLE temperature_hourly
CREATE TABLE hdd_hourly
(
+ house_id TINYINT NOT NULL,
date DATETIME NOT NULL,
hdd DECIMAL(4,3)
);
CREATE TABLE hdd_daily
(
+ house_id TINYINT NOT NULL,
date DATE NOT NULL,
hdd DECIMAL(6,3)
);
CREATE TABLE hdd_monthly
(
+ house_id TINYINT NOT NULL,
date DATE NOT NULL,
hdd DECIMAL(7,3)
);
CREATE TABLE temperature_daily
(
+ house_id TINYINT NOT NULL,
device_id TINYINT NOT NULL,
date DATE NOT NULL,
temperature_min DECIMAL(6,3),
@@ -84,30 +92,37 @@ CREATE TABLE temperature_daily
CREATE TABLE monitor_devices
(
- device_id TINYINT NOT NULL,
- name VARCHAR(32) NOT NULL
+ device_id TINYINT NOT NULL,
+ name VARCHAR(32) NOT NULL
+);
+
+CREATE TABLE houses
+(
+ house_id TINYINT NOT NULL,
+ name VARCHAR(32) NOT NULL
);