Jelajahi Sumber

add ai data collect

stanley-king 3 tahun lalu
induk
melakukan
600ee24bca

+ 10 - 0
helper/refill/RefillBase.php

@@ -19,6 +19,7 @@ use QueueClient;
 use member_info;
 use Exception;
 use trans_wapper;
+use Cache;
 
 class RefillBase
 {
@@ -642,4 +643,13 @@ class RefillBase
             return false;
         }
     }
+
+    public function UpdateRatio()
+    {
+        $ins = Cache::getInstance('cacheredis');
+        $val = $ins->get('channel_ratios');
+        if(!empty($val)) {
+            Log::record($val,Log::DEBUG);
+        }
+    }
 }

+ 10 - 6
plot/DataCenter.py

@@ -33,7 +33,7 @@ class DataCenter(object):
         pass
 
     def prepare_data(self):
-        while True:
+        while self._mquit == False:
             try:
                 pool = redis.ConnectionPool(host=self._mRHost, port=self._mRPort, db=0)
                 r = redis.Redis(connection_pool=pool)
@@ -52,8 +52,13 @@ class DataCenter(object):
             except Exception as ex:
                 print(ex)
             finally:
-                for i in range(60):
-                    if self._mquit == True:
+                time_sec = int(time.time())
+                cur_min = time_sec - time_sec % 60
+
+                for i in range(66):
+                    time_sec = int(time.time())
+                    next_min = time_sec - time_sec % 60
+                    if next_min > cur_min or self._mquit:
                         break
                     else:
                         stime.sleep(1)
@@ -417,11 +422,10 @@ class DataCenter(object):
             except Exception as ex:
                 print(ex)
             finally:
-                for i in range(60):
+                for i in range(66):
                     time_sec = int(time.time())
                     next_min = time_sec - time_sec % 60
-
-                    if next_min > cur_min:
+                    if (next_min > cur_min and time_sec % 60 == 2) or self._mquit:
                         break
                     else:
                         stime.sleep(1)

+ 2 - 2
plot/MchDataCenter.py

@@ -32,7 +32,7 @@ class MchDataCenter(object):
         pass
 
     def prepare_data(self):
-        while True:
+        while self._mquit == False:
             try:
                 pool = redis.ConnectionPool(host=self._mRHost, port=self._mRPort, db=0)
                 r = redis.Redis(connection_pool=pool)
@@ -52,7 +52,7 @@ class MchDataCenter(object):
                 print(ex)
             finally:
                 for i in range(60):
-                    if self._mquit == True:
+                    if self._mquit:
                         break
                     else:
                         stime.sleep(1)

+ 28 - 0
rdispatcher/codispatcher.php

@@ -90,6 +90,34 @@ function sub_message(&$waiting_quit,&$sub_redis,$channels)
     Log::record("sub_message quit",Log::DEBUG);
 }
 
+function ratio_update(&$waiting_quit)
+{
+    //每分钟的第0秒 将上一分钟的数据,写入HD5File。
+    //每分钟的第2秒 统计之前的数据
+    //每分钟的第3秒触发更新 成功率统计数据
+    while (!$waiting_quit)
+    {
+        for ($i = 0; $i < 61; $i++) {
+            $cur_time = time();
+            $time_sec = $cur_time;
+            $next_min = $time_sec - $time_sec % 60;
+
+            if(($next_min > $cur_min && $time_sec % 60 == 3) || $waiting_quit) {
+                $cur_min = $next_min;
+                break;
+            } else {
+                Swoole\Coroutine::sleep(0.1);
+            }
+        }
+        if(!$waiting_quit) {
+            refill\RefillFactory::instance()->UpdateRatio();
+        }
+    }
+
+    $waiting_quit = true;
+    Log::record("ratio_update quit",Log::DEBUG);
+}
+
 $workers = [];
 for ($i = 0; $i < $process_count;$i++)
 {

+ 26 - 0
test/TestRedis.php

@@ -282,6 +282,32 @@ class TestRedis extends TestCase
 
     }
 
+    public function testSec()
+    {
+        $cur_min = 0;
+        while(true)
+        {
+            for ($i = 0; $i < 61; $i++) {
+                $cur_time = time();
+                $time_sec = $cur_time;
+                $next_min = $time_sec - $time_sec % 60;
+
+                if($next_min > $cur_min && $time_sec % 60 == 3) {
+                    $cur_min = $next_min;
+                    break;
+                } else {
+                    sleep(1);
+                }
+            }
+            $a = strftime("%Y-%m-%d %H:%M:%S",$cur_time);
+            $b = strftime("%Y-%m-%d %H:%M:%S",$time_sec);
+            $c = strftime("%Y-%m-%d %H:%M:%S",$cur_min);
+            $d = strftime("%Y-%m-%d %H:%M:%S",$next_min);
+
+            Log::record("cur_time={$a},time_sec={$b},cur_min={$c},next_min={$d}",Log::DEBUG);
+        }
+    }
+
     ////docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRedis::testCancel)( .*)?$/" --test-suffix TestRedis.php /var/www/html/test
     ////docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRedis::testCancelPayed)( .*)?$/" --test-suffix TestRedis.php /var/www/html/test
     public static function tearDownAfterClass() : void