Change some styling. Fix undefined array_key in functions and show overview values in yearly view.
Some checks failed
Build power-consumtion image / Build-and-release-image (push) Failing after 26s

This commit is contained in:
2025-10-15 17:56:51 +02:00
parent 46e24640b5
commit 9f72a69347
4 changed files with 45 additions and 8 deletions

View File

@@ -106,14 +106,15 @@ function get_grid_feed_by_month(mysqli $db, string $table_aggregation, string $t
$price_result = $db->query($price_query);
$price = [];
while ($row = $price_result->fetch_assoc()) {
$price[$row['year'] . '-' . str_pad($row['month'], 2, '0', STR_PAD_LEFT)] = $row['price'];
while ($price_row = $price_result->fetch_assoc()) {
$price[$price_row['year'] . '-' . str_pad($price_row['month'], 2, '0', STR_PAD_LEFT)] = $price_row['price'];
}
$grid_feed_by_month = [];
while ($row = $feed_result->fetch_assoc()) {
$grid_feed_by_month[$row['year'] . '-' . str_pad($row['month'], 2, '0', STR_PAD_LEFT)] = $row['SUM(grid_feed)'] * $price[$row['year'] . '-' . str_pad($row['month'], 2, '0', STR_PAD_LEFT)] / 100000;
$key = $row['year'] . '-' . str_pad($row['month'], 2, '0', STR_PAD_LEFT);
$price[$key] = $price[$key] ?? 0;
$grid_feed_by_month[$key] = $row['SUM(grid_feed)'] * $price[$key] / 100000;
}
return $grid_feed_by_month;

View File

@@ -47,6 +47,7 @@ button, .button {
color: rgb(0, 0, 0);
font-size: 1.3rem;
padding: 8px 0;
cursor: pointer;
}
#chart-container {

View File

@@ -45,11 +45,11 @@ $chosen_date_time = new DateTime($chosen_date);
<title>Consumption values</title>
<link rel="stylesheet" href="/css/layout.css"/>
</head>
<body>
<form id="date_form" style="align-self: center; width: 500px; display: grid; grid-template-columns: 20% 20% 20% 20% 20%; gap: 10px;" action="/production.php" method="post">
<body style="max-width: 1000px; align-self: center; margin: 0 auto;">
<form id="date_form" style="display: grid; grid-template-columns: 20% 20% 20% 20% 20%; gap: 10px;" action="/production.php" method="post">
<?php
if ($dates['first'] < $chosen_date_time) {
echo "<button type='button' onclick='submit_form(\"" . $chosen_date_time->modify('-1 month')->format('Y-m') . "\")'><</button>";
echo "<button type='button' onclick='submit_form(\"" . $chosen_date_time->modify('-1 month')->format('Y-m') . "\")'><</button>\n";
} else {
echo '<span></span>';
}
@@ -66,7 +66,7 @@ $chosen_date_time = new DateTime($chosen_date);
</form>
<form action="production.php" method="post"
style="display: grid; grid-template-columns: 15% 12% 10% 10% 12%; gap: 2px 10px; margin-top: 10px; font-size: 1.3rem;">
style="display: grid; grid-template-columns: 20% 20% 20% 20% 20%; gap: 2px 10px; margin-top: 10px; font-size: 1.3rem; border-top: 2px solid gray; padding-top: 20px;">
<?php
foreach ($production_values as $daily_production) {
?>

View File

@@ -11,6 +11,10 @@ $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);
$aggregation = get_year_aggregation($local_db, $table_aggregation, $chosen_year);
$year_production = get_year_production($local_db, $table_production, $chosen_year);
$grid_feed_by_month = get_grid_feed_by_month($local_db, $table_aggregation, $table_production, $chosen_year);
?>
<!DOCTYPE html>
<html lang="de">
@@ -41,6 +45,37 @@ $values = get_year_values($local_db, $table_aggregation, $chosen_year);
<a class="button" href="production.php">Werte</a>
<input type="hidden" name="year" id="year" value=""/>
</form>
<div style="display: grid; grid-template-columns: 5% 15% 15%; gap: 2px 10px; margin-top: 5px; border-top: 2px solid gray; padding-top: 5px;">
<span class="color"></span>
<label><b>Messung</b></label>
<span><b>Jahr</b></span>
<span class="color color-1"></span>
<label>Verbrauch</label>
<span><?php echo number_format($aggregation['meter_consumption'], 1, ',', '.'); ?> KWh</span>
<span class="color color-2"></span>
<label>Berechnet</label>
<span><?php echo number_format($aggregation['power_sensor'], 1, ',', '.'); ?> KWh</span>
<span class="color color-3"></span>
<label>Einspeisung</label>
<span><?php echo number_format($aggregation['grid_feed'], 1, ',', '.'); ?> KWh</span>
<span class="color color-4"></span>
<label>Produktion</label>
<span><?php echo number_format($year_production['eg'] + $year_production['og'], 1, ',', '.'); ?> KWh</span>
<span class="color"></span>
<label><b>Ersparnis</b></label>
<span><b><?php echo number_format(($year_production['eg_price'] + $year_production['og_price'] - array_sum($grid_feed_by_month)), 2, ',', '.'); ?> €</b></span>
<span class="color"></span>
<label><b>Eigenverbrauch</b></label>
<span><b><?php echo number_format(100 - $aggregation['grid_feed'] * 100 / ($year_production['eg'] + $year_production['og']), 2, ',', '.'); ?> %</b></span>
</div>
<div id="chart-container">
<canvas id="chart"></canvas>
</div>