Selaa lähdekoodia

fix:成功率计算按照回调成功+回调失败为总量

stanley-king 3 vuotta sitten
vanhempi
commit
615ed3517f
3 muutettua tiedostoa jossa 30 lisäystä ja 9 poistoa
  1. 4 0
      helper/refill/RefillBase.php
  2. 11 0
      helper/refill/util.php
  3. 15 9
      plot/MchDataCenter.py

+ 4 - 0
helper/refill/RefillBase.php

@@ -158,6 +158,10 @@ class RefillBase
             Log::record("Error:" . $ex->getMessage(), Log::ERR);
         }
 
+        if(!$success) {
+            util::incr_user_fail($mchid,$card_type, $spec,$org_quality);
+        }
+
         $mod_refill->edit($order_id, ['notify_time' => time(), 'is_retrying' => 0,'notify_state' => 1]);
         util::pop_queue_order($mchid,$mch_order);
         QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);

+ 11 - 0
helper/refill/util.php

@@ -391,6 +391,17 @@ class util
         $ins->hIncrBy($name, $key_sec, 1);
     }
 
+    public static function incr_user_fail($mchid,$card_type, $spec,$quality)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'user_monitor_fail';
+        $sec = time();
+        $key_sec = "{$mchid}-{$quality}-{$card_type}-{$spec}-{$sec}";
+
+        $ins->hIncrBy($name, $key_sec, 1);
+    }
+
     public static function incr_commit($chname, $card_type, $spec, $quality, $fsuccess = true)
     {
         $ins = Cache::getInstance('cacheredis');

+ 15 - 9
plot/MchDataCenter.py

@@ -13,7 +13,7 @@ import logging
 
 class MchDataCenter(object):
     pos_map = {
-        'commit': 0, 'notify': 1
+        'commit': 0, 'success': 1, 'fail': 2
     }
 
     def __init__(self):
@@ -42,11 +42,13 @@ class MchDataCenter(object):
                     hfive = h5py.File(self._file_name, 'w')
 
                 self.read_redis(hfive, r, 'nc_user_monitor_commit', 'commit')
-                self.read_redis(hfive, r, 'nc_user_monitor_success', 'notify')
+                self.read_redis(hfive, r, 'nc_user_monitor_success', 'success')
+                self.read_redis(hfive, r, 'nc_user_monitor_fail', 'fail')
                 hfive.close()
 
                 self.del_redis(r, 'nc_user_monitor_commit')
                 self.del_redis(r, 'nc_user_monitor_success')
+                self.del_redis(r, 'nc_user_monitor_fail')
             except Exception as ex:
                 print(ex)
             finally:
@@ -94,7 +96,8 @@ class MchDataCenter(object):
         today = self.day_stamp(time)
         path = f'/{today}/{mchid}/{quality}/{card_type}/{amount}'
         if path not in hfive:
-            hfive[path] = np.zeros((2, 86400))
+            dim = len(self.pos_map)
+            hfive[path] = np.zeros((dim, 86400))
 
         diff = time - today
         if diff < 0:
@@ -190,7 +193,8 @@ class MchDataCenter(object):
             fig = Figure(figsize=(16, 8))
             ax = fig.subplots()
 
-            predata = np.zeros((2, 86400))
+            dim = len(self.pos_map)
+            predata = np.zeros((dim, 86400))
             x = np.arange(0, 86400, interval)
 
             sub_count = 0
@@ -235,7 +239,8 @@ class MchDataCenter(object):
 
     def _read_dict_data(self, hfive, mchPaths):
         for mchid, paths in mchPaths.items():
-            predata = np.zeros((2, 86400))
+            dim = len(self.pos_map)
+            predata = np.zeros((dim, 86400))
             for path in paths:
                 predata += hfive[path]
             yield mchid, predata
@@ -299,10 +304,10 @@ class MchDataCenter(object):
         return filer_text, paths
 
     def _draw_plot(self, ax, x, day_stamp, start_pos, end_pos, data, interval=300, path=''):
-        # 'commit-succ': 0, 'commit-fail': 1, 'notify-succ': 2, 'notify-fail': 3, 'user_succ': 4
+        # 'commit-succ': 0, 'notify-succ': 1, 'notify-fail': 2
         logging.getLogger('app').debug("path=%s", path)
 
-        all = data[0]
+        all = data[1] + data[2]
         all = all.reshape((-1, interval))
         all = np.sum(all, axis=1)
 
@@ -389,13 +394,14 @@ class MchDataCenter(object):
         return result
 
     def _merge_data(self, hfive, paths):
-        predata = np.zeros((2, 86400))
+        dim = len(self.pos_map)
+        predata = np.zeros((dim, 86400))
         for path in paths:
             predata += hfive[path]
         return predata
 
     def _calc_mratio(self,data,startes,end):
-        all = data[0]
+        all = data[1] + data[2]
         ySucc = data[1]
         x = np.arange(0, 86400, 1)