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;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ $last_value = get_last_value($local_db, $table_aggregation, $chosen_date);
|
||||
<link rel="stylesheet" href="/css/layout.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<form style="display: grid; grid-template-columns: 5% 5% 20% 5%; gap: 10px;" action="/index.php" method="post">
|
||||
<form style="display: grid; grid-template-columns: 5% 5% 20% 5% 5%; gap: 10px;" action="/index.php" method="post">
|
||||
<label for="date">Datum</label>
|
||||
<select name="date" id="date" onchange="submit();">
|
||||
<?php
|
||||
@@ -49,11 +49,12 @@ $last_value = get_last_value($local_db, $table_aggregation, $chosen_date);
|
||||
</select>
|
||||
<span></span>
|
||||
<a class="button" href="production.php">Werte setzen</a>
|
||||
<a class="button" href="year.php">Jahresübersicht</a>
|
||||
</form>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 5% 15% 15% 15% 15% 15% 15%; gap: 2px 10px; margin-top: 5px; border-top: 2px solid gray; padding-top: 5px;">
|
||||
<span class="color"></span>
|
||||
<label><b>Messungen</b></label>
|
||||
<label><b>Messung</b></label>
|
||||
<span><b>Monat</b></span>
|
||||
<span><b>Jahr</b></span>
|
||||
<span><b>Min</b></span>
|
||||
@@ -62,43 +63,35 @@ $last_value = get_last_value($local_db, $table_aggregation, $chosen_date);
|
||||
|
||||
<span class="color color-1"></span>
|
||||
<label>Verbrauch</label>
|
||||
<span><?php echo number_format($month_values['meter_consumption'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_values['meter_consumption'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($month_values['meter_consumption'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_values['meter_consumption'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_meter'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_meter'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_meter'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
|
||||
<span class="color color-2"></span>
|
||||
<label>Berechnet</label>
|
||||
<span><?php echo number_format($month_values['power_sensor'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_values['power_sensor'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($month_values['power_sensor'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_values['power_sensor'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_power'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_power'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_power'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
|
||||
<span class="color color-3"></span>
|
||||
<label>Einspeisung</label>
|
||||
<span><?php echo number_format($month_values['grid_feed'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_values['grid_feed'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
|
||||
<span class="color color-4"></span>
|
||||
<label>Produktion EG</label>
|
||||
<span><?php echo number_format($month_production['eg'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_production['eg'], 3, ',', '.'); ?> KWh</span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span><?php echo number_format($month_values['grid_feed'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_values['grid_feed'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_feed'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_feed'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_feed'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
|
||||
<span class="color color-4"></span>
|
||||
<label>Produktion OG</label>
|
||||
<span><?php echo number_format($month_production['og'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_production['og'], 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_production'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_production'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_production'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($month_production['eg'] + $month_production['og'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($year_production['eg'] + $year_production['og'], 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['min_production'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['max_production'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
<span><?php echo number_format($data['avg_production'] / 1000, 1, ',', '.'); ?> KWh</span>
|
||||
|
||||
<span class="color"></span>
|
||||
<label><b>Ersparnis</b></label>
|
||||
|
||||
90
public/year.php
Normal file
90
public/year.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
$app = require(__DIR__ . '/../bootstrap.php');
|
||||
$local_db = $app['local_db'];
|
||||
$table_aggregation = $app['config']['local']['table_aggregation'];
|
||||
$table_production = $app['config']['local']['table_production'];
|
||||
|
||||
require_once(__DIR__ . '/../functions/functions.php');
|
||||
|
||||
$chosen_year = (isset($_POST['year'])) ? $_POST['year'] : date('Y');
|
||||
$years = get_years($local_db, $table_aggregation);
|
||||
$values = get_year_values($local_db, $table_aggregation, $chosen_year);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<title>Consumption values</title>
|
||||
<link rel="stylesheet" href="/css/layout.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form id="year_form"
|
||||
style="align-self: center; width: 500px; display: grid; grid-template-columns: 25% 25% 25% 25%; gap: 10px;"
|
||||
action="/year.php"
|
||||
method="post">
|
||||
<a class="button" href="index.php">Monatsübersicht</a>
|
||||
<?php
|
||||
if ($years['first'] < $chosen_year) {
|
||||
echo "<button type='button' onclick='submit_form(2024)'><</button>";
|
||||
} else {
|
||||
echo '<span></span>';
|
||||
}
|
||||
echo '<span style="text-align: center">' . $chosen_year . '</span>';
|
||||
if ($years['last'] > $chosen_year) {
|
||||
echo "<button type='button' onclick='submit_form(" . $chosen_year + 1 . ")'>></button>";
|
||||
} else {
|
||||
echo '<span></span>';
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="year" id="year" value=""/>
|
||||
</form>
|
||||
<div id="chart-container">
|
||||
<canvas id="chart"></canvas>
|
||||
</div>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js"></script>
|
||||
<script>
|
||||
function submit_form(value) {
|
||||
document.getElementById('year').value = value;
|
||||
document.getElementById('year_form').submit();
|
||||
}
|
||||
|
||||
const chart = document.getElementById('chart');
|
||||
|
||||
new Chart(chart, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: <?php echo json_encode($values['date']); ?>,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Verbrauch Zählerstand',
|
||||
data: <?php echo json_encode($values['meter_consumption']); ?>,
|
||||
backgroundColor: '#375BEB',
|
||||
},
|
||||
{
|
||||
label: 'Verbrauch berechnet',
|
||||
data: <?php echo json_encode($values['power_sensor']); ?>,
|
||||
backgroundColor: '#90EB36',
|
||||
},
|
||||
{
|
||||
label: 'Einspeisung',
|
||||
data: <?php echo json_encode($values['grid_feed']); ?>,
|
||||
backgroundColor: '#EB5F36',
|
||||
},
|
||||
{
|
||||
label: 'Erzeugung',
|
||||
data: <?php echo json_encode($values['production']); ?>,
|
||||
backgroundColor: '#DAE32D',
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
aspectRatio: 2,
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user