stanley-king hace 2 años
padre
commit
8f4a321278
Se han modificado 4 ficheros con 64 adiciones y 40 borrados
  1. 10 3
      plot/app.py
  2. 10 6
      plot/refill/ChannelCovPainter.py
  3. 15 31
      plot/refill/ChannelPainter.py
  4. 29 0
      plot/refill/ChannelReader.py

+ 10 - 3
plot/app.py

@@ -11,6 +11,8 @@ import signal as sig
 import sys, getopt
 
 app = Flask(__name__)
+app.debug = True
+
 curname = __name__
 
 logging.basicConfig(filename='/var/www/html/data/log/flask.log',
@@ -19,7 +21,7 @@ logging.basicConfig(filename='/var/www/html/data/log/flask.log',
 logger = logging.getLogger('plot')
 
 from refill import ChannelCumPainter, ChannelCovPainter, ChannelCovSuccPainter
-from refill import MerchantCumRatioPainter, MerchantAmountPainter, MerchantCovRatioPainter,ChannelSpeedAnalyzePainter
+from refill import MerchantCumRatioPainter, MerchantAmountPainter, MerchantCovRatioPainter, ChannelSpeedAnalyzePainter
 from refill import filter_chname, filter_cardtype, filter_mchids, get_channels, get_mchids
 from refill import NetcheckCovPainter, get_net_channels
 
@@ -57,6 +59,7 @@ def ch_ratio():
         start_time, end_time, card_types, spec, filter_wave = parse_parmeter()
         chnames = request.args.get('chnames')
         chnames = filter_chname(chnames)
+        show_all = request.args.get('show_all')
 
         painter = ChannelCumPainter(start_time=start_time, end_time=end_time, chnames=chnames, card_types=card_types, spec=spec,
                                     filter_wave=filter_wave)
@@ -67,6 +70,7 @@ def ch_ratio():
     except Exception as ex:
         return onError(ex)
 
+
 @app.route('/plot/ch_speed_ratio')
 def ch_speed_ratio():
     try:
@@ -80,12 +84,13 @@ def ch_speed_ratio():
         painter = ChannelSpeedAnalyzePainter(start_time=start_time, end_time=end_time,
                                              chnames=chnames, card_types=card_types, spec=spec,
                                              period=period)
-        buf , ratios = painter.paint()
+        buf, ratios = painter.paint()
         data = base64.b64encode(buf.getbuffer()).decode("ascii")
         return jsonify({'img': data, 'ratios': ratios, 'state': 'success'})
     except Exception as ex:
         return onError(ex)
 
+
 @app.route('/plot/ch_covratio')
 def ch_covratio():
     try:
@@ -93,9 +98,11 @@ def ch_covratio():
         start_time, end_time, card_types, spec, filter_wave = parse_parmeter()
         chnames = request.args.get('chnames')
         chnames = filter_chname(chnames)
+        show_all = request.args.get('show_all')
+        show_all = False if show_all is None else bool(show_all)
 
         painter = ChannelCovPainter(start_time=start_time, end_time=end_time, chnames=chnames, card_types=card_types, spec=spec,
-                                    filter_wave=filter_wave)
+                                    filter_wave=filter_wave,show_all=show_all)
         buf, ratios = painter.paint()
         data = base64.b64encode(buf.getbuffer()).decode("ascii")
 

+ 10 - 6
plot/refill/ChannelCovPainter.py

@@ -1,5 +1,5 @@
 from .DataStream import EChPosmap as pos_map
-from .ChannelReader import ChannelReader
+from .ChannelReader import ChannelReader, ChPathFilter
 from .ChannelPainter import ChannelPainter, ratio_pathes
 from matplotlib.figure import Figure
 from matplotlib import ticker
@@ -9,13 +9,16 @@ from .algorithm import calc_cov_chratios
 import time as time
 
 import logging
+
 logger = logging.getLogger('ChannelCumPainter')
 
+
 class ChannelCovPainter(ChannelPainter):
-    def __init__(self, start_time: int, end_time: int, chnames: set = None, card_types: set = None, spec: int = None, filter_wave: int = None):
+    def __init__(self, start_time: int, end_time: int, chnames: set = None, card_types: set = None, spec: int = None, filter_wave: int = None,
+                 show_all: bool = False):
         self._reader = ChannelReader()
         filter_wave = filter_wave or 3600
-        self._chnames, self._card_types, self._spec, self._filter_wave = chnames, card_types, spec, filter_wave
+        self._chnames, self._card_types, self._spec, self._filter_wave, self._show_all = chnames, card_types, spec, filter_wave, show_all
         days, self._start_time, self._end_time, self._interval = self.calc_time(self._reader, start_time, end_time)
         pass
 
@@ -25,8 +28,9 @@ class ChannelCovPainter(ChannelPainter):
         if len(days) == 0:
             return BytesIO()
 
+        filter = ChPathFilter(self._chnames, self._card_types, self._spec, self._show_all)
         tuple_pathes = reader.many_tuple_path(days, self._chnames, self._card_types, self._spec)
-        gen = ratio_pathes(reader, tuple_pathes, days, self._spec)
+        gen = ratio_pathes(reader, tuple_pathes, days, filter)
         day_stamp = days[0]
 
         fig_create, fig_flush = self._fig_funs()
@@ -40,7 +44,7 @@ class ChannelCovPainter(ChannelPainter):
 
         stime = lambda t: time.strftime('%d-%H:%M:%S', time.localtime(t))
         logger.debug("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)
+                     self._start_time, stime(self._start_time), stime(self._end_time), left_len, right_len)
 
         chname_ratios = []
         for _chname, _card_type, _spec, _data in gen:
@@ -58,4 +62,4 @@ class ChannelCovPainter(ChannelPainter):
         result = []
         for name, ratio in chname_ratios:
             result.append(f'{name}:{ratio}')
-        return buf, result
+        return buf, result

+ 15 - 31
plot/refill/ChannelPainter.py

@@ -1,5 +1,5 @@
 from .DataStream import EChPosmap as pos_map, day_stamp, span_days, time_border, calc_interval
-from .ChannelReader import ChannelReader
+from .ChannelReader import ChannelReader, ChPathFilter
 from .PainterBase import PainterBase
 from collections import defaultdict
 from matplotlib.figure import Figure
@@ -21,51 +21,35 @@ def get_channels():
     logger.debug(_all_channels)
     return list(_all_channels)
 
-class ChPathFilter(object):
-    def __init__(self,chnames: set = None, card_types: set = None,spec: int = None,show_all: bool=False):
-        self._chnames = chnames
-        self._card_types = card_types
-        self._spec = spec
-        self._show_all = show_all
-    pass
 
-def ratio_pathes(reader: ChannelReader, tuple_pathes: dict, days: list, spec=None):
+def ratio_pathes(reader: ChannelReader, tuple_pathes: dict, days: list, filter: ChPathFilter = None):
     count = len(days)
-    show_detail = True if len(list(tuple_pathes.keys())) == 1 else False
-    if show_detail == False:
-        all_datas = reader.init_data(count)
-    else:
-        all_datas = None
+    all_datas = None if filter.show_detail() else reader.init_data(count)
+    show_channel = filter.show_channel()
 
     for name, tup in tuple_pathes.items():
         _add_channel(name)
         mch_datas = reader.init_data(count)
-        for _card_type, _spec in tup:
-            if spec is not None and _spec != spec:
-                continue
-
-            if show_detail:
-                detail_datas = reader.init_data(count)
-            else:
-                detail_datas = None
 
+        for _card_type, _spec in tup:
+            detail_datas = reader.init_data(count) if filter.show_detail() else None
             for i, day in enumerate(days):
                 data = reader.read(day, name, _card_type, _spec)
                 if data is not None:
                     column_pos = i * 86400
-                    view = mch_datas[:, column_pos:column_pos + 86400]
-                    view += data
-
-                    if show_detail:
+                    if mch_datas is not None:
+                        view = mch_datas[:, column_pos:column_pos + 86400]
+                        view += data
+                    if detail_datas is not None:
                         view = detail_datas[:, column_pos:column_pos + 86400]
                         view += data
-            if show_detail:
+            if detail_datas is not None:
                 yield name, _card_type, _spec, detail_datas
-        if all_datas is not None:
+        if all_datas is not None and mch_datas is not None:
             all_datas += mch_datas
-        yield name, None, None, mch_datas
-
-    if show_detail == False:
+        if mch_datas is not None and show_channel:
+            yield name, None, None, mch_datas
+    if all_datas is not None:
         yield 'all', None, None, all_datas
 
 

+ 29 - 0
plot/refill/ChannelReader.py

@@ -13,6 +13,35 @@ import logging
 
 logger = logging.getLogger('reader')
 
+class ChPathFilter(object):
+    def __init__(self,chnames: set = None, card_types: set = None,spec: int = None,only_all: bool=False):
+        self._chnames = chnames
+        self._card_types = card_types
+        self._spec = spec
+        self._only_all = only_all
+
+    def channels(self):
+        return self._chnames
+    def card_types(self):
+        return self._card_types
+    def spec(self):
+        return self._spec
+    def only_all(self):
+        return self._only_all
+    def show_detail(self):
+        if self._only_all:
+            return False
+        elif len(self._chnames) == 1:
+            return True
+        else:
+            return False
+    def show_channel(self):
+        if self._only_all:
+            return False
+        else:
+            not_show = self._spec is not None and self._chnames is not None and len(self._chnames) == 1 and self._card_types is not None and len(self._card_types) == 1
+            return not_show == False
+    pass
 
 class ChannelReader(DataReadStream):
     def __init__(self):