diff --git a/api/beestat.sql b/api/beestat.sql index fc2750e..6a8732b 100644 --- a/api/beestat.sql +++ b/api/beestat.sql @@ -491,10 +491,10 @@ CREATE TABLE `runtime_thermostat_summary` ( `sum_economizer` mediumint unsigned NOT NULL, `sum_heating_degree_days` smallint unsigned NOT NULL, `sum_cooling_degree_days` smallint unsigned NOT NULL, - `avg_outdoor_temperature` smallint NOT NULL, - `avg_outdoor_humidity` tinyint unsigned NOT NULL, - `min_outdoor_temperature` smallint NOT NULL, - `max_outdoor_temperature` smallint NOT NULL, + `avg_outdoor_temperature` smallint NULL, + `avg_outdoor_humidity` tinyint unsigned NULL, + `min_outdoor_temperature` smallint NULL, + `max_outdoor_temperature` smallint NULL, `avg_indoor_temperature` smallint NOT NULL, `avg_indoor_humidity` tinyint unsigned NOT NULL, `deleted` tinyint(1) NOT NULL DEFAULT '0', diff --git a/api/runtime_thermostat_summary.php b/api/runtime_thermostat_summary.php index 43b0b58..d9c0168 100755 --- a/api/runtime_thermostat_summary.php +++ b/api/runtime_thermostat_summary.php @@ -257,13 +257,20 @@ class runtime_thermostat_summary extends cora\crud { ]; } - $runtime_thermostat['outdoor_temperature'] *= 10; + if($runtime_thermostat['outdoor_temperature'] !== null) { + $runtime_thermostat['outdoor_temperature'] *= 10; + } + $runtime_thermostat['indoor_temperature'] *= 10; $data[$date]['count']++; $data[$date]['sum_fan'] += $runtime_thermostat['fan']; - $data[$date]['min_outdoor_temperature'] = min($runtime_thermostat['outdoor_temperature'], $data[$date]['min_outdoor_temperature']); - $data[$date]['max_outdoor_temperature'] = max($runtime_thermostat['outdoor_temperature'], $data[$date]['max_outdoor_temperature']); + + if ($runtime_thermostat['outdoor_temperature'] !== null) { + $data[$date]['min_outdoor_temperature'] = min($runtime_thermostat['outdoor_temperature'], $data[$date]['min_outdoor_temperature']); + $data[$date]['max_outdoor_temperature'] = max($runtime_thermostat['outdoor_temperature'], $data[$date]['max_outdoor_temperature']); + } + $data[$date]['sum_auxiliary_heat_1'] += $runtime_thermostat['auxiliary_heat_1']; $data[$date]['sum_auxiliary_heat_2'] += $runtime_thermostat['auxiliary_heat_2']; @@ -314,8 +321,26 @@ class runtime_thermostat_summary extends cora\crud { // Write to the database. foreach($data as $date => &$row) { - $row['avg_outdoor_temperature'] = round(array_sum($row['avg_outdoor_temperature']) / count($row['avg_outdoor_temperature'])); - $row['avg_outdoor_humidity'] = round(array_sum($row['avg_outdoor_humidity']) / count($row['avg_outdoor_humidity'])); + if (count($row['avg_outdoor_temperature']) > 0) { + $row['avg_outdoor_temperature'] = round(array_sum($row['avg_outdoor_temperature']) / count($row['avg_outdoor_temperature'])); + } else { + $row['avg_outdoor_temperature'] = null; + } + + if (count($row['avg_outdoor_humidity']) > 0) { + $row['avg_outdoor_humidity'] = round(array_sum($row['avg_outdoor_humidity']) / count($row['avg_outdoor_humidity'])); + } else { + $row['avg_outdoor_humidity'] = null; + } + + if ($row['min_outdoor_temperature'] === INF) { + $row['min_outdoor_temperature'] = null; + } + + if ($row['max_outdoor_temperature'] === -INF) { + $row['max_outdoor_temperature'] = null; + } + $row['avg_indoor_temperature'] = round(array_sum($row['avg_indoor_temperature']) / count($row['avg_indoor_temperature'])); $row['avg_indoor_humidity'] = round(array_sum($row['avg_indoor_humidity']) / count($row['avg_indoor_humidity']));