|
@@ -0,0 +1,62 @@
|
|
|
+from .DataStream import ENetPosmap as pos_map
|
|
|
+from .NetcheckPainter import NetcheckPainter, net_pathes
|
|
|
+from .NetchkReader import NetchkReader
|
|
|
+from matplotlib.figure import Figure
|
|
|
+from matplotlib import ticker
|
|
|
+from io import BytesIO
|
|
|
+import numpy as np
|
|
|
+from .algorithm import calc_cov_netfail
|
|
|
+import time as time
|
|
|
+
|
|
|
+import logging
|
|
|
+logger = logging.getLogger('ChannelCumPainter')
|
|
|
+
|
|
|
+class NetcheckCovPainter(NetcheckPainter):
|
|
|
+ def __init__(self, start_time: int, end_time: int, chnames: set = None, filter_wave: int = None):
|
|
|
+ self._reader = NetchkReader()
|
|
|
+ if filter_wave is None:
|
|
|
+ filter_wave = 3600
|
|
|
+ self._chnames, self._filter_wave = chnames, filter_wave
|
|
|
+ _days, self._start_time, self._end_time, self._interval = self.calc_time(self._reader, start_time, end_time)
|
|
|
+ pass
|
|
|
+
|
|
|
+ def paint(self):
|
|
|
+ reader = self._reader
|
|
|
+ self._days, _start_time, _end_time, _interval = self.calc_time(self._reader, self._start_time - self._filter_wave, self._end_time)
|
|
|
+
|
|
|
+ tuple_pathes = reader.many_tuple_path(self._days, self._chnames)
|
|
|
+ gen = net_pathes(reader, tuple_pathes, self._days)
|
|
|
+ if len(self._days) == 0:
|
|
|
+ return BytesIO()
|
|
|
+
|
|
|
+ day_stamp = self._days[0]
|
|
|
+ fig_create, fig_flush = self._fig_funs()
|
|
|
+ ax, fig = fig_create()
|
|
|
+ x = np.array([d - self._start_time for d in range(self._start_time, self._end_time)])
|
|
|
+ window = np.ones(self._filter_wave)
|
|
|
+
|
|
|
+ left_len = self._start_time - _start_time
|
|
|
+ right_len = _end_time - self._end_time
|
|
|
+
|
|
|
+ stime = lambda t: time.strftime('%d-%H:%M:%S', time.localtime(t))
|
|
|
+ logger.debug("near_stamp start_time %d, %s end_time=%s left_len=%d right_len=%d",
|
|
|
+ self._start_time, stime(self._start_time), stime(self._end_time),left_len,right_len)
|
|
|
+
|
|
|
+ chname_ratios = []
|
|
|
+ for _chname, _data in gen:
|
|
|
+ fail, fails, count = calc_cov_netfail(_data, pos_map, _start_time - day_stamp, _end_time - day_stamp, window, left_len,right_len)
|
|
|
+ label, ratio = self._label(chname=_chname, succ=fails, count=count)
|
|
|
+ ax.plot(x, fail, ls='-', label=label)
|
|
|
+ if _chname != 'all':
|
|
|
+ chname_ratios.append((_chname, ratio))
|
|
|
+
|
|
|
+ ticks = [d - self._start_time for d in range(self._start_time, self._end_time + 1, self._interval)]
|
|
|
+ xlables = [time.strftime('%d-%H:%M:%S', time.localtime(d + self._start_time)) for d in ticks]
|
|
|
+ buf = fig_flush(ax, fig, ticks, xlables)
|
|
|
+
|
|
|
+ chname_ratios = sorted(chname_ratios, key=lambda x: (x[1], x[0]), reverse=True)
|
|
|
+ result = []
|
|
|
+ for name, ratio in chname_ratios:
|
|
|
+ result.append(f'{name}:{ratio}')
|
|
|
+
|
|
|
+ return buf, result
|