From 51f1c521a78eb716baca8763039bccf5a01d48ad Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Wed, 22 May 2024 10:15:11 +0300 Subject: [PATCH] =?utf8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF?= =?utf8?q?=D0=BE=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5=20?= =?utf8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BE=20=D0=BF=D0=BE?= =?utf8?q?=D1=81=D0=B5=D1=82=D0=B8=D1=82=D0=B5=D0=BB=D1=8F=D1=85=20=D1=81?= =?utf8?q?=20=D0=BA=D0=B0=D0=BC=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api1/views/cron/domru-cams.php | 246 +++++++++++++++------------ 1 file changed, 141 insertions(+), 105 deletions(-) diff --git a/erp24/api1/views/cron/domru-cams.php b/erp24/api1/views/cron/domru-cams.php index 9b94527..64794c9 100644 --- a/erp24/api1/views/cron/domru-cams.php +++ b/erp24/api1/views/cron/domru-cams.php @@ -7,7 +7,7 @@ error_reporting(E_ALL ^ E_NOTICE); // https://api.bazacvetov24.ru/cron/domru_cams.php?tip=0&token=1CjgpXfgkh1pXV3KR2H57G3VtHCffrp154up1t36&daysCnt=12 -$data = Yii::$app->db->createCommand("SELECT entity_id, export_val FROM `export_import_table` WHERE export_id='3' AND entity='city_store'")->queryAll(); +$data = Yii::$app->db->createCommand("SELECT entity_id, export_val FROM export_import_table WHERE export_id='3' AND entity='city_store'")->queryAll(); // $data=$db::getRows("SELECT entity_id, export_val FROM `export_import_table` WHERE export_id='3' AND entity='city_store'"); foreach ($data as $row) $revers[$row["export_val"]]=$row["entity_id"]; @@ -23,84 +23,54 @@ foreach($revers as $cam_id => $name) { } -$tip=rand(0,4); -$daysCnt=2; -if(isset($_GET["tip"])) $tip=(int)$_GET["tip"]; -if(!empty($_GET["daysCnt"])) $daysCnt=(int)$_GET["daysCnt"]; +//$tip=rand(0,4); +$daysCnt = 2; +//if (isset($_GET["tip"])) $tip = (int)$_GET["tip"]; +if (!empty($_GET["daysCnt"])) $daysCnt = (int)$_GET["daysCnt"]; -if($tip==0) $array = array( 'Login' => 'mochage-8r-136', 'Password' => 'fjtq8z3u'); -if($tip==1) $array = array( 'Login' => 'kuznzx-am-136', 'Password' => '8e4ma237'); -if($tip==2) $array = array( 'Login' => 'lazava-d8-136', 'Password' => '5gp3znn0'); -if($tip==3) $array = array( 'Login' => 'alieah-4d-136', 'Password' => 'qh7bxq5p'); -if($tip==4) $array = array( 'Login' => 'ipbelo-n2-ci', 'Password' => '8h09h42q38'); +foreach (range(0,4) as $tip){ + if ($tip == 0) $array = array('Login' => 'mochage-8r-136', 'Password' => 'fjtq8z3u'); + if ($tip == 1) $array = array('Login' => 'kuznzx-am-136', 'Password' => '8e4ma237'); + if ($tip == 2) $array = array('Login' => 'lazava-d8-136', 'Password' => '5gp3znn0'); + if ($tip == 3) $array = array('Login' => 'alieah-4d-136', 'Password' => 'qh7bxq5p'); + if ($tip == 4) $array = array('Login' => 'ipbelo-n2-ci', 'Password' => '8h09h42q38'); -echo"
ТИП $tip ".$array[$tip]["Login"]." "; + echo "
ТИП $tip " . $array["Login"] . " "; + $all = []; + $counterArr = []; + $allcnt = []; + $count_date = []; -$acc=1; + $acc = 1; -$ch = curl_init('https://vs.domru.ru/api/Login'); -curl_setopt($ch, CURLOPT_POST, 1); -curl_setopt($ch, CURLOPT_POSTFIELDS, $array); + $ch = curl_init('https://vs.domru.ru/api/Login'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $array); // Или предать массив строкой: // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array, '', '&')); -curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); -curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); -curl_setopt($ch, CURLOPT_HEADER, false); -$html = curl_exec($ch); -curl_close($ch); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_HEADER, false); + $html = curl_exec($ch); + curl_close($ch); -$json=json_decode($html,true); + $json = json_decode($html, true); //echo " ".$json["SessionID"]." "; -$sid=$json["SessionID"]; - -$array = array( - 'SessionID' => $sid -); - - -$ch = curl_init('https://vs.domru.ru/api/GetCameras'); -curl_setopt($ch, CURLOPT_POST, 1); -curl_setopt($ch, CURLOPT_POSTFIELDS, $array); -curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); -curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); -curl_setopt($ch, CURLOPT_HEADER, false); -$html = curl_exec($ch); -curl_close($ch); -$json=json_decode($html,true, 512, JSON_UNESCAPED_UNICODE); - -echo"
Названия камер"; -foreach($json as $id => $arrs) { - echo"
$id - name=".$arrs["Name"]." ".$arrs["AccountObjectName"]." CameraID=".$arrs["CameraID"]." "; -} - + $sid = $json["SessionID"]; -//exit(); -//echo'
';print_r($json);echo'
'; - - - -echo"За дней $daysCnt"; - -for($Offset=0;$Offset<=$daysCnt;$Offset++) { $array = array( - 'SessionID' => $sid, - 'Analytics' => 'CrossingLine', - 'From' =>date("Y-m-d H:i:s",time()-86400*($Offset)), - 'To' => date("Y-m-d H:i:s",time()-86400*($Offset-1)), - 'Direction' =>'Out', - 'GroupBy' => 'hour', - 'Limit' =>1000 - + 'SessionID' => $sid ); - $ch = curl_init('https://vs.domru.ru/api/ExportReport'); + + $ch = curl_init('https://vs.domru.ru/api/GetCameras'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $array); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -108,74 +78,140 @@ for($Offset=0;$Offset<=$daysCnt;$Offset++) { curl_setopt($ch, CURLOPT_HEADER, false); $html = curl_exec($ch); curl_close($ch); + $json = json_decode($html, true, 512, JSON_UNESCAPED_UNICODE); + + echo "
Названия камер"; + foreach ($json as $id => $arrs) { + echo "
$id - name=" . $arrs["Name"] . " " . $arrs["AccountObjectName"] . " CameraID=" . $arrs["CameraID"] . " "; + } + + +//exit(); +//echo'
';print_r($json);echo'
'; + + + + echo "За дней $daysCnt"; + + for ($Offset = 0; $Offset <= $daysCnt; $Offset++) { + $array = array( + 'SessionID' => $sid, + 'Analytics' => 'CrossingLine', + 'From' => date("Y-m-d H:i:s", time() - 86400 * ($Offset)), + 'To' => date("Y-m-d H:i:s", time() - 86400 * ($Offset - 1)), + 'Direction' => 'Out', + 'GroupBy' => 'hour', + 'Limit' => 1000 + + ); + + $ch = curl_init('https://vs.domru.ru/api/ExportReport'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $array); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_HEADER, false); + $html = curl_exec($ch); + curl_close($ch); //echo $html; - $file_put = __DIR__ . "/xml/ExportReport".$acc."_".$Offset.".xml"; + $file_put = __DIR__ . "/../../log/xml/ExportReport" . $acc . "_" . $Offset . ".xml"; - file_put_contents($file_put,$html); + file_put_contents($file_put, $html); //echo""; - $json=json_decode($html,true, 512, JSON_UNESCAPED_UNICODE); + $json = json_decode($html, true, 512, JSON_UNESCAPED_UNICODE); //echo" ".$json["Error"].""; - $xml = simplexml_load_file($file_put); - $maas=json_decode(json_encode($xml), true); - asort($maas); - foreach($maas["count"] ?? [] as $id =>$arr) { + $xml = simplexml_load_file($file_put); + $maas = json_decode(json_encode($xml), true); + asort($maas); + foreach ($maas["count"] ?? [] as $id => $arr) { //echo"
DateTime=".$arr["DateTime"]." $id =>".$arr["CameraName"]." CameraID=".$arr["CameraID"]." value=".$arr["Value"]." " ; - if(isset($revers[$arr["CameraName"]])) { - $store_id=$revers[$arr["CameraName"]]; - $date_ar=explode(" ",$arr["DateTime"]); - $date=$date_ar[0]; - $hour=explode(":",$date_ar[1]); - $hour=$hour[0]; - $counter=(int)$arr["Value"]; + if (isset($revers[$arr["CameraName"]])) { + $store_id = $revers[$arr["CameraName"]]; + $date_ar = explode(" ", $arr["DateTime"]); + $date = $date_ar[0]; + $hour = explode(":", $date_ar[1]); + $hour = $hour[0]; + $counter = (int)$arr["Value"]; //echo"
$store_id,$date,$hour,$counter"; - $counterArr[$store_id][$date][$hour] +=$counter; - $all[$arr["CameraName"]]=$all[$arr["CameraName"]]+$arr["Value"]; - $allcnt[$arr["CameraName"]]++; - $count_date[$arr["CameraName"]][$date]=$count_date[$arr["CameraName"]][$date]+$arr["Value"]; + if (!array_key_exists($store_id, $counterArr)) { + $counterArr[$store_id] = []; + } + if (!array_key_exists($date, $counterArr[$store_id])) { + $counterArr[$store_id][$date] = []; + } + if (!array_key_exists($hour, $counterArr[$store_id][$date])) { + $counterArr[$store_id][$date][$hour] = 0; + } + $counterArr[$store_id][$date][$hour] += $counter; - } else echo"
у камеры нет сопоставления ".$arr["CameraName"]." = ".$revers[$arr["CameraName"]]." "; - } + if (!array_key_exists($arr["CameraName"], $all)) { + $all[$arr["CameraName"]] = 0; + } + $all[$arr["CameraName"]] = $all[$arr["CameraName"]] + $arr["Value"]; - // вносим в массив - foreach($maas["count"] ?? [] as $id =>$arr) { - if(isset($revers[$arr["CameraName"]])) { - $store_id=$revers[$arr["CameraName"]]; - $date_ar=explode(" ",$arr["DateTime"]); - $date=$date_ar[0]; - $hour=explode(":",$date_ar[1]); - $hour=$hour[0]; - $counter=$counterArr[$store_id][$date][$hour] ; -// $z="insert IGNORE into store_visitors (store_id, date, date_hour, counter) values (?,?,?,?) ON DUPLICATE KEY UPDATE counter=?"; -// $db::sql($z,[$store_id,$date,$hour,$counter,$counter]); - Yii::$app->db->createCommand("insert IGNORE into store_visitors (store_id, date, date_hour, counter) values (:store_id,:date,:date_hour,:counter) ON DUPLICATE KEY UPDATE counter=:counter") - ->bindValues([ - ':store_id' => $store_id, - ':date' => $date, - ':date_hour' => $hour, - ':counter' => $counter, - ])->execute(); - echo"
$date h=$hour store_id=$store_id value=$counter"; + if (!array_key_exists($arr["CameraName"], $allcnt)) { + $allcnt[$arr["CameraName"]] = 0; + } + $allcnt[$arr["CameraName"]]++; + + if (!array_key_exists($arr["CameraName"], $count_date)) { + $count_date[$arr["CameraName"]] = []; + } + + if (!array_key_exists($date, $count_date[$arr["CameraName"]])) { + $count_date[$arr["CameraName"]][$date] = 0; + } + $count_date[$arr["CameraName"]][$date] = $count_date[$arr["CameraName"]][$date] + $arr["Value"]; + + } else { + echo "
у камеры нет сопоставления " . $arr["CameraName"]; + echo " = " . ($revers[$arr["CameraName"]] ?? '-') . " "; + } } - } + // вносим в массив + foreach ($maas["count"] ?? [] as $id => $arr) { + if (isset($revers[$arr["CameraName"]])) { + $store_id = $revers[$arr["CameraName"]]; + $date_ar = explode(" ", $arr["DateTime"]); + $date = $date_ar[0]; + $hour = explode(":", $date_ar[1]); + $hour = $hour[0]; + $counter = $counterArr[$store_id][$date][$hour]; +// $z="insert IGNORE into store_visitors (store_id, date, date_hour, counter) values (?,?,?,?) ON DUPLICATE KEY UPDATE counter=?"; +// $db::sql($z,[$store_id,$date,$hour,$counter,$counter]); + + Yii::$app->db->createCommand("INSERT INTO store_visitors (store_id, date, date_hour, counter) values (:store_id,:date,:date_hour,:counter) ON CONFLICT (store_id, date, date_hour) DO UPDATE SET counter=:counter") + ->bindValues([ + ':store_id' => $store_id, + ':date' => $date, + ':date_hour' => $hour, + ':counter' => $counter, + ])->execute(); + echo "
$date h=$hour store_id=$store_id value=$counter"; + } + } - $filename ='file_cnt.txt'; - file_put_contents(__DIR__ . '/txt/' . $filename, $Offset."".date("Y-m-d H:i:s").""); - if ($all) { - arsort($all); - foreach ($all as $cid => $val) echo "
$cid = > $val "; ///".$allcnt[$cid]." + + $filename = 'file_cnt.txt'; + file_put_contents(__DIR__ . '/../../log/text/' . $filename, $Offset . "" . date("Y-m-d H:i:s") . ""); + if ($all) { + arsort($all); + foreach ($all as $cid => $val) echo "
$cid = > $val "; ///".$allcnt[$cid]." + } } + sleep(2); } -- 2.39.5