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