stanley-king 2 年之前
父節點
當前提交
8cb36bff05
共有 3 個文件被更改,包括 68 次插入3 次删除
  1. 12 3
      plot/refill/MTimesRatioCalc.py
  2. 41 0
      plot/refill/MerchantCalc.py
  3. 15 0
      plot/testPlot.py

+ 12 - 3
plot/refill/MTimesRatioCalc.py

@@ -1,4 +1,4 @@
-from .MerchantCalc import MerchantCalc, mch_paths
+from .MerchantCalc import MerchantCalc, mch_cardtype_paths
 from .algorithm import calc_mchratios_val
 from .DataStream import EMchPosmap as pos_map
 from .DataStream import day_stamp
@@ -35,7 +35,9 @@ class MTimesRatioCalc(MerchantCalc):
         start_end_tups = calc_start_end([900, 1800, 3600, 7200, 86400], end_time - day_start)
 
         tuple_pathes = reader.many_tuple_path(days)
-        gen = mch_paths(reader, tuple_pathes, days)
+        gen = mch_cardtype_paths(reader, tuple_pathes, days)
+
+        card_types = {None: 'ALL', 4: 'YD', 5: 'LT', 6: 'DX'}
 
         result = dict()
         for _mchid, _card_type, _spec, _data in gen:
@@ -43,7 +45,14 @@ class MTimesRatioCalc(MerchantCalc):
                 succs, fails, ratio = calc_mchratios_val(_data, pos_map, start, end)
                 if _mchid not in result:
                     result[_mchid] = dict()
-                result[_mchid][secs] = [succs, fails, ratio]
+
+                if _card_type not in card_types:
+                    continue
+
+                name = card_types[_card_type]
+                if name not in result[_mchid]:
+                    result[_mchid][name] = dict()
+                result[_mchid][name][secs] = [succs, fails, ratio]
 
         if len(result) != 0:
             rclient.set(f"nc_merchant_ratios", json.dumps(result))

+ 41 - 0
plot/refill/MerchantCalc.py

@@ -49,6 +49,47 @@ def mch_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
                     view += data
         yield mchid, None, None, mch_datas
 
+def mch_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
+    count = len(days)
+    for mchid, tup in tuple_pathes.items():
+        mch_datas = reader.init_data(count)
+        for _card_type, _spec in tup:
+            for i, day in enumerate(days):
+                data = reader.read(day, mchid, _card_type, _spec)
+                if data is not None:
+                    column_pos = i * 86400
+                    view = mch_datas[:, column_pos:column_pos + 86400]
+                    view += data
+        yield mchid, None, None, mch_datas
+
+def mch_cardtype_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
+    def split_card(card_specs):
+        result = dict()
+        for card_type,spec in card_specs:
+            if card_type not in result:
+                result[card_type] = []
+            result[card_type].append(spec)
+        return result
+
+    count = len(days)
+    for mchid, tup in tuple_pathes.items():
+        mch_datas = reader.init_data(count)
+        card_specs = split_card(tup)
+        for _card_type, specs in card_specs.items():
+            card_type_data = reader.init_data(count)
+            for _spec in specs:
+                for i, day in enumerate(days):
+                    data = reader.read(day, mchid, _card_type, _spec)
+                    if data is not None:
+                        column_pos = i * 86400
+                        view = mch_datas[:, column_pos:column_pos + 86400]
+                        view += data
+
+                        view = card_type_data[:, column_pos:column_pos + 86400]
+                        view += data
+            yield mchid, _card_type, None, card_type_data
+        yield mchid, None, None, mch_datas
+
 def allpathes(reader: MerchantReader, tuple_pathes: dict, days: list, spec=None):
     count = len(days)
     show_detail = True if len(list(tuple_pathes.keys())) == 1 else False

+ 15 - 0
plot/testPlot.py

@@ -203,6 +203,21 @@ class MyTestCase(unittest.TestCase):
         all = merge(b,all)
         x = 0;
 
+    def test_split(self):
+        def split_card(card_specs):
+            result = dict()
+            for card_type,spec in card_specs:
+                if card_type not in result:
+                    result[card_type] = []
+                result[card_type].append(spec)
+            return result
+
+
+        tups = [(4, 100),  (4, 50) ,(5,10),(4, 30),(5,30),(6,100),(5,100),]
+        x = split_card(tups)
+        y = 1
+
+