stanley-king 2 年之前
父节点
当前提交
b907ef6c49

+ 24 - 7
plot/refill/ChSpeedControlCalc.py

@@ -1,26 +1,32 @@
 from .ChannelCalc import ChannelCalc, detail_pathes
-from .algorithm import calc_chspeed, calc_chratio, calc_commit, calc_chprice
+from .algorithm import calc_chspeed, calc_chratio, calc_commit, calc_chprice, calc_chspeed_ratio
 from .DataStream import EChPosmap as pos_map
 from .DataStream import ch_calc_cfgs
 from .ChannelReader import ChannelReader
-from .speed_item import speed_item
+from .speed_item import speed_item, order_pmf
 from .speed_manager import speed_manager
+import numpy as np
 import time as time
 import json
 import redis
 
 import logging
+
 logger = logging.getLogger('ChSpeedControlCalc')
 
+
 class ChSpeedControlCalc(ChannelCalc):
     # def __init__(self):
     #     pass
 
+    def _calc_pmf(self, _commits, _succs):
+        pass
+
     def _collect_data(self):
-        start_period, ratio_period, speed_period, monitor_period = ch_calc_cfgs()
+        start_period, ratio_period, speed_period, monitor_period, cdf_speed_period = ch_calc_cfgs()
 
         reader = self._reader()
-        end_time = int(time.time()) - 86400
+        end_time = int(time.time()) - 86400 * 2
         days, start_time, end_time = self.calc_time(reader, end_time - start_period, end_time)
 
         day_stamp = days[0]
@@ -32,9 +38,21 @@ class ChSpeedControlCalc(ChannelCalc):
 
         for _name, _card_type, _spec, _data in gen:
             speed = calc_chspeed(_data, pos_map, end_pos - speed_period, end_pos) / 5
-            price,pratio = calc_chprice(_data, pos_map, end_pos - speed_period, end_pos) #price,profit_ratio =
+            price, pratio = calc_chprice(_data, pos_map, end_pos - speed_period, end_pos)
             ratio, ratio_commit, notify_time, succ_time = calc_chratio(_data, pos_map, end_pos - start_period, end_pos)
             monitor_commit = calc_commit(_data, pos_map, end_pos - monitor_period, end_pos) / 5
+            _commits, _succs, _ratios = calc_chspeed_ratio(_data, pos_map, end_pos - start_period, end_pos, cdf_speed_period)
+
+            x = _succs.astype(int).tolist()
+            succs = ','.join(str(i) for i in x)
+
+            x = _commits.astype(int).tolist()
+            commits = ','.join(str(i) for i in x)
+
+            logger.debug(f'commits={commits},succs={succs}')
+
+            # pmf = order_pmf()
+            # pmf.calculate(_commits,_succs)
 
             # key = f'{_spec}-{_card_type}'
             # result[key] = [speed, ratio, ratio_commit, notify_time, monitor_commit]
@@ -44,8 +62,7 @@ class ChSpeedControlCalc(ChannelCalc):
     def _calc_handler(self, rclient):
         self._collect_data()
 
-
         # if len(result) != 0:
         #     rclient.set(f"nc_refill_channel_control_speed", json.dumps(result))
         #     rclient.publish('refill', json.dumps({'type': 'channel_speed', 'value': 0}))
-        return 60
+        return 60

+ 1 - 1
plot/refill/ChannelSpeedAnalyzePainter.py

@@ -114,7 +114,7 @@ class ChannelSpeedAnalyzePainter(ChannelPainter):
             commits = np.array(commits).astype(int)
             self._succ_hist(succs,ax_hist_succs)
             self._succ_cdf(succs,commits,ax_succ_cdf,ax_ratio_cdf,ax_ratio_latest)
-        buf = self._flush(fig, ax_scatter, ax_succ_cdf, ax_hist_succs, ax_ratio_cdf, ax_ratio_latest)
+            buf = self._flush(fig, ax_scatter, ax_succ_cdf, ax_hist_succs, ax_ratio_cdf, ax_ratio_latest)
 
         result = []
         channels = get_channels()

+ 2 - 1
plot/refill/DataStream.py

@@ -81,8 +81,9 @@ def ch_calc_cfgs():
     speed_period = 300
     monitor_period = 600
     start_period = 1800
+    cdf_speed_period = 60
 
-    return start_period, ratio_period, speed_period, monitor_period
+    return start_period, ratio_period, speed_period, monitor_period, cdf_speed_period
 
 
 class DataWriteStream(metaclass=ABCMeta):

+ 2 - 0
plot/refill/__init__.py

@@ -30,6 +30,8 @@ from .ChSpeedControlCalc import ChSpeedControlCalc
 
 from .WriterConsumer import WriterConsumer
 
+from .speed_item import order_pmf,speed_item
+
 
 from .server_util import opt_parse
 

+ 43 - 0
plot/refill/speed_item.py

@@ -1,4 +1,47 @@
 
+import numpy as np
 class speed_item(object):
     def __init__(item):
         pass
+
+
+class order_pmf(object):
+
+    def calculate(self, commits, succs):
+        succs = succs.astype(int)
+        commits = commits.astype(int)
+
+        self._succs = np.sum(succs)
+        self._commits = np.sum(commits)
+
+        min = np.min(commits)
+        max = np.max(commits)
+
+        mcommits = [i for i in range(0, max + 1, 1)]
+        msuccs = []
+
+        succ = self._succ
+        scales = [succ * i for i in range(0,1.0,0.2)]
+
+        for i in mcommits:
+            pos = np.where(commits == i)
+            succ = succs[pos]
+            count = np.sum(succ)
+            msuccs.append(count)
+
+        msuccs = np.array(msuccs)
+        msuccs = np.cumsum(msuccs)
+
+
+
+        pos = np.where(msuccs == succ)
+        if len(pos[0]) > 1:
+            end = pos[0][1]
+            mcommits = mcommits[:end]
+            ratio = ratio[:end]
+        pass
+
+    def succ_count(self):
+        return self._succs
+    def commit_count(self):
+        return self._commits

+ 20 - 0
plot/testSpeed.py

@@ -0,0 +1,20 @@
+import unittest
+from refill import order_pmf
+import numpy as np
+
+
+class SpeedTestCase(unittest.TestCase):
+    def test_calculate(self):
+        commits = [23,8,82,72,157,228,119,164,119,226,166,127,349,220,267,133,57,257,307,83,14,25,172,428,145,379,219,335,231,630]
+        succs=[0,0,0,0,0,0,0,0,1,1,0,0,0,0,2,0,0,0,0,1,1,0,0,1,0,2,0,1,0,0]
+        pmf = order_pmf()
+        pmf.calculate(np.array(commits),np.array(succs))
+
+        pass
+
+
+
+
+
+if __name__ == '__main__':
+    unittest.main()