Compare commits

...

10 Commits

Author SHA1 Message Date
23e4aaefa8 Fix errors for first of month.
Some checks failed
Build power-consumtion image / Build-and-release-image (push) Failing after 2m33s
2025-04-01 08:27:25 +02:00
4cb13ebc85 Fix production view for initial display. 2025-03-31 09:51:18 +02:00
94c012cd70 Adjust production view to existing views and fix typo in month view. 2025-03-31 09:41:50 +02:00
5e2d693345 Adjust month view to year view. 2025-03-29 14:22:24 +01:00
0319687d97 Extend with yearly view. 2025-03-29 13:35:46 +01:00
01e654cd14 Get rid of PHP warnings. 2025-03-20 17:29:56 +01:00
bb9eddead7 Use slim alpine nginx fpm 8.4 image. 2025-03-20 17:15:58 +01:00
64dc995b1d Use secrets and security scan for workflow. 2025-03-20 13:59:41 +01:00
44b725a382 PHP 8 Style. 2024-05-17 12:11:01 +02:00
e85080078e Add daily production values. 2024-05-17 12:10:25 +02:00
8 changed files with 419 additions and 154 deletions

View File

@@ -1,15 +1,14 @@
name: Build power-consumption image
name: Build power-consumtion image
on:
push:
branches: [ master ]
schedule:
# Run every Sunday at midnight
- cron: '0 0 * * 0'
env:
# Use docker.io for Docker Hub if empty
REGISTRY: cs-registry.ddnss.de
USER: chris
PASS: q',\H(Od:G3).Xv<#!5P
IMAGE: /home/power-consumption
jobs:
Build-and-release-image:
@@ -26,20 +25,41 @@ jobs:
- name: Log into registry
uses: docker/login-action@v3
with:
registry: https://cs-git.ddnss.de
username: ${{ env.USER }}
password: ${{ env.PASS }}
registry: ${{ secrets.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASS }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: cs-git.ddnss.de/home/power-consumption
images: ${{ secrets.REGISTRY_URL }}${{ env.IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
env:
ACTIONS_RUNTIME_TOKEN: ''
with:
tags: cs-git.ddnss.de/home/power-consumption:latest
push: true
tags: ${{ secrets.REGISTRY_URL }}${{ env.IMAGE }}:latest
push: true
- name: Scan image
uses: anchore/scan-action@v6
id: scan
with:
image: ${{ secrets.REGISTRY_URL }}${{ env.IMAGE }}:latest
fail-build: false
output-format: table
severity-cutoff: critical
registry-username: ${{ secrets.REGISTRY_USER }}
registry-password: ${{ secrets.REGISTRY_PASS }}
grype-version: 'v0.90.0'
- name: Inspect file
run: cat ${{ steps.scan.outputs.table }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: scan-result
path: ${{ steps.scan.outputs.table }}

View File

@@ -1,13 +1,5 @@
#Use prebuilt image
FROM cs-git.ddnss.de/docker/php-apache-8-3:latest
WORKDIR /var/www/html
COPY . .
FROM cs-git.ddnss.de/docker/nginx-fpm-8-4
RUN sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
ENV SERVE_PATH=/public
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN chown -R www-data:www-data /var/www/html
VOLUME /var/www/html/config
COPY . /var/www/html

View File

@@ -22,17 +22,41 @@ function build_date_dropdown(mysqli $db, string $table): array
return $dates;
}
function get_month(mysqli $db, string $table): array
{
$date_query = 'SELECT MIN(date) AS first, MAX(date) AS last FROM ' . $table . ';';
$date = $db->query($date_query)->fetch_assoc();
$first_date = new DateTime($date['first']);
$last_date = new DateTime($date['last']);
return ['first' => $first_date, 'last' => $last_date];
}
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 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 = [];
$values['avg_meter'] = 0;
$values['avg_power'] = 0;
$values['avg_feed'] = 0;
$values['avg_production'] = 0;
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 +66,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 +146,34 @@ 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): array
{
$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;
}
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;
}

View File

@@ -58,7 +58,7 @@ for ($date_diff = $interval->days; $date_diff > 0; $date_diff--) {
$grid_feed = 0;
}
$aggregation_query = 'INSERT INTO ' . $local_table . ' (`date`, `meter_consumption`, `power_sensor`, `grid_feed`, `last_value`) VALUES ("' . $date->format('Y-m-d') . '", ' . $meter_consumption . ', ' . $power_sensor . ', ' . $grid_feed . ', ' . $consumption_end . ');';
$aggregation_query = 'INSERT INTO ' . $local_table . ' (`date`, `meter_consumption`, `power_sensor`, `grid_feed`, `last_value`, `production_eg`, `production_og`) VALUES ("' . $date->format('Y-m-d') . '", ' . $meter_consumption . ', ' . $power_sensor . ', ' . $grid_feed . ', ' . $consumption_end . ', 0, 0);';
$local_db->query($aggregation_query);
}

56
public/css/layout.css Normal file
View File

@@ -0,0 +1,56 @@
body {
font-family: sans-serif;
font-size: 1.3rem;
display: flex;
flex-direction: column;
}
input {
font-size: 1.3rem;
}
div > span {
text-align: right;
}
div.grid-container {
display: grid;
column-gap: 20px;
}
span.color-1 {
background-color: #375BEB;
}
span.color-2 {
background-color: #90EB36;
}
span.color-3 {
background-color: #EB5F36;
}
span.color-4 {
background-color: #DAE32D;
}
form > div {
display: flex;
flex-direction: row;
}
button, .button {
text-align: center;
background-color: rgb(239, 239, 239);
border: 2px outset rgb(0, 0 , 0);
text-decoration: none;
color: rgb(0, 0, 0);
font-size: 1.3rem;
padding: 8px 0;
}
#chart-container {
position: relative;
width: 95vw;
height: 95vh;
}

View File

@@ -19,8 +19,10 @@ if (isset($_POST['action']) && $_POST['action'] == 'set_values') {
$local_db->query($query);
}
$dates = build_date_dropdown($local_db, $table_aggregation);
$chosen_date = (isset($_POST['date'])) ? $_POST['date'] : $dates[0];
$actual = new DateTime();
$dates = get_month($local_db, $table_aggregation);
$chosen_date = (isset($_POST['date'])) ? $_POST['date'] : $actual->modify('-1 day')->format('Y-m');
$data = get_aggregation($local_db, $table_aggregation, $chosen_date);
$month_values = get_month_aggregation($local_db, $table_aggregation, $chosen_date);
$year_values = get_year_aggregation($local_db, $table_aggregation, $chosen_date);
@@ -29,160 +31,94 @@ $month_production = get_month_production($local_db, $table_production, $chosen_d
$year_production = get_year_production($local_db, $table_production, $chosen_date);
$last_value = get_last_value($local_db, $table_aggregation, $chosen_date);
$colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
$chosen_date_time = new DateTime($chosen_date);
?>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Consumption values</title>
<style>
body {
font-family: sans-serif;
}
label {
display: inline-block;
width: 200px;
}
span.color-1 {
background-color: <?php echo $colors[0]; ?>;
}
span.color-2 {
background-color: <?php echo $colors[1]; ?>;
}
span.color-3 {
background-color: <?php echo $colors[2]; ?>;
}
span.color-4 {
background-color: <?php echo $colors[3]; ?>;
}
span.color {
display: inline-block;
width: 40px;
height: 12px;
}
span {
display: inline-block;
width: 200px;
text-align: right;
}
#chart-container {
position: relative;
width: 80vw;
height: 70vh;
}
</style>
<link rel="stylesheet" href="/css/layout.css"/>
</head>
<body>
<form action="/index.php" method="post" style="display: inline-block;float: left; margin-right: 100px;">
<select name="date" onchange="submit();">
<?php
foreach ($dates as $date) {
$selected = ($date == $chosen_date) ? ' selected="selected"' : '';
echo '<option value="' . $date . '"' . $selected . '>' . $date . '</option>';
}
?>
</select>
<form id="date_form" style="align-self: center; width: 500px; display: grid; grid-template-columns: 20% 20% 20% 20% 20%; gap: 10px;" action="/index.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>";
} else {
echo '<span></span>';
}
echo '<span style="text-align: center">' . $chosen_date_time->modify('+1 month')->format('Y-m') . '</span>';
if ($dates['last'] > $chosen_date_time->modify('+1 month')) {
echo "<button type='button' onclick='submit_form(\"" . $chosen_date_time->format('Y-m') . "\")'>></button>";
} else {
echo '<span></span>';
}
?>
<a class="button" href="year.php">Jahr</a>
<a class="button" href="production.php">Werte</a>
<input type="hidden" name="date" id="date" value=""/>
</form>
<form action="/index.php" method="post">
<input type="hidden" name="date" value="<?php echo $chosen_date; ?>"/>
<input type="hidden" name="action" value="set_values"/>
<label style="text-align: right;" for="EG">EG</label>
<input type="number" step="0.001" name="eg" id="EG" value="<?php echo $month_production['eg']; ?>"/>
<label style="text-align: right;" for="OG">OG</label>
<input type="number" step="0.001" name="og" id="OG" value="<?php echo $month_production['og']; ?>"/>
<label style="text-align: right;" for="price">Preis</label>
<input type="number" step="0.01" name="price" id="price" value="<?php echo $month_production['price']; ?>"/>
<button type="submit">Werte setzen</button>
</form>
<div style="margin-top: 20px; font-weight: bold;">
<label>Messungen</label>
<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>
<span>Monat</span>
<span>Jahr</span>
<span>Min</span>
<span>Max</span>
<span>Durchschnitt</span>
</div>
<label><b>Messung</b></label>
<span><b>Monat</b></span>
<span><b>Jahr</b></span>
<span><b>Min</b></span>
<span><b>Max</b></span>
<span><b>Durchschnitt</b></span>
<div>
<span class="color color-1"></span>
<label>Verbrauch Zählerstand</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>
</div>
<label>Verbrauch</label>
<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>
<div>
<span class="color color-2"></span>
<label>Verbrauch 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>
</div>
<label>Berechnet</label>
<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>
<div>
<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>
</div>
<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>
<div>
<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><?php echo number_format($month_production['eg'] / count($data['date']), 3, ',', '.'); ?> kWh</span>
</div>
<label>Produktion</label>
<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>
<div style="border-bottom: 1px solid black;">
<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></span>
<span></span>
<span><?php echo number_format($month_production['og'] / count($data['date']), 3, ',', '.'); ?> kWh</span>
</div>
<div>
<span class="color"></span>
<label><b>Ersparnis</b></label>
<span><b><?php echo number_format(($month_production['eg'] + $month_production['og'] - $month_values['grid_feed']) * $month_production['price'] / 100, 2, ',', '.'); ?> €</b></span>
<span><b><?php echo number_format(($year_production['eg_price'] + $year_production['og_price'] - array_sum($grid_feed_by_month)), 2, ',', '.'); ?> €</b></span>
</div>
<span></span>
<span></span>
<span></span>
<div>
<span class="color"></span>
<label><b>Eigenverbrauch</b></label>
<span><b><?php echo ($month_production['eg'] + $month_production['og'] > 0) ? number_format(100 - $month_values['grid_feed'] * 100 / ($month_production['eg'] + $month_production['og']), 2, ',', '.') : 0; ?> %</b></span>
<span><b><?php echo number_format(100 - $year_values['grid_feed'] * 100 / ($year_production['eg'] + $year_production['og']), 2, ',', '.'); ?> %</b></span>
</div>
<span></span>
<span></span>
<span></span>
<div>
<span class="color"></span>
<label><b>Letzter Zählerstand</b></label>
<span><b><?php echo number_format($last_value, 3, ',', '.'); ?> kWh</b></span>
<label><b>Zählerstand</b></label>
<span><b><?php echo number_format($last_value, 1, ',', '.'); ?> kWh</b></span>
</div>
<div id="chart-container">
@@ -191,6 +127,12 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js"></script>
<script>
function submit_form(value) {
document.getElementById('date').value = value;
document.getElementById('date_form').submit();
}
const chart = document.getElementById('chart');
new Chart(chart, {
@@ -201,17 +143,22 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
{
label: 'Verbrauch Zählerstand',
data: <?php echo json_encode($data['meter_consumption']); ?>,
backgroundColor: '<?php echo $colors[0]; ?>',
backgroundColor: '#375BEB',
},
{
label: 'Verbrauch berechnet',
data: <?php echo json_encode($data['power_sensor']); ?>,
backgroundColor: '<?php echo $colors[1]; ?>',
backgroundColor: '#90EB36',
},
{
label: 'Einspeisung',
data: <?php echo json_encode($data['grid_feed']); ?>,
backgroundColor: '<?php echo $colors[2]; ?>',
backgroundColor: '#EB5F36',
},
{
label: 'Erzeugung',
data: <?php echo json_encode($data['production']); ?>,
backgroundColor: '#DAE32D',
}
]
},
@@ -222,4 +169,4 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
});
</script>
</body>
</html>
</html>

101
public/production.php Normal file
View File

@@ -0,0 +1,101 @@
<?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');
if (isset($_POST['action']) && $_POST['action'] == 'set_values') {
$sum_eg = 0;
$sum_og = 0;
foreach ($_POST['values'] as $key => $value) {
$update_query = 'UPDATE ' . $table_aggregation . ' SET production_eg = ' . $value['production_eg'] . ', production_og = ' . $value['production_og'] . ' WHERE `date` = "' . $key . '" LIMIT 1;';
$local_db->query($update_query);
$sum_eg += $value['production_eg'] / 1000;
$sum_og += $value['production_og'] / 1000;
}
$check_query = 'SELECT date FROM ' . $table_production . ' WHERE date = "' . $_POST['date'] . '-01";';
$check_result = $local_db->query($check_query);
if ($check_result->num_rows === 0) {
$query = 'INSERT INTO ' . $table_production . ' (date, eg, og, price) VALUES ("' . $_POST['date'] . '-01", ' . $sum_eg . ', ' . $sum_og . ', ' . $_POST['price'] . ');';
} else {
$query = 'UPDATE ' . $table_production . ' SET eg = "' . $sum_eg . '", og = "' . $sum_og . '", price = "' . $_POST['price'] . '" WHERE date = "' . $_POST['date'] . '-01";';
}
$local_db->query($query);
}
$actual = new DateTime();
$dates = get_month($local_db, $table_aggregation);
$chosen_date = (isset($_POST['date'])) ? $_POST['date'] : $actual->modify('-1 day')->format('Y-m');
$production_values = get_production_values_for_month($local_db, $table_aggregation, $chosen_date);
$month_production = get_month_production($local_db, $table_production, $chosen_date);
$chosen_date_time = new DateTime($chosen_date);
?>
<!DOCTYPE html>
<html lang="de">
<head>
<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">
<?php
if ($dates['first'] < $chosen_date_time) {
echo "<button type='button' onclick='submit_form(\"" . $chosen_date_time->modify('-1 month')->format('Y-m') . "\")'><</button>";
} else {
echo '<span></span>';
}
echo '<span style="text-align: center">' . $chosen_date_time->modify('+1 month')->format('Y-m') . '</span>';
if ($dates['last'] > $chosen_date_time->modify('+1 month')) {
echo "<button type='button' onclick='submit_form(\"" . $chosen_date_time->format('Y-m') . "\")'>></button>";
} else {
echo '<span></span>';
}
?>
<a class="button" href="index.php">Monat</a>
<a class="button" href="year.php">Jahr</a>
<input type="hidden" name="date" id="date" value=""/>
</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;">
<?php
foreach ($production_values as $daily_production) {
?>
<span><?php echo $daily_production['date']; ?></span>
<label style="text-align: right;" for="production_eg[<?php echo $daily_production['date']; ?>]">EG</label>
<input type="number" step="0.01" name="values[<?php echo $daily_production['date']; ?>][production_eg]"
id="production_eg[<?php echo $daily_production['date']; ?>]"
value="<?php echo $daily_production['production_eg']; ?>"/>
<label style="text-align: right;" for="production_og[<?php echo $daily_production['date']; ?>]">OG</label>
<input type="number" step="0.01" name="values[<?php echo $daily_production['date']; ?>][production_og]"
id="production_og[<?php echo $daily_production['date']; ?>]"
value="<?php echo $daily_production['production_og']; ?>"/>
<?php
}
?>
<span>Preis</span>
<label style="text-align: right;">Cent / kWh</label>
<input type="number" step="0.01" name="price" value="<?php echo $month_production['price']; ?>"/>
<span></span>
<button type="submit">Speichern</button>
<input type="hidden" name="action" value="set_values"/>
<input type="hidden" name="date" value="<?php echo $chosen_date; ?>"/>
</form>
<script>
function submit_form(value) {
document.getElementById('date').value = value;
document.getElementById('date_form').submit();
}
</script>
</body>
</html>

91
public/year.php Normal file
View File

@@ -0,0 +1,91 @@
<?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: 20% 20% 20% 20% 20%; gap: 10px;"
action="/year.php"
method="post">
<?php
if ($years['first'] < $chosen_year) {
echo "<button type='button' onclick='submit_form(" . $chosen_year - 1 . ")'><</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>';
}
?>
<a class="button" href="index.php">Monat</a>
<a class="button" href="production.php">Werte</a>
<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>