|
@@ -0,0 +1,42 @@
|
|
|
+from .ChannelCalc import ChannelCalc, detail_pathes
|
|
|
+from .algorithm import calc_chspeed, calc_chratio, calc_commit
|
|
|
+from .DataStream import EChPosmap as pos_map
|
|
|
+from .DataStream import ch_calc_cfgs
|
|
|
+from .ChannelReader import ChannelReader
|
|
|
+import time as time
|
|
|
+import json
|
|
|
+import redis
|
|
|
+
|
|
|
+import logging
|
|
|
+logger = logging.getLogger('ChSpeedControlCalc')
|
|
|
+
|
|
|
+class ChSpeedControlCalc(ChannelCalc):
|
|
|
+
|
|
|
+ def _calc_handler(self, rclient):
|
|
|
+ reader = self._reader()
|
|
|
+ end_time = int(time.time())
|
|
|
+ period = 1800
|
|
|
+ days, start_time, end_time = self.calc_time(reader, end_time - period, end_time)
|
|
|
+
|
|
|
+ day_stamp = days[0]
|
|
|
+ tuple_pathes = reader.many_tuple_path(days, card_types=set([4, 5, 6]))
|
|
|
+ gen = detail_pathes(reader, tuple_pathes, days)
|
|
|
+
|
|
|
+ start_pos = start_time - day_stamp
|
|
|
+ end_pos = end_time - day_stamp
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
+ 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
|