stanley-king 2 years ago
parent
commit
978f64cde4

+ 0 - 3
admin/templates/default/analysis.cov.provider.php

@@ -182,11 +182,8 @@
     $(function() {
 
         var provider = <?php echo json_encode($output['providers']) ?>
-
         let ratios = [];
-
         let qualitys = [];
-
         const defaultChannelType = <?php echo refill\Quality::Normal; ?>;
 
         $.get(`index.php?act=refill_analysis&op=provider_data`, function(data) {

+ 1 - 0
docker/compose/homecuda/storage/docker-compose.yml

@@ -9,6 +9,7 @@ services:
       - ../conf/etc/localtime:/etc/localtime:ro
       - ../conf/redis/6379.conf:/etc/redis/redis.conf
       - /mnt/redisdata:/data
+    restart: always
     container_name: "panda-redis"
     command: [redis-server,"/etc/redis/redis.conf"]
     deploy:

+ 20 - 2
plot/app.py

@@ -21,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
+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
 
@@ -69,6 +69,24 @@ def ch_ratio():
     except Exception as ex:
         return onError(ex)
 
+@app.route('/plot/ch_speed_ratio')
+def ch_speed_ratio():
+    try:
+        logger.debug('start ch_speed_ratio')
+        start_time, end_time, card_types, spec, filter_wave = parse_parmeter()
+        chnames = request.args.get('chnames')
+        chnames = filter_chname(chnames)
+        period = request.args.get('period')
+        period = 60 if period is None else int(period.strip())
+
+        painter = ChannelSpeedAnalyzePainter(start_time=start_time, end_time=end_time,
+                                             chnames=chnames, card_types=card_types, spec=spec,
+                                             period=period)
+        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():
@@ -197,7 +215,7 @@ def mch_order_send():
 
 
 if __name__ == "__main__":
-    debug_mode = False
+    debug_mode = True
     if debug_mode:
         app.run(debug=True, host='0.0.0.0', port=5000)
     else:

+ 0 - 1
plot/refill/ChannelPainter.py

@@ -76,7 +76,6 @@ class ChannelPainter(PainterBase):
             ax.set_xticklabels(lables)
             fig.autofmt_xdate()
             ax.grid()
-            # fig.subplots_adjust(left=0.1, right=0.8, top=0.95, bottom=0.1)
             ax.legend(bbox_to_anchor=(1, 1), loc='upper left')
             fig.tight_layout()
 

+ 121 - 0
plot/refill/ChannelSpeedAnalyzePainter.py

@@ -0,0 +1,121 @@
+from .DataStream import EChPosmap as pos_map
+from .ChannelReader import ChannelReader
+from .ChannelPainter import ChannelPainter, ratio_pathes, get_channels
+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 _succ_hist(self, y, ax_histx):
+        vals,pos,_1 = ax_histx.hist(y)
+        if len(pos) >= 2:
+            interval = (pos[1] - pos[0]) / 5
+        else:
+            interval = 0
+
+        for i in range(len(vals)):
+            ax_histx.annotate(text=int(vals[i]),xy = (pos[i] + interval,vals[i]))
+        ax_histx.grid()
+
+    def _fig_create(self):
+        fig = Figure(figsize=(16, 8))
+        gs = fig.add_gridspec(nrows=2, ncols=4, height_ratios=(2, 6), width_ratios=(4, 4, 4, 4))
+        ax_hist_succs = fig.add_subplot(gs[0, :])
+        ax_scatter = fig.add_subplot(gs[1, 0])
+        ax_succ_cdf = fig.add_subplot(gs[1, 1])
+        ax_ratio_cdf = fig.add_subplot(gs[1, 2])
+        ax_ratio_latest = fig.add_subplot(gs[1, 3])
+        return fig, ax_hist_succs, ax_scatter, ax_succ_cdf, ax_ratio_cdf, ax_ratio_latest
+
+    def _flush(self, fig, ax_scatter, ax_succ_cdf, ax_hist_succs, ax_ratio_cdf, ax_ratio_latest):
+        ax_scatter.grid()
+        ax_hist_succs.grid()
+        ax_ratio_cdf.grid()
+        ax_ratio_latest.grid()
+        ax_succ_cdf.grid()
+        fig.tight_layout()
+
+        buf = BytesIO()
+        fig.savefig(buf, format="png")
+        return buf
+
+    def _succ_cdf(self, succs, commits, ax_count, ax_ratio,ax_latest):
+        min = np.min(commits)
+        max = np.max(commits)
+
+        x = [i for i in range(0, max + 1, 1)]
+        y = []
+
+        for i in x:
+            pos = np.where(commits == i)
+            succ = succs[pos]
+            count = np.sum(succ)
+            y.append(count)
+
+        y = np.array(y)
+        succ = np.sum(y)
+        y = np.cumsum(y)
+
+        ax_count.plot(x, y, ls='-')
+        ratio = y / (succ + 0.00000001)
+        ax_ratio.plot(x, ratio, ls='-')
+
+        pos = np.where(y == succ)
+        if len(pos[0]) > 1:
+            end = pos[0][1]
+            x = x[:end]
+            ratio = ratio[:end]
+        ax_latest.plot(x, ratio, ls='-')
+        pass
+
+    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 = []
+        fig, ax_hist_succs, ax_scatter, ax_succ_cdf, ax_ratio_cdf, ax_ratio_latest = self._fig_create()
+        for _chname, _card_type, _spec, _data in gen:
+            # if _card_type is not None and _spec is not None:
+            logger.debug(f'chname={_chname} card_type={_card_type} spec={_spec}')
+            _commits, _succs, _ratios = calc_chspeed_ratio(_data, pos_map, _start_time - day_stamp, _end_time - day_stamp, self._period)
+            ax_scatter.scatter(_commits, _succs)
+            commits.extend(_commits)
+            succs.extend(_succs)
+            ratios.extend(ratios)
+
+        succs = np.array(succs).astype(int)
+        commits = np.array(commits).astype(int)
+
+        self._succ_hist(succs,ax_hist_succs)
+        self._succ_cdf(succs,commits,ax_succ_cdf,ax_ratio_cdf,ax_ratio_latest)
+        buf = self._flush(fig, ax_scatter, ax_succ_cdf, ax_hist_succs, ax_ratio_cdf, ax_ratio_latest)
+
+        result = []
+        channels = get_channels()
+        for name in channels:
+            result.append(f'{name}:0.00')
+        return buf,result

+ 2 - 1
plot/refill/__init__.py

@@ -11,6 +11,7 @@ from .ChannelReader import ChannelReader
 from .ChannelCumPainter import ChannelCumPainter
 from .ChannelCovPainter import ChannelCovPainter
 from .ChannelCovSuccPainter import ChannelCovSuccPainter
+from .ChannelSpeedAnalyzePainter import ChannelSpeedAnalyzePainter
 
 from .ChannelPainter import get_channels
 from .MerchantPainter import get_mchids
@@ -34,7 +35,7 @@ from .server_util import opt_parse
 __all__ = ['DataWriteStream', 'DataReadStream',
            'MerchantWriter', 'ChannelWriter', 'NetchkWriter', 'WriteConsumer',
            'MerchantReader', 'NetchkReader', 'ChannelReader',
-           'ChannelCumPainter', 'ChannelCovPainter', 'ChannelCovSuccPainter',
+           'ChannelCumPainter', 'ChannelCovPainter', 'ChannelCovSuccPainter', 'ChannelSpeedAnalyzePainter',
            'MerchantCumRatioPainter', 'MerchantAmountPainter', 'MerchantCovRatioPainter',
            'get_channels', 'get_mchids',
            'queueListener', 'open_hdf5', 'day_stamp', 'time_border',

+ 13 - 1
plot/refill/algorithm.py

@@ -2,7 +2,7 @@ from .DataStream import EMchPosmap
 import numpy as np
 import logging
 
-logger = logging.getLogger('calcer')
+logger = logging.getLogger('algorithm')
 
 
 def calc_chratios(data, pos_map, start, end, window, left_len, right_len):
@@ -49,6 +49,18 @@ def calc_cov_chratios(data, pos_map, start, end, window, left_len,right_len = 0)
 
     return succs, commits, y
 
+
+def calc_chspeed_ratio(data, pos_map, start, end, period):
+    dim = pos_map.dim()
+    view = data[:, start:end]
+    sum_view = view.reshape((dim, -1, period))
+    sums = np.sum(sum_view, axis=2)
+
+    succs = sums[pos_map.succ_count]
+    commits = sums[pos_map.commit_count]
+    ratios = succs / (commits + 0.000001)
+    return commits, succs, ratios
+
 def calc_cov_chsuccs(data, pos_map, start, end, window, left_len,right_len):
     view = data[[pos_map.succ_count, pos_map.fail_count, pos_map.commit_count], :]
     view = view[:, start:end]

+ 8 - 0
plot/testPlot.py

@@ -51,6 +51,14 @@ class MyTestCase(unittest.TestCase):
         painter = ChannelCumPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6})
         painter.paint()
 
+    def test_ch_speed_analyze_painter(self):
+        from refill import ChannelSpeedAnalyzePainter
+
+        start_time = 1664632800
+        end_time = 1664640000
+        painter = ChannelSpeedAnalyzePainter(start_time=start_time, end_time=end_time, chnames=set(['feimingyunew']), card_types={4},spec=100)
+        painter.paint()
+
     def test_chcov_ratio(self):
         from refill import ChannelCovPainter
 

+ 1 - 1
plot/test_h5py.py

@@ -16,7 +16,7 @@ class MyTestCase(unittest.TestCase):
     def test_chunk(self):
         file = '/var/www/html/data/stdata/test.hdf5'
         hfive = open_hdf5(file, True)
-        dset = hfive.create_dataset('chunkede', (8, 86400),chunks=(8,3600))
+        dset = hfive.create_dataset('chunkede', (8, 86400), chunks=(8, 3600))
         print(dset.chunks)
         print(time.time())
         for i in range(8):