date("Y")){ exit; } if(isset($_GET["type"])){ if(strtolower($_GET["type"]) =="lastyear"){ $_GET["year"] = date("Y")-1; }elseif(strtolower($_GET["type"]) =="prelastyear"){ $_GET["year"] = date("Y")-2; } } $Query = "SELECT SUM(gridPcons/12000) as 'Stromverbrauch', SUM((gridPcons*cost)/12000)+140 as 'Stromkosten (140€ fix)', SUM(pvP - IF(gridP < 0, -gridP,0) - IF(battP < 0, -battP,0)- heaterPwr + IF(battP > 0, battP,0))*cost/12000 as 'Verbrauchsersparnis', SUM((gridPfeed*gain)/12000) as 'Einspeisevergütung', SUM(IF(gridP < 500, heaterPwr, 0)*0.063/12000) as 'Ersparnis Heizung', SUM(IF(battP > 0, battP, 0)*cost/12000) as 'Ersparnis Batterie', AVG(autonomy) AS 'Ø Autarkie', (SUM(PL1_EV+PL2_EV+PL3_EV))/12 AS 'Autoladung ges. EG', (((SUM(IF(gridP>100,0,PL1_EV+PL2_EV+PL3_EV)))/(SUM(PL1_EV+PL2_EV+PL3_EV))))*100 AS 'Autoladung Solar EG', (SUM(IF(gridP>100,0,(PL1_EV+PL2_EV+PL3_EV)*cost))/12) AS 'Ersparnis Solarladung EG', (SUM(PL1_EV+PL2_EV+PL3_EV))/24.5 AS 'Benzin gespart EG', (SUM(PL1_EVog+PL2_EVog+PL3_EVog))/12 AS 'Autoladung ges. OG', (((SUM(IF(gridP>100,0,PL1_EVog+PL2_EVog+PL3_EVog)))/(SUM(PL1_EVog+PL2_EVog+PL3_EVog))))*100 AS 'Autoladung Solar OG', (SUM(IF(gridP>100,0,(PL1_EVog+PL2_EVog+PL3_EVog)*cost))/12) AS 'Ersparnis Solarladung OG', (SUM(PL1_EVog+PL2_EVog+PL3_EVog))/24.5 AS 'Benzin gespart OG' FROM EnergyFlow JOIN gridCosts ON DATE(datetime) >= DATE(gridCosts.active_date) AND DATE(datetime) <= DATE(gridCosts.end_date) WHERE year(datetime) = ".$_GET["year"].";"; $PrevQuery = "SELECT SUM(gridPcons/12000) as 'Stromverbrauch', SUM((gridPcons*cost)/12000)+140 as 'Stromkosten (140€ fix)', SUM(pvP - IF(gridP < 0, -gridP,0) - IF(battP < 0, -battP,0)- heaterPwr + IF(battP > 0, battP,0))*cost/12000 as 'Verbrauchsersparnis', SUM((gridPfeed*gain)/12000) as 'Einspeisevergütung', SUM(IF(gridP < 500, heaterPwr, 0)*0.063/12000) as 'Ersparnis Heizung', SUM(IF(battP > 0, battP, 0)*cost/12000) as 'Ersparnis Batterie', AVG(autonomy) AS 'Ø Autarkie', (SUM(PL1_EV+PL2_EV+PL3_EV))/12 AS 'Autoladung ges. EG', (((SUM(IF(gridP>100,0,PL1_EV+PL2_EV+PL3_EV)))/(SUM(PL1_EV+PL2_EV+PL3_EV))))*100 AS 'Autoladung Solar EG', (SUM(IF(gridP>100,0,(PL1_EV+PL2_EV+PL3_EV)*cost))/12) AS 'Ersparnis Solarladung EG', (SUM(PL1_EV+PL2_EV+PL3_EV))/24.5 AS 'Benzin gespart EG', (SUM(PL1_EVog+PL2_EVog+PL3_EVog))/12 AS 'Autoladung ges. OG', (((SUM(IF(gridP>100,0,PL1_EVog+PL2_EVog+PL3_EVog)))/(SUM(PL1_EVog+PL2_EVog+PL3_EVog))))*100 AS 'Autoladung Solar OG', (SUM(IF(gridP>100,0,(PL1_EVog+PL2_EVog+PL3_EVog)*cost))/12) AS 'Ersparnis Solarladung OG', (SUM(PL1_EVog+PL2_EVog+PL3_EVog))/24.5 AS 'Benzin gespart OG' FROM EnergyFlow JOIN gridCosts ON DATE(datetime) >= DATE(gridCosts.active_date) AND DATE(datetime) <= DATE(gridCosts.end_date) WHERE year(datetime) = ".($_GET["year"]-1).";"; $units = Array("kWh","€","€","€","€","€","€","%","kWh","%","€","L","kWh","%","€","L"); $LessIsBetter = Array(true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false); function array_insert($array,$values,$offset) { return array_slice($array, 0, $offset, true) + $values + array_slice($array, $offset, NULL, true); } if (checkLogin()) { $html = "
"; $mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB); $Res = mysqli_query($mysql,$Query); $ResPrev = mysqli_query($mysql,$PrevQuery); if(!$Res || !$ResPrev){ echo "Error:
".mysqli_error($mysql)."
"; } if ($Res->num_rows > 0) { $i = 0; $row = $Res->fetch_assoc(); $rowPrev = $ResPrev->fetch_assoc(); //$row["Vergütung+Einsparung Strom"] = $row["Einspeisevergütung"]+$row["Verbrauchsersparnis"]; $row = array_insert($row,["Verg.+Einsp. Strom" => $row["Einspeisevergütung"]+$row["Verbrauchsersparnis"]],4); $rowPrev = array_insert($rowPrev,["Verg.+Einsp. Strom" => $rowPrev["Einspeisevergütung"]+$rowPrev["Verbrauchsersparnis"]],4); $i = 0; foreach ($row as $name => $value) { if(str_starts_with($name,"Autoladung ges.")){ $html .= "

"; $html .= "
"; } /*$html .= "
".$name." ". number_format(floatval($value),2,",",".") ."".$units[$i++]."
";*/ $html .= "
".$name."
"; $i++; } } $html .= "
"; } //header('Content-Type: application/json'); echo $html; //echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';