stanley-king vor 2 Jahren
Ursprung
Commit
537f8eadc3

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

@@ -181,11 +181,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:

+ 1 - 1
helper/refill/policy/chctlex.php

@@ -375,7 +375,7 @@ class chctlex
 
         //working .....
         $names = array_unique($names);
-        Log::record("auto_match outprice= {$out_price} names=" . implode(',', $names), Log::DEBUG);
+        Log::record("auto_match outprice= {$out_price} max_inprice={$max_inprice} names=" . implode(',', $names), Log::DEBUG);
         $ctls = $price_filter($names, $spec, $card_type, $quality);
         $ctlitem_logger("price filter", $ctls);
 

+ 23 - 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,27 @@ 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 start_time 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 = painter.paint()
+        data = base64.b64encode(buf.getbuffer()).decode("ascii")
+        return f"<img src='data:image/png;base64,{data}'/>"
+        # return buf
+        # 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 +218,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()
 

+ 81 - 0
plot/refill/ChannelSpeedAnalyzePainter.py

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

+ 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 = int(time.time()) - 6 * 86400 - 7200
+        end_time = int(time.time()) - 6 * 86400
+        painter = ChannelSpeedAnalyzePainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6})
+        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):