Add last meter consumption value.

This commit is contained in:
2024-05-04 11:46:42 +02:00
parent f626eb245d
commit c8001590cf
2 changed files with 16 additions and 0 deletions

View File

@@ -109,4 +109,13 @@ function get_year_production(mysqli $db, string $table, $date): array
$sum_result = $db->query($sum_query);
return $sum_result->fetch_assoc();
}
function get_last_value(mysqli $db, string $table, $date): float
{
$value_query = 'SELECT last_value FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date DESC LIMIT 1;';
$value_result = $db->query($value_query);
$data = $value_result->fetch_assoc();
return floatval($data['last_value']) / 1000;
}

View File

@@ -27,6 +27,7 @@ $year_values = get_year_aggregation($local_db, $table_aggregation, $chosen_date)
$grid_feed_by_month = get_grid_feed_by_month($local_db, $table_aggregation, $table_production, $chosen_date);
$month_production = get_month_production($local_db, $table_production, $chosen_date);
$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'];
@@ -178,6 +179,12 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
<span><b><?php echo number_format(100 - $year_values['grid_feed'] * 100 / ($year_production['eg'] + $year_production['og']), 2, ',', '.'); ?> %</b></span>
</div>
<div>
<span class="color"></span>
<label><b>Letzter Zählerstand</b></label>
<span><b><?php echo number_format($last_value, 3, ',', '.'); ?> %</b></span>
</div>
<div id="chart-container">
<canvas id="chart"></canvas>
</div>