|
@@ -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
|