Add daily production values.
This commit is contained in:
@@ -24,15 +24,17 @@ function build_date_dropdown(mysqli $db, string $table): array
|
||||
|
||||
function get_aggregation(mysqli $db, string $table, $date): array
|
||||
{
|
||||
$value_query = 'SELECT date, meter_consumption, power_sensor, grid_feed FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
||||
$value_query = 'SELECT date, meter_consumption, power_sensor, grid_feed, production_eg, production_og FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
||||
$value_result = $db->query($value_query);
|
||||
|
||||
$values = [];
|
||||
while ($row = $value_result->fetch_assoc()) {
|
||||
$production = ($row['production_eg'] + $row['production_og']);
|
||||
$values['date'][] = $row['date'];
|
||||
$values['meter_consumption'][] = $row['meter_consumption'];
|
||||
$values['power_sensor'][] = $row['power_sensor'];
|
||||
$values['grid_feed'][] = $row['grid_feed'];
|
||||
$values['production'][] = $production;
|
||||
$values['min_meter'] = (isset($values['min_meter']) && $values['min_meter'] < $row['meter_consumption']) ? $values['min_meter'] : $row['meter_consumption'];
|
||||
$values['max_meter'] = (isset($values['max_meter']) && $values['max_meter'] > $row['meter_consumption']) ? $values['max_meter'] : $row['meter_consumption'];
|
||||
$values['avg_meter'] += $row['meter_consumption'];
|
||||
@@ -42,11 +44,15 @@ function get_aggregation(mysqli $db, string $table, $date): array
|
||||
$values['min_feed'] = (isset($values['min_feed']) && $values['min_feed'] < $row['grid_feed']) ? $values['min_feed'] : $row['grid_feed'];
|
||||
$values['max_feed'] = (isset($values['max_feed']) && $values['max_feed'] > $row['grid_feed']) ? $values['max_feed'] : $row['grid_feed'];
|
||||
$values['avg_feed'] += $row['grid_feed'];
|
||||
$values['min_production'] = (isset($values['min_production']) && $values['min_production'] < $production) ? $values['min_production'] : $production;
|
||||
$values['max_production'] = (isset($values['max_production']) && $values['max_production'] > $production) ? $values['max_production'] : $production;
|
||||
$values['avg_production'] += $production;
|
||||
}
|
||||
|
||||
$values['avg_meter'] /= count($values['meter_consumption']);
|
||||
$values['avg_power'] /= count($values['power_sensor']);
|
||||
$values['avg_feed'] /= count($values['grid_feed']);
|
||||
$values['avg_production'] /= count($values['production']);
|
||||
|
||||
return $values;
|
||||
}
|
||||
@@ -118,4 +124,17 @@ function get_last_value(mysqli $db, string $table, $date): float
|
||||
$data = $value_result->fetch_assoc();
|
||||
|
||||
return floatval($data['last_value']) / 1000;
|
||||
}
|
||||
|
||||
function get_production_values_for_month(mysqli $db, string $table, $date)
|
||||
{
|
||||
$value_query = 'SELECT date, production_og, production_eg FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
||||
$value_result = $db->query($value_query);
|
||||
$production_values = [];
|
||||
|
||||
while ($row = $value_result->fetch_assoc()) {
|
||||
$production_values[] = $row;
|
||||
}
|
||||
|
||||
return $production_values;
|
||||
}
|
||||
Reference in New Issue
Block a user