diff --git a/functions/functions.php b/functions/functions.php index 01a1dd1..78278a1 100644 --- a/functions/functions.php +++ b/functions/functions.php @@ -24,15 +24,17 @@ function build_date_dropdown(mysqli $db, string $table): array 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 = []; 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 +44,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 +124,17 @@ 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) +{ + $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; } \ No newline at end of file diff --git a/jobs/aggregate.php b/jobs/aggregate.php index b5bc4af..9028c56 100644 --- a/jobs/aggregate.php +++ b/jobs/aggregate.php @@ -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); } diff --git a/public/css/layout.css b/public/css/layout.css new file mode 100644 index 0000000..32e3640 --- /dev/null +++ b/public/css/layout.css @@ -0,0 +1,49 @@ +body { + font-family: sans-serif; + display: flex; + flex-direction: column; +} + +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 { + text-align: center; + background-color: rgb(239, 239, 239); + border: 2px outset rgb(0, 0 , 0); + text-decoration: none; + color: rgb(0, 0, 0); +} + +#chart-container { + position: relative; + width: 95vw; + height: 95vh; +} diff --git a/public/index.php b/public/index.php index 4eef287..509e31e 100644 --- a/public/index.php +++ b/public/index.php @@ -29,61 +29,17 @@ $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']; - ?>