Extend with yearly view.
This commit is contained in:
@@ -22,6 +22,13 @@ function build_date_dropdown(mysqli $db, string $table): array
|
||||
return $dates;
|
||||
}
|
||||
|
||||
function get_years(mysqli $db, string $table): array
|
||||
{
|
||||
$years_query = 'SELECT MIN(YEAR(date)) AS first, MAX(YEAR(date)) AS last FROM ' . $table . ';';
|
||||
|
||||
return $db->query($years_query)->fetch_assoc();
|
||||
}
|
||||
|
||||
function get_aggregation(mysqli $db, string $table, $date): array
|
||||
{
|
||||
$value_query = 'SELECT date, meter_consumption, power_sensor, grid_feed, production_eg, production_og FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
||||
@@ -141,4 +148,21 @@ function get_production_values_for_month(mysqli $db, string $table, $date): arra
|
||||
}
|
||||
|
||||
return $production_values;
|
||||
}
|
||||
|
||||
function get_year_values(mysqli $db, string $table, $year): array
|
||||
{
|
||||
$query = 'SELECT MONTH(date) AS month, ROUND(SUM(meter_consumption / 1000)) AS meter_consumption, ROUND(SUM(power_sensor / 1000)) as power_sensor, ROUND(SUM(grid_feed / 1000)) as grid_feed, ROUND(SUM(production_og + production_eg) / 1000) AS production FROM ' . $table . ' WHERE YEAR(date) = ' . $year . ' GROUP BY MONTH(date) ORDER BY MONTH(date);';
|
||||
$result = $db->query($query);
|
||||
$values = [];
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$values['date'][] = $row['month'];
|
||||
$values['meter_consumption'][] = $row['meter_consumption'];
|
||||
$values['power_sensor'][] = $row['power_sensor'];
|
||||
$values['grid_feed'][] = $row['grid_feed'];
|
||||
$values['production'][] = $row['production'];
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
Reference in New Issue
Block a user