????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.37 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/appsrv.astacus.se/rock_backup/ |
Upload File : |
<?php
include 'setup.php';
$TEXT = "";
$mysqli = new mysqli("www.astacus.se", "carlhoffstedt", "Astacus2020!", "energicontrol");
$sql = "SELECT * FROM tblAstacusMetricUnits WHERE Ethernet = '".$ethernet."'";
$result = $mysqli->query($sql);
while($obj = $result->fetch_object()){
$wanted_temp = $obj->Wanted_temp;
$minimum_temp = $obj->Minimum_temp;
$percent_save = $obj->PercentSave;
}
$timeSeries = array();
for ($i = 0; $i < 24; $i++) {
$h = 18 - date("H") + $i;
$time = date("Y-m-d\TH:00:00\Z", strtotime("+".$h." hours"));
$timeSeries[] = $time;
}
$hours = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1); // Last one is set to 1, otherwise loop doesnt work if last hour is 0
$average_price = 0;
$from = date("Y-m-d",strtotime("0 days"))."T18:00:00Z";
$to = date("Y-m-d",strtotime("1 days"))."T17:00:00Z";
// found what is average price
$date_from30 = "startTime >= '".date('Y-m-d',strtotime("-30 days"))."'";
$sql = "SELECT * FROM tblNordpool WHERE $date_from30 and area = 'SE3' order by startTime";
$result = $mysqli->query($sql);
$sum = 0;
$x = 0;
while($obj = $result->fetch_object()){
$price = ($obj->value)/(1000*1);
$sum += $price;
$x++;
}
$average_price = $sum/$x;
///////////
// Find what cooling and heating cofficent is
$from1 = date("Y-m-d",strtotime("0 days"))." 18:00:00";
$to1 = date("Y-m-d",strtotime("1 days"))." 17:00:00";
$today = date("Y-m-d",strtotime("0 days"));
$sql = "SELECT * FROM tblForcast WHERE timeSeries >= '".$from1."' and timeSeries <= '".$to1."' and enteryDate = '".$today."' group by timeSeries order by timeSeries";
$result = $mysqli->query($sql);
$x = 0;
$t_effektiv = 0;
$ws = 0;
while($obj = $result->fetch_object()){
$t_effektiv += $obj->t_effektiv;
$ws += $obj->ws;
$x++;
}
$t_effektiv = $t_effektiv / $x;
$ws = $ws / $x;
echo("<br>".$sql."<br>");
$myvalue = $t_effektiv;
$from_ = date("Y-m-d\TH:00:00", strtotime("-7 days"));
$sql = "select (TempChange) as TempChange from tblEnergyLog2 OutsideTempWind WHERE Direction = 'Down' and TimeDate >= '$from_' order by abs(OutsideTempWind + (".$myvalue.")) desc LIMIT 1";
$indoor_temp_drop_per_hour = 0;
$result = $mysqli->query($sql);
while($obj = $result->fetch_object()){
$indoor_temp_drop_per_hour = $obj->TempChange * 1.25; // Test
}
echo("<br>".$sql."<br>");
$sql = "select (TempChange) as TempChange from tblEnergyLog2 OutsideTempWind WHERE Direction = 'Up' and TimeDate >= '$from_' order by abs(OutsideTempWind + (".$myvalue.")) desc LIMIT 1";
$indoor_temp_increase_per_hour = 0;
$result = $mysqli->query($sql);
while($obj = $result->fetch_object()){
$indoor_temp_increase_per_hour = $obj->TempChange * 0.75;; // Test
}
echo("<br>".$sql."<br>");
if($indoor_temp_drop_per_hour == 0){
$indoor_temp_drop_per_hour = 0.300;
}
if($indoor_temp_increase_per_hour == 0){
$indoor_temp_increase_per_hour = 0.300;
}
$TEXT .= "Indoor temp drop is: $indoor_temp_drop_per_hour<br>";
$TEXT .= "Indoor temp increase is: $indoor_temp_increase_per_hour<br><br>";
$low_price = $average_price * $percent_save;
$sql = "SELECT * FROM tblNordpool WHERE startTime >= '".$from."' and startTime <= '".$to."' and area = 'SE3' order by startTime";
echo("<br>".$sql."<br>");
$result = $mysqli->query($sql);
$TEXT .= "Average price for the latest 30 days is: ".round($average_price, 3). "kr ink moms.<br><br>";
$TEXT .= "Prices for the next 24 hours from 18:00<br>";
$x = 0;
$COUNT_NORDPOOL = 0;
$price_array = array();
while($obj = $result->fetch_object()){
$price = ($obj->value)/(1000*1);
$TEXT .= "$x : ". $price."<br>";
$price_array[$x] = $price;
if($price <= $low_price){
$hours[$x] = 1;
}
$COUNT_NORDPOOL++;
$x++;
}
$TEXT .= "<br><br>";
$TEXT .= "Table where heat pump is allowed to be on = 1 based on 30% below average<br>";
$x = 0;
foreach ($hours as &$value) {
$TEXT .= "$x : ". $value."<br>";
$x++;
}
// count maximum hours before we need to heat
$TEXT .= "Indoor temp drop is: $indoor_temp_drop_per_hour<br>";
$TEXT .= "Indoor temp increase is: $indoor_temp_increase_per_hour<br><br>";
$TEXT .= "Off 1 hr, needs to be on for: (".$indoor_temp_drop_per_hour / $indoor_temp_increase_per_hour.") <br><br>";
$indoor_temp_drop_per_hour = $indoor_temp_drop_per_hour * ($indoor_temp_drop_per_hour / $indoor_temp_increase_per_hour);
$temp_delta = $temp_drop;
$hours_inrow = floor($temp_delta / $indoor_temp_drop_per_hour);
$TEXT .="<br>Maximum hours without heat: ".$hours_inrow." h based on buildings cool down cofficient (".$indoor_temp_drop_per_hour.") degrees / hour<br><br>";
$TEXT .="Now, lets found hours in our table where the sequence of 0´s is more then ".$hours_inrow.". We find that at index: <br>";
$periods_we_need_to_heat = array();
$index_arr = array();
$count_arr = array();
for ($i = 0; $i < 24; $i++) {
if($hours[$i] == 0){
$count = 0;
for ($j = 0; $j < 24; $j++) {
if($hours[$j+$i] == 0){
$count++;
}else{
if($count > $hours_inrow){
$TEXT .= "Index ($i): ".$count."<br>";
$periods_we_need_to_heat[$i] = $count;
$index_arr[] = $i;
$count_arr[] = $count;
}
$i = $i + $count;
break;
}
}
}
}
$TEXT .= "<br>For these periods we need to find the cheapest hours to heat the building. Now worries, I will make the calculations! ;) <br><br>";
// Create filters to check what will be the lowest consumption and price
$filter1 = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
$filter2 = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
$filter3 = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
for ($i = 0; $i < 24; $i++) {
$filter1[$i*($hours_inrow+1)] = 1;
$filter2[$i*($hours_inrow+1)+1] = 1;
$filter3[$i*($hours_inrow+1)+2] = 1;
}
for ($i = 0; $i < 24; $i++) {
$TEXT .=$filter1[$i]." - ".$filter2[$i]." - ".$filter3[$i]."<br>";
}
// Save prices in arrays for later step
$price_arr_all = array();
foreach ($periods_we_need_to_heat as &$value) {
$key = array_search($value, $periods_we_need_to_heat);
$price_arr = array();
for ($i = 0; $i < $value; $i++) {
$price_arr[] = $price_array[$key+$i];
}
$price_arr_all[] = $price_arr;
}
$x = 0;
$picked_filter = "";
foreach ($price_arr_all as &$price_arr) {
$sum_filter1 = 0;
$sum_filter2 = 0;
$sum_filter3 = 0;
$i = 0;
foreach ($price_arr as &$value) {
$TEXT .=$value."<br>";
if($filter1[$i] == 1){
$sum_filter1 +=$value;
}
if($filter2[$i] == 1){
$sum_filter2 +=$value;
}
if($filter3[$i] == 1){
$sum_filter3 +=$value;
}
$i++;
}
$smallest = $sum_filter1;
if($smallest > $sum_filter2){
$smallest = $sum_filter2;
}
if($smallest > $sum_filter3){
$smallest = $sum_filter3;
}
$TEXT .="<br>sum_filter1:".$sum_filter1;
$TEXT .="<br>sum_filter2:".$sum_filter2;
$TEXT .="<br>sum_filter3:".$sum_filter3;
if($smallest == $sum_filter1){
$picked_filter = $filter1;
$TEXT .="<br>Picked filter 1<br>";
}else if($smallest == $sum_filter2){
$picked_filter = $filter2;
$TEXT .="<br>Picked filter 2<br>";
}else if($smallest == $sum_filter3){
$picked_filter = $filter3;
$TEXT .="<br>Picked filter 3<br>";
}
// MAKE THINGS
$TEXT .= $index_arr[$x]." %".$count_arr[$x]."%".$x;
for ($i = $index_arr[$x]; $i < $index_arr[$x]+$count_arr[$x]; $i++) {
if($picked_filter[$i] == 1 && $hours[$i] == 0){
$hours[$i] = 1;
}
}
$x++;
$TEXT .= "<br>---<br>";
}
$sum_fixed_price = 0;
$sum_spot_price = 0;
$spot_price_average = 0;
$sum_spot_price_no_control = 0;
$c=0;
$hrs_array = array();
for ($i = 0; $i < 24; $i++) {
$ic = $i + (17 - date("H"));
$d = date("Y-m-d\TH:00:00",strtotime("+".($ic+1)."hours"));
$TEXT .= $d." - ".$hours[$i]." - ".$price_array[$i]."<br>";
$hrs_array[$d] = $hours[$i];
if($hours[$i] == 1){
$sum_spot_price += $price_array[$i];
$spot_price_average += $price_array[$i];
$c++;
}
$sum_spot_price_no_control += $price_array[$i];
$sum_fixed_price += $average_price;
}
$spot_price_average = $spot_price_average / $c;
//ADD ONOFF TO DB
if($COUNT_NORDPOOL > 10){
for ($i = 0; $i < 24; $i++) {
$h = 18 - date("H") + $i;
$key = date("Y-m-d\TH:00:00", strtotime("+".$h." hours"));
$found = 0;
$sql = "SELECT * FROM tblPriceControl WHERE Ethernet = '$ethernet' and startTime ='$key'";
$result = $mysqli->query($sql);
while($obj = $result->fetch_object()){
$found = 1;
}
if($found == 1){
$sql = "UPDATE tblPriceControl SET OnOff = '$hours[$i]' WHERE Ethernet = '$ethernet' and startTime ='$key')";
$TEXT .= "UPDATE tblPriceControl SET OnOff = ".$hours[$i]." WHERE Ethernet = ".$ethernet." and startTime =".$key.")<br>";
$result = $mysqli->query($sql);
}else{
$sql = "INSERT INTO tblPriceControl VALUES (null, '".$ethernet."','".$key."','".$hours[$i]."')";
$TEXT .= "INSERT INTO tblPriceControl VALUES (null, ".$ethernet.",".$key.",".$hours[$i].")<br>";
$result = $mysqli->query($sql);
}
}
}else{
$TEXT .= "<br><br>NO NORDPOOL DATA IS AVAILIBLE YET: ".date("Y-m-d H:i:s");
}
$TEXT .= "<br><br>RESULTS: <br>";
$TEXT .="Fixed price at (".round($average_price, 3).") kr: ". round($sum_fixed_price)." kr <br>";
$TEXT .="Spot price at (".round($spot_price_average, 3).") kr: ". round($sum_spot_price)." kr <br>";
$TEXT .="Spot price at (".round($spot_price_average, 3).") kr: ". round($sum_spot_price_no_control)." kr (no price control) <br>";
echo($TEXT);
$sql = "INSERT INTO tblCalculationLog VALUES (null, '".date("Y-m-d H:i:s")."','".$TEXT."')";
$result = $mysqli->query($sql);
?>