소스 검색

for success ratio

stanley-king 2 년 전
부모
커밋
bbc7bc55b0
6개의 변경된 파일50개의 추가작업 그리고 20개의 파일을 삭제
  1. 2 3
      crontab/control/minutes.php
  2. 2 2
      docker/compose/homecuda/cli/docker-compose.yml
  3. 21 10
      plot/refill/ChSpeedRatioCalc.py
  4. 2 2
      plot/refill/DataStream.py
  5. 14 0
      plot/refill/algorithm.py
  6. 9 3
      plot/testSpeed.py

+ 2 - 3
crontab/control/minutes.php

@@ -487,10 +487,9 @@ class minutesControl extends BaseCronControl
 
     private function _calc_arrears()
     {
-        $send_amount_reader = function()
-        {
+        $send_amount_reader = function () {
             $val = rkcachex('stat-merchant-sendamount', 'refill-');
-            $val = json_decode($val,true);
+            $val = json_decode($val, true);
             return $val;
         };
 

+ 2 - 2
docker/compose/homecuda/cli/docker-compose.yml

@@ -40,8 +40,8 @@ services:
 
   pythoncli:
     image: pycpu:3.7.10
-    ports:
-      - 5000:5000
+#    ports:
+#      - 5000:5000
     volumes:
       - /mnt/xyzshop/docker/compose/homecuda/conf/etc/localtime:/etc/localtime:ro
       - /mnt/xyzshop:/var/www/html

+ 21 - 10
plot/refill/ChSpeedRatioCalc.py

@@ -1,6 +1,7 @@
 from .ChannelCalc import ChannelCalc, detail_pathes
-from .algorithm import calc_chspeed, calc_chratio, calc_commit
+from .algorithm import calc_chspeed, calc_chratio, calc_commit, calc_unback_time
 from .DataStream import EChPosmap as pos_map
+from .DataStream import ch_calc_cfgs
 from .ChannelReader import ChannelReader
 import time as time
 import json
@@ -9,14 +10,21 @@ import redis
 import logging
 logger = logging.getLogger('ChSpeedCalc')
 
+def mktime(strtime):
+    tdata = time.strptime(strtime, "%Y-%m-%d %H:%M:%S")
+    time_stamp = int(time.mktime(tdata))
+    return time_stamp
+
+
 class ChSpeedRatioCalc(ChannelCalc):
     def _calc_handler(self, rclient):
         logger.debug('_calc_handler')
+        start_period, ratio_period, speed_period, monitor_period, cdf_speed_period = ch_calc_cfgs()
 
         reader = self._reader()
-        end_time = int(time.time())
-        period = 1800
-        days, start_time, end_time = self.calc_time(reader, end_time - period, end_time)
+        # end_time = int(time.time())
+        end_time = mktime('2022-11-01 11:10:00')
+        days, start_time, end_time = self.calc_time(reader, end_time - start_period, end_time)
 
         day_stamp = days[0]
         tuple_pathes = reader.many_tuple_path(days, card_types=set([4, 5, 6]))
@@ -25,16 +33,19 @@ class ChSpeedRatioCalc(ChannelCalc):
         start_pos = start_time - day_stamp
         end_pos = end_time - day_stamp
 
+        mins = speed_period / 60
         result = dict()
         for _name, _card_type, _spec, _data in gen:
-            speed = calc_chspeed(_data, pos_map, end_pos - 300, end_pos) / 5
-            ratio, ratio_commit, notify_time, succ_time = calc_chratio(_data, pos_map, end_pos - period, end_pos)
-            monitor_commit = calc_commit(_data, pos_map, end_pos - 600, end_pos) / 5
+            speed = calc_chspeed(_data, pos_map, end_pos - speed_period, end_pos) / mins
+            speed = int(speed)
+            # calc_unback_time(_data, pos_map, end_pos - start_period, end_pos)
+            ratio, commit, notify_time, succ_time = calc_chratio(_data, pos_map, end_pos - ratio_period, end_pos)
+            logger.debug(f'{_name}-{_card_type}-{_spec} speed:{speed}')
 
             key = f'{_name}-{_spec}-{_card_type}'
-            result[key] = [speed, ratio, ratio_commit, notify_time, monitor_commit]
-            logger.debug("%s-%d-%d speed=%d ratio=%.5f commit_count=%d notify_time=%.5f succ_time=%.5f monitor_commit=%d", _name, _card_type, _spec, speed, ratio,
-                         ratio_commit, notify_time, succ_time, monitor_commit)
+            result[key] = [speed, ratio, commit, notify_time, 0]
+            logger.debug("%s-%d-%d speed=%d ratio=%.5f commit=%d notify_time=%.5f succ_time=%.5f",
+                         _name, _card_type, _spec, speed, ratio, commit, notify_time, succ_time)
 
         if len(result) != 0:
             rclient.set(f"nc_refill_channel_control_model", json.dumps(result))

+ 2 - 2
plot/refill/DataStream.py

@@ -78,9 +78,9 @@ def span_days(start_time, end_time):
 
 def ch_calc_cfgs():
     ratio_period = 1800
-    speed_period = 300
+    speed_period = 60
     monitor_period = 600
-    start_period = 1800
+    start_period = 3600
     cdf_speed_period = 60
 
     return start_period, ratio_period, speed_period, monitor_period, cdf_speed_period

+ 14 - 0
plot/refill/algorithm.py

@@ -145,6 +145,20 @@ def calc_chratio(data, pos_map, start, end):
     return round(ratio, 5), commit_count, int(back_time), int(succ_time)
 
 
+def calc_unback_time(data, pos_map, start, end):
+    view = data[[pos_map.succ_count, pos_map.fail_count, pos_map.commit_count], :]
+    view = view[:, start:end]
+    delta = view[2, :] - view[0, :] - view[1, :]
+    pos = np.where(delta > 0)
+    if len(pos[0]) > 0:
+        start = pos[0][0]
+        count = np.sum(delta)
+    else:
+        pass
+    
+    return delta
+
+
 def calc_commit(data, pos_map, start, end):
     view = data[[pos_map.commit_count], :]
     view = view[:, start:end]

+ 9 - 3
plot/testSpeed.py

@@ -75,9 +75,15 @@ class SpeedTestCase(unittest.TestCase):
         x = int(round(2.55,0))
         pass
 
-
-
-
+    def testTime(self):
+        import time
+        a1 = "2019-5-10 23:40:00"
+        # 先转换为时间数组
+        timeArray = time.strptime(a1, "%Y-%m-%d %H:%M:%S")
+
+        # 转换为时间戳
+        timeStamp = int(time.mktime(timeArray))
+        print(timeStamp)
 
 
 if __name__ == '__main__':