stanley-king пре 2 година
родитељ
комит
2c2155ae58

+ 13 - 4
plot/refill/ChannelCovPainter.py

@@ -92,16 +92,25 @@ class ChannelCovPainter(ChannelPainter):
 
         fig, ax_succ_cdf, ax_commit_cdf, ax_ratio = self._fig_create()
         line_lables = []
+
+        index = 0;
         for _chname, _card_type, _spec, _data in gen:
+            color = self.color(index)
+            index += 1
+
             _succ, _commit, y, _succ_period, _fail_period = calc_cov_chratios(_data, pos_map, _start_time - day_stamp, _end_time - day_stamp, window,
                                                                             left_len, right_len)
             _succs,_commits = calc_count_cdf(_data, pos_map, _start_time - day_stamp, _end_time - day_stamp, left_len, right_len)
 
-            label = self._label_simple(chname=_chname, card_type=_card_type, spec=_spec)
+            label = self._label_simple(chname=_chname, filter=filter, card_type=_card_type, spec=_spec)
             line_lables.append(label)
-            ax_ratio.plot(x, y, ls='-')
-            ax_succ_cdf.plot(x, _succs, ls='-')
-            ax_commit_cdf.plot(x, _commits, ls='-')
+
+            ax_ratio.plot(x, y, ls='-', color=color)
+            ax_succ_cdf.plot(x, _succs, ls='-', color=color)
+            ax_commit_cdf.plot(x, _commits, ls='-', color=color)
+            # ax_ratio.plot(x, y, ls='-')
+            # ax_succ_cdf.plot(x, _succs, ls='-')
+            # ax_commit_cdf.plot(x, _commits, ls='-')
 
             if _card_type is None and _spec is None and _chname != 'all':
                 _ratio = _succ / (_commit + 0.00001)

+ 33 - 3
plot/refill/ChannelPainter.py

@@ -107,8 +107,38 @@ class ChannelPainter(PainterBase):
 
         return lable, ratio
 
-    def _label_simple(self, chname, card_type=None, spec=None):
+    def _label_simple(self, chname, filter, card_type=None, spec=None):
+        def scard_type(card_type):
+            if card_type == 1:
+                _card_type = 'SY'
+            elif card_type == 2:
+                _card_type = 'SH'
+            elif card_type == 4:
+                _card_type = 'YD'
+            elif card_type == 5:
+                _card_type = 'LT'
+            elif card_type == 6:
+                _card_type = 'DX'
+            elif card_type == 7:
+                _card_type = 'TH'
+            else:
+                _card_type = ""
+            return _card_type
+
         if card_type is None and spec is None:
             return chname
-        if card_type is not None and spec is not None:
-            return chname
+
+        channels = filter.channels()
+        if channels is None or len(channels) > 1:
+            return f'{chname}-{scard_type(card_type)}'
+        else:
+            return f'{scard_type(card_type)}-{spec}'
+
+
+
+
+
+
+
+
+

+ 0 - 1
plot/refill/ChannelWriter.py

@@ -123,7 +123,6 @@ class ChannelWriter(DataWriteStream):
     def path_pos(self, chname, time, spec, card_type):
         today = day_stamp(time)
         path = f'/{self._version}/{today}/{chname}/{card_type}/{spec}'
-        # log.debug("%s,%s", 'ChannelWriter', path)
 
         dset = self._data_set(path=path)
         return dset, time - today

+ 5 - 1
plot/refill/DataStream.py

@@ -209,7 +209,6 @@ class EMchPosmap(IntEnum):
     @staticmethod
     def dim():
         return 7
-
     pass
 
 
@@ -222,11 +221,16 @@ class EChPosmap(IntEnum):
     fail_count = 5
     fail_amounts = 6
     fail_periods = 7
+    succ_mch_amounts = 8
 
     @staticmethod
     def dim():
         return 8
 
+    @staticmethod
+    def old_dim():
+        return 8
+
     pass
 
 

+ 14 - 0
plot/refill/PainterBase.py

@@ -7,6 +7,18 @@ from .DataStream import span_days, day_stamp, span_days, time_border, calc_inter
 import logging
 logger = logging.getLogger('PainterBase')
 
+all_colors = ['#000000', '#0000FF', '#FF0000', '#FF00FF', '#FFFF00', '#00FFFF', '#00FF00', '#00FF80', '#008080', '#808080', '#80FFFF',
+          '#800080', '#FF8000', '#800000', '#008000', '#8080FF', '#FF8080', '#8000FF', '#808000', '#0080FF', '#80FF80', '#80FF00', '#FF0080',
+          '#FF80FF', '#FFFF80', '#000080', '#400000', '#400040', '#4040FF', '#FF4000', '#408000', '#FF40FF', '#FFFF40', '#40FF40', '#FF4080',
+          '#40FFFF', '#404000', '#808040', '#FF8040', '#804000', '#00FF40', '#000040', '#40FF80', '#408040', '#FF0040', '#804040', '#40FF00',
+          '#008040', '#800040', '#FF4040', '#804080', '#400080', '#404040', '#004000', '#4080FF', '#0040FF', '#004040', '#80FF40', '#4000FF',
+          '#404080', '#004080', '#8040FF', '#408080', '#8000C0', '#C000C0', '#C0C0C0', '#40C000', '#40C080', '#FFC000', '#C0C0FF', '#C040FF',
+          '#C000FF', '#FFC080', '#FF00C0', '#40C040', '#40C0C0', '#80C040', '#4040C0', '#80C0FF', '#4000C0', '#00C040', '#C00040', '#00C0C0',
+          '#8040C0', '#40C0FF', '#C08080', '#C00080', '#C0FFC0', '#C0C040', '#80C080', '#8080C0', '#C04080', '#C080C0', '#C04040', '#FFC0FF',
+          '#C040C0', '#00C080', '#C0C080', '#40FFC0', '#C080FF', '#FF80C0', '#00FFC0', '#C0FFFF', '#C0FF00', '#C0FF40', '#C00000', '#FFFFC0',
+          '#FFC040', '#80C000', '#0040C0', '#C04000', '#00C0FF', '#FF40C0', '#80C0C0', '#FFC0C0', '#C0FF80', '#0080C0', '#00C000', '#80FFC0',
+          '#0000C0', '#4080C0', '#C0C000', '#C08000', '#C08040']
+
 class PainterBase(object):
     def __init__(self):
         self._redis_client = None
@@ -67,3 +79,5 @@ class PainterBase(object):
 
         return xticks,xlables
 
+    def color(self,index):
+        return all_colors[index]

+ 22 - 16
plot/testPlot.py

@@ -56,7 +56,7 @@ class MyTestCase(unittest.TestCase):
 
         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 = ChannelSpeedAnalyzePainter(start_time=start_time, end_time=end_time, chnames=set(['feimingyunew']), card_types={4}, spec=100)
         painter.paint()
 
     def test_chcov_ratio(self):
@@ -64,7 +64,7 @@ class MyTestCase(unittest.TestCase):
 
         start_time = int(time.time()) - 10 * 86400 - 3600
         end_time = int(time.time()) - 10 * 86400
-        painter = ChannelCovPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6},filter_wave=3600)
+        painter = ChannelCovPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6}, filter_wave=3600)
         painter.paint()
 
     def test_chcov_succ(self):
@@ -72,7 +72,7 @@ class MyTestCase(unittest.TestCase):
 
         start_time = int(time.time()) - 20 * 86400 - 3600
         end_time = int(time.time()) - 20 * 86400
-        painter = ChannelCovSuccPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6},filter_wave=3600)
+        painter = ChannelCovSuccPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6}, filter_wave=3600)
         painter.paint()
 
     def test_mch_ratio_painter(self):
@@ -99,14 +99,24 @@ class MyTestCase(unittest.TestCase):
         painter = MerchantAmountPainter(start_time=start_time, end_time=end_time, mchids=set(), card_types={4, 5, 6})
         painter.paint()
 
+
+    def test_ChannelWriter(self):
+        from refill import ChannelWriter, open_hdf5
+        import time
+
+        hfive = open_hdf5('/var/www/html/data/stdata/channel.hdf5', True)
+        chwriter = ChannelWriter(hfive)
+        item = {'channel_name':'zero', 'time':time.time(), 'spec':50, 'card_type':4, 'channel_amount':49, 'period':30}
+        chwriter.write('ch_succ',item)
+
     def test_netcheck(self):
         from refill import NetchkReader
         import time
         from refill import day_stamp
 
         day = day_stamp(int(time.time()) - 4 * 86400)
-        days = [day,day-86400]
-        
+        days = [day, day - 86400]
+
         net = NetchkReader()
         channels = net.tuple_path(day)
         channels = net.many_tuple_path(days)
@@ -209,7 +219,7 @@ class MyTestCase(unittest.TestCase):
                 time.sleep(0.01)
 
         handler = PrintHandler()
-        consumer = WriterConsumer(handler,'PrintHandler')
+        consumer = WriterConsumer(handler, 'PrintHandler')
         consumer.start()
 
         for i in range(100000):
@@ -221,8 +231,8 @@ class MyTestCase(unittest.TestCase):
         from collections import defaultdict
         import time as time
 
-        def merge(l,r):
-            for name,ls in l.items():
+        def merge(l, r):
+            for name, ls in l.items():
                 if name in r:
                     ls.extend(r[name])
                     k = set(ls)
@@ -235,27 +245,23 @@ class MyTestCase(unittest.TestCase):
         a = {'yunchonggongfs': [(4, 100), (4, 30), (4, 50)]}
         b = {'yunchonggongfs': [(4, 100), (4, 200), (4, 50)]}
 
-        all = merge(a,all)
-        all = merge(b,all)
+        all = merge(a, all)
+        all = merge(b, all)
         x = 0;
 
     def test_split(self):
         def split_card(card_specs):
             result = dict()
-            for card_type,spec in card_specs:
+            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),]
+        tups = [(4, 100), (4, 50), (5, 10), (4, 30), (5, 30), (6, 100), (5, 100), ]
         x = split_card(tups)
         y = 1
 
 
-
-
-
 if __name__ == '__main__':
     unittest.main()