|
@@ -0,0 +1,81 @@
|
|
|
+from .DataStream import EChPosmap as pos_map
|
|
|
+from .ChannelReader import ChannelReader
|
|
|
+from .ChannelPainter import ChannelPainter, ratio_pathes
|
|
|
+from matplotlib.figure import Figure
|
|
|
+from matplotlib import ticker
|
|
|
+from io import BytesIO
|
|
|
+import numpy as np
|
|
|
+from .algorithm import calc_chspeed_ratio
|
|
|
+import time as time
|
|
|
+
|
|
|
+import logging
|
|
|
+logger = logging.getLogger('ChannelSpeedAnalyzePainter')
|
|
|
+
|
|
|
+class ChannelSpeedAnalyzePainter(ChannelPainter):
|
|
|
+ def __init__(self, start_time: int, end_time: int, chnames: set = None, card_types: set = None, spec: int = None, period: int = 60):
|
|
|
+ self._reader = ChannelReader()
|
|
|
+ self._chnames, self._card_types, self._spec, self._period = chnames, card_types, spec, period
|
|
|
+ days, self._start_time, self._end_time, self._interval = self.calc_time(self._reader, start_time, end_time)
|
|
|
+
|
|
|
+ secs = self._end_time - self._start_time
|
|
|
+ if secs % period > 0:
|
|
|
+ self._start_time = self._start_time -(period - secs % period)
|
|
|
+ pass
|
|
|
+
|
|
|
+ def _scatter_hist(self, x, y, ax, ax_histx):
|
|
|
+ # def xwidth(length):
|
|
|
+ # width = length / 10
|
|
|
+ #
|
|
|
+ # def xBins(x):
|
|
|
+ # x = np.array(x)
|
|
|
+ # xLength = np.max(x)
|
|
|
+ x = np.array(x)
|
|
|
+ xLength = np.max(x)
|
|
|
+ bins = np.arange(0, xLength, 100)
|
|
|
+
|
|
|
+ ax_histx.tick_params(axis="x", labelbottom=False)
|
|
|
+ # xbins = np.arange(0, xLength, binwidth)
|
|
|
+ ax_histx.hist(x, bins=bins)
|
|
|
+
|
|
|
+ def _fig_create(self):
|
|
|
+ fig = Figure(figsize=(12, 8))
|
|
|
+ gs = fig.add_gridspec(2, 1, height_ratios=(1, 4),
|
|
|
+ left=0.1, right=0.9, bottom=0.1, top=0.9,
|
|
|
+ wspace=0.05, hspace=0.05)
|
|
|
+ ax = fig.add_subplot(gs[1, 0])
|
|
|
+ ax_histx = fig.add_subplot(gs[0, 0], sharex=ax)
|
|
|
+ return ax, fig, ax_histx
|
|
|
+
|
|
|
+ def _flush(self, ax, fig):
|
|
|
+ ax.grid()
|
|
|
+ ax.legend()
|
|
|
+ fig.tight_layout()
|
|
|
+
|
|
|
+ buf = BytesIO()
|
|
|
+ fig.savefig(buf, format="png")
|
|
|
+ return buf
|
|
|
+
|
|
|
+ def paint(self):
|
|
|
+ reader = self._reader
|
|
|
+ days, _start_time, _end_time, _interval = self.calc_time(self._reader, self._start_time, self._end_time)
|
|
|
+ if len(days) == 0:
|
|
|
+ return BytesIO()
|
|
|
+
|
|
|
+ tuple_pathes = reader.many_tuple_path(days, self._chnames, self._card_types, self._spec)
|
|
|
+ gen = ratio_pathes(reader, tuple_pathes, days, self._spec)
|
|
|
+ day_stamp = days[0]
|
|
|
+
|
|
|
+ commits = []
|
|
|
+ succs = []
|
|
|
+ ratios = []
|
|
|
+ ax, fig, ax_histx = self._fig_create()
|
|
|
+ for _chname, _card_type, _spec, _data in gen:
|
|
|
+ _commits, _succs, _ratios = calc_chspeed_ratio(_data, pos_map, _start_time - day_stamp, _end_time - day_stamp, self._period)
|
|
|
+ ax.scatter(_commits, _succs)
|
|
|
+ commits.extend(_commits)
|
|
|
+ succs.extend(_succs)
|
|
|
+ ratios.extend(ratios)
|
|
|
+ self._scatter_hist(commits, succs, ax, ax_histx)
|
|
|
+
|
|
|
+ buf = self._flush(ax,fig)
|
|
|
+ return buf
|