stanley-king 2 years ago
parent
commit
29478bd4b0
3 changed files with 60 additions and 14 deletions
  1. 18 1
      plot/plot_control.py
  2. 40 12
      plot/refill/MerchantPainter.py
  3. 2 1
      plot/refill/algorithm.py

+ 18 - 1
plot/plot_control.py

@@ -12,7 +12,7 @@ import signal as sig
 import sys, getopt
 
 from refill import ChannelPainter,MerchantPainter
-from refill import filter_chname,filter_cardtype,filter_mchids
+from refill import filter_chname, filter_cardtype, filter_mchids, get_channels, get_mchids
 
 logging.basicConfig(filename='/var/www/html/data/log/flask.log',
                     format='%(levelname)10s  %(asctime)s  %(name)10s %(thread)d %(message)s',
@@ -61,6 +61,23 @@ def ch_ratio():
     except Exception as ex:
         return onError(ex)
 
+@app.route('/plot/channels')
+def channels():
+    try:
+        channels = get_channels()
+        return jsonify(channels)
+    except Exception as ex:
+        logger.error(ex)
+        return jsonify([])
+
+@app.route('/plot/mchids')
+def mchids():
+    try:
+        mchids = get_mchids()
+        return jsonify(mchids)
+    except Exception as ex:
+        logger.error(ex)
+        return jsonify([])
 
 @app.route('/plot/mch_ratio')
 def mch_ratio():

+ 40 - 12
plot/refill/MerchantPainter.py

@@ -187,12 +187,15 @@ class MerchantPainter(object):
     def _fig_bar_funs(self):
         def create():
             fig = Figure(figsize=(19, 8))
-            ax = fig.subplots()
-            ax.set_title('sending order count monitor')
-            ax.set(xlabel='merchant id', ylabel='count')
-            return ax, fig
+            ax_count, ax_amount = fig.subplots(2, 1)
+            ax_count.set_title('sending order count monitor')
+            ax_count.set(xlabel='merchant id', ylabel='count')
 
-        def flush(ax, fig, xticks=None, xlables=None, yticks=None, ylables=None):
+            ax_amount.set_title('sending order amount monitor')
+            ax_amount.set(xlabel='merchant id', ylabel='amount')
+            return ax_count, ax_amount, fig
+
+        def end(ax, xticks=None, xlables=None, yticks=None, ylables=None):
             if xticks is not None:
                 ax.set_xticks(ticks=xticks)
             if xlables is not None:
@@ -205,13 +208,14 @@ class MerchantPainter(object):
 
             ax.legend()
             ax.grid()
-            fig.autofmt_xdate()
 
+        def flush(fig):
+            fig.autofmt_xdate()
             buf = BytesIO()
             fig.savefig(buf, format="png")
             return buf
 
-        return create, flush
+        return create, end,flush
 
     def paint_refilling(self):
         tuple_pathes = self._reader.many_tuple_path(self._days, self._mchids, self._card_types, self._spec)
@@ -220,8 +224,8 @@ class MerchantPainter(object):
             return BytesIO()
 
         day_stamp = self._days[0]
-        fig_create, fig_flush = self._fig_bar_funs()
-        ax, fig = fig_create()
+        fig_create, fig_end, fig_flush = self._fig_bar_funs()
+        ax_count, ax_amount, fig = fig_create()
 
         lables = list()
         datas = list()
@@ -232,11 +236,17 @@ class MerchantPainter(object):
             send_count, submit_count, succ_count, fail_count, amounts, lack = ret
             logger.debug("mchid=%d send=%d submit=%d succ=%d fail=%d",_mchid,send_count, submit_count, succ_count, fail_count)
 
-        send_count, submit_count, succ_count, fail_count, amounts, lack = zip(*datas)
+        send_count, submit_count, succ_count, fail_count, submit_amount, succ_amount, fail_amount, send_amount, lack = zip(*datas)
+        self.draw_count(ax_count, lables, send_count, submit_count, succ_count, fail_count, fig_end)
+        self.draw_amount(ax_amount, lables, submit_amount, succ_amount, fail_amount, send_amount, lack, fig_end)
+
+        return fig_flush(fig)
+
+    def draw_count(self, ax, lables, send_count, submit_count, succ_count, fail_count, fig_end):
         width = 0.24
         x_asix = np.arange(len(lables))
 
-        rect_send = ax.bar(x_asix - width * 0.5, list(send_count), width, label='send', align='center')
+        rect_send = ax.bar(x_asix - width * 0.5, list(send_count), width, label='sending', align='center')
         rect_submit = ax.bar(x_asix - width * 1.5, list(submit_count), width, label='summit',align='center')
         rect_succ = ax.bar(x_asix + width * 0.5, list(succ_count), width, label='succ',align='center')
         rect_fail = ax.bar(x_asix + width * 1.5, list(fail_count), width, label='fail', align='center')
@@ -246,4 +256,22 @@ class MerchantPainter(object):
         ax.bar_label(rect_succ, padding=0, rotation=270)
         ax.bar_label(rect_fail, padding=0, rotation=270)
 
-        return fig_flush(ax, fig, xticks=x_asix, xlables=lables)
+        fig_end(ax, xticks=x_asix, xlables=lables)
+        pass
+
+    def draw_amount(self, ax, lables, submit_amount, succ_amount, fail_amount, send_amount, lack, fig_end):
+        width = 0.24
+        x_asix = np.arange(len(lables))
+
+        rect_submit = ax.bar(x_asix - width * 1.5, list(submit_amount), width, label='summit',align='center')
+        rect_send = ax.bar(x_asix - width * 0.5, list(send_amount), width, label='sending', align='center')
+        rect_succ = ax.bar(x_asix + width * 0.5, list(succ_amount), width, label='succ',align='center')
+        rect_fail = ax.bar(x_asix + width * 1.5, list(fail_amount), width, label='fail', align='center')
+
+        ax.bar_label(rect_submit, padding=0, rotation=270)
+        ax.bar_label(rect_send, padding=0, rotation=270)
+        ax.bar_label(rect_succ, padding=0, rotation=270)
+        ax.bar_label(rect_fail, padding=0, rotation=270)
+
+        fig_end(ax, xticks=x_asix, xlables=lables)
+        pass

+ 2 - 1
plot/refill/algorithm.py

@@ -38,4 +38,5 @@ def calc_morder_send(data, pos_map: type(EMchPosmap), start: int, end: int):
     send_amounts = sums[pos_map.submit_amounts] - sums[pos_map.succ_mch_amounts] - sums[pos_map.fail_mch_amounts]
     lack_amounts = send_amounts * ratio
 
-    return send_count, sums[pos_map.submit_count], sums[pos_map.succ_count], sums[pos_map.fail_count], send_amounts, lack_amounts
+    return send_count, sums[pos_map.submit_count], sums[pos_map.succ_count], sums[pos_map.fail_count], sums[pos_map.submit_amounts], \
+           sums[pos_map.succ_mch_amounts], sums[pos_map.fail_mch_amounts], send_amounts, lack_amounts