drupal: create a water chart based on default data in case the user does not have a water sensor

This commit is contained in:
Bart Van Der Meerssche 2010-07-20 23:27:15 +00:00
parent afed061a2b
commit dfa266e3d3
1 changed files with 38 additions and 13 deletions

View File

@ -310,12 +310,19 @@ function _logger_dashboard($type, $function, $interval) {
} }
$end = ((int) (time() / $resolution)) * $resolution; $end = ((int) (time() / $resolution)) * $resolution;
$result_me = db_query("SELECT lm.meter, lm.function, lu.private, lu.electricity_unit, lu.water_unit $settings_me = db_fetch_object(db_query("SELECT private, electricity_unit, water_unit
FROM {logger_meters} lm FROM {logger_users}
INNER JOIN {logger_users} lu on lm.uid = lu.uid WHERE uid = %d", $user->uid));
WHERE lm.uid = %d AND lm.type = '%s'
ORDER BY lm.function", $user->uid, $type);
$main_me = db_fetch_object(db_query("SELECT meter, function
FROM {logger_meters}
WHERE uid = %d AND type = '%s' AND function = '%s'
ORDER BY created", $user->uid, $type, $function));
$result_me = db_query("SELECT meter, function
FROM {logger_meters}
WHERE uid = %d AND type = '%s'
ORDER BY function", $user->uid, $type);
$meter_me = db_fetch_object($result_me); $meter_me = db_fetch_object($result_me);
$result_sub = db_query("SELECT u.name, lm.meter, lu.private $result_sub = db_query("SELECT u.name, lm.meter, lu.private
@ -326,10 +333,11 @@ function _logger_dashboard($type, $function, $interval) {
INNER JOIN {logger_users} lu ON u.uid = lu.uid INNER JOIN {logger_users} lu ON u.uid = lu.uid
WHERE ur.requester_id = %d AND urt.name = '%s' AND type = '%s' AND function = '%s' WHERE ur.requester_id = %d AND urt.name = '%s' AND type = '%s' AND function = '%s'
ORDER BY ur.rid", $user->uid, 'subscription', $type, $function); ORDER BY ur.rid", $user->uid, 'subscription', $type, $function);
$meter_sub = db_fetch_object($result_sub);
switch ($type) { switch ($type) {
case 'electricity': case 'electricity':
switch ($meter_me->electricity_unit) { switch ($settings_me->electricity_unit) {
case 'watt': case 'watt':
$unit = 'watt'; $unit = 'watt';
$factor = 3600; // 1Wh/s = 3600 W $factor = 3600; // 1Wh/s = 3600 W
@ -350,7 +358,7 @@ function _logger_dashboard($type, $function, $interval) {
break; break;
case 'water': case 'water':
switch ($meter_me->water_unit) { switch ($settings_me->water_unit) {
case 'lpmin': case 'lpmin':
$unit = 'liter/min'; $unit = 'liter/min';
$factor = 6; // 1 dl/s = 6 l/min $factor = 6; // 1 dl/s = 6 l/min
@ -371,16 +379,18 @@ function _logger_dashboard($type, $function, $interval) {
$i = 0; $i = 0;
$string->line = ' COMMENT:"\s"'; $string->line = ' COMMENT:"\s"';
if (user_access('logger') && ((!$meter_sub = db_fetch_object($result_sub)) || $meter_me->private)) { if (user_access('logger') && ((!$meter_sub) || $settings_me->private) && $meter_me) {
do { do {
$string->def .= _logger_chart_def($i, $data_path, $meter_me->meter, $factor); $string->def .= _logger_chart_def($i, $data_path, $meter_me->meter, $factor);
$string->line .= _logger_chart_line($i, $color[$i], $meter_me->function); $string->line .= _logger_chart_line($i, $color[$i], $meter_me->function);
$i++; $i++;
} while ($meter_me = db_fetch_object($result_me)); } while ($meter_me = db_fetch_object($result_me));
} }
elseif (user_access('logger')) { elseif (user_access('logger') && $meter_sub && (!$settings_me->private)) {
$string->def .= _logger_chart_def($i, $data_path, $meter_me->meter, $factor); if ($main_me) {
$string->line .= _logger_chart_line($i, $color[$i], $user->name); $string->def .= _logger_chart_def($i, $data_path, $main_me->meter, $factor);
$string->line .= _logger_chart_line($i, $color[$i], $user->name);
}
do { do {
$i++; $i++;
@ -406,9 +416,24 @@ function _logger_dashboard($type, $function, $interval) {
} }
} while($meter_sub = db_fetch_object($result_sub)); } while($meter_sub = db_fetch_object($result_sub));
} }
elseif (user_access('logger')) {
$result_def = db_query("SELECT meter, function
FROM {logger_meters}
WHERE uid = %d AND type = '%s'
ORDER BY function", 1, $type);
$meter_def = db_fetch_object($result_def);
$i++;
$string->def .= _logger_chart_def($i, $data_path, $meter_def->meter, $factor);
$string->line .= _logger_chart_line($i, $color[$i], 'icarus75');
}
else { else {
$string->def .= _logger_chart_def($i, $data_path, $meter_me->meter, $factor); do {
$string->line .= _logger_chart_line($i, $color[$i], $user->name); $string->def .= _logger_chart_def($i, $data_path, $meter_me->meter, $factor);
$string->line .= _logger_chart_line($i, $color[$i], $meter_me->function);
$i++;
} while ($meter_me = db_fetch_object($result_me));
} }
//construct the TZ=GMT-02:00 format from the $user->timezone object updated by the autotimezone module //construct the TZ=GMT-02:00 format from the $user->timezone object updated by the autotimezone module