????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.191 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 : /proc/self/root/var/www/appsrv.astacus.se/shellyctr/ |
Upload File : |
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$mysqli = new mysqli("www.astacus.se", "carlhoffstedt", "Astacus2020!", "ShellyCTR");
$sql = "SELECT tblPriceControl.Username as Username, tblPriceControl.Area as Area, tblPriceControl.Percent_on as Percent_on, tblPriceControl.Percent_off as Percent_off FROM tblUsers,tblPriceControl WHERE tblPriceControl.Username = tblUsers.Username ";
$result = $mysqli->query($sql);
while($obj = $result->fetch_object()){
$Username = $obj->Username;
$area = $obj->Area;
$percent_on = $obj->Percent_on;
$percent_off = $obj->Percent_off;
if($percent_on == "1"){
$add_on = 1;
}
if($percent_off == "1"){
$add_off = 1;
}
$nbr_hrs_off = round((24*$percent_off))+$add_off;
$nbr_hrs_on = round((24*$percent_on))+$add_on;
$from = date("Y-m-d",strtotime("+1 days"))." 00:00:00";
$to = date("Y-m-d",strtotime("+1 days"))." 24:00:00";
$sql = "SELECT * FROM tblNordpool WHERE endTime >= '".$from."' and endTime <= '".$to."' and area = '".$area."' order by endTime";
$result = $mysqli->query($sql);
$moms = 1.25;
$hours_arr = array();
while($obj = $result->fetch_object()){
$timestamp = $obj->endTime;
$month = date("n",strtotime($timestamp)); //1-12
$hour = date("G",strtotime($timestamp)); // 0-24
if($month >= 11 || $month <= 3){
if($hour >= 6 && $hour < 22){
$tariff = 0.536;
}else{
$tariff = 0.20;
}
}else{
$tariff = 0.20;
}
$value = ($obj->value/1000 + $tariff)*$moms;
$hours_arr[] = array($timestamp, $value);
}
$sum = 0;
foreach ($hours_arr as &$v1) {
$sum +=$v1[1];
}
$average = $sum/count($hours_arr);
$arr_off = array();
$arr_on = array();
foreach ($hours_arr as &$v1) {
$arr_off[] = $v1[1];
$arr_on[] = $v1[1];
}
rsort($arr_off);
$largest = array_slice($arr_off, 0, $nbr_hrs_off);
sort($arr_on);
$smallest = array_slice($arr_on, 0, $nbr_hrs_on);
$status_arr = array();
$controltype = 1;
$status = 0;
foreach ($hours_arr as &$v1) {
if(in_array($v1[1],$smallest)){
$status = 1;
}else{
$status = 0;
}
$status_arr[] = array(date("Y-m-d",strtotime("+1 days")),$controltype,$Username, $v1[0],$v1[1],$status);
}
$controltype = 2;
$status = 0;
foreach ($hours_arr as &$v1) {
if(in_array($v1[1],$largest)){
$status = 0;
}else{
$status = 1;
}
$status_arr[] = array(date("Y-m-d",strtotime("+1 days")),$controltype,$Username, $v1[0],$v1[1],$status);
}
$controltype = 3;
$status = 0;
foreach ($hours_arr as &$v1) {
if($v1[1] < $average){
$status = 1;
}else{
$status = 0;
}
$status_arr[] = array(date("Y-m-d",strtotime("+1 days")),$controltype,$Username, $v1[0],$v1[1],$status);
}
foreach ($status_arr as &$v1) {
$sql = "DELETE FROM tblShellyControl WHERE Username = '".$v1[2]."' and Controldate = '".date("Y-m-d",strtotime("+1 days"))."';";
echo($sql ."<br>");
$mysqli->query($sql);
}
$sql = "";
foreach ($status_arr as &$v1) {
$sql = "INSERT INTO tblShellyControl VALUES(null,'".$v1[0]."',".$v1[1].",'".$v1[2]."','".$v1[3]."','".$v1[4]."','".$v1[5]."');";
$mysqli->query($sql);
echo($sql ."<br>");
}
}
/*
*/
?>