stanley-king 2 年 前
コミット
433bcc97cd

+ 2 - 2
docker/compose/workcuda/cli/docker-compose.yml

@@ -41,8 +41,8 @@ services:
 
   pythoncli:
     image: pyflask:3.7.10
-    ports:
-      - 5000:5000
+#    ports:
+#      - 5000:5000
     volumes:
       - /mnt/xyzshop/docker/compose/workcuda/conf/etc/localtime:/etc/localtime:ro
       - /mnt/xyzshop:/var/www/html

+ 4 - 3
plot/refill/ChSpeedControlCalc.py

@@ -1,7 +1,7 @@
 from .ChannelCalc import ChannelCalc, detail_pathes
 from .algorithm import calc_chspeed, calc_chratio, calc_commit, calc_chprice, calc_chspeed_ratio
 from .DataStream import EChPosmap as pos_map
-from .DataStream import ch_calc_cfgs
+from .DataStream import ch_calc_cfgs,mktime
 from .ChannelReader import ChannelReader
 from .chs_type_spec import type_spec_chs, ch_type_spec
 from .chs_manager import chs_manager
@@ -23,7 +23,8 @@ class ChSpeedControlCalc(ChannelCalc):
         start_period, ratio_period, speed_period, monitor_period, cdf_speed_period = ch_calc_cfgs()
 
         reader = self._reader()
-        end_time = int(time.time())
+        # end_time = int(time.time())
+        end_time = mktime('2022-11-01 11:10:00')
         days, start_time, end_time = self.calc_time(reader, end_time - start_period, end_time)
 
         day_stamp = days[0]
@@ -48,4 +49,4 @@ class ChSpeedControlCalc(ChannelCalc):
         if len(result) != 0:
             rclient.set(f"nc_refill_channel_control_speed", json.dumps(result))
             rclient.publish('refill', json.dumps({'type': 'channel_speed', 'value': 0}))
-        return 300
+        return 180

+ 5 - 12
plot/refill/ChSpeedRatioCalc.py

@@ -1,19 +1,15 @@
 from .ChannelCalc import ChannelCalc, detail_pathes
 from .algorithm import calc_chspeed, calc_chratio, calc_commit, calc_unback_time
 from .DataStream import EChPosmap as pos_map
-from .DataStream import ch_calc_cfgs
+from .DataStream import ch_calc_cfgs, mktime
 from .ChannelReader import ChannelReader
 import time as time
 import json
 import redis
 
 import logging
-logger = logging.getLogger('ChSpeedCalc')
 
-def mktime(strtime):
-    tdata = time.strptime(strtime, "%Y-%m-%d %H:%M:%S")
-    time_stamp = int(time.mktime(tdata))
-    return time_stamp
+logger = logging.getLogger('ChSpeedCalc')
 
 
 class ChSpeedRatioCalc(ChannelCalc):
@@ -22,8 +18,8 @@ class ChSpeedRatioCalc(ChannelCalc):
         start_period, ratio_period, speed_period, monitor_period, cdf_speed_period = ch_calc_cfgs()
 
         reader = self._reader()
-        # end_time = int(time.time())
-        end_time = mktime('2022-11-01 11:10:00')
+        end_time = int(time.time())
+        # end_time = mktime('2022-11-01 11:10:00')
         days, start_time, end_time = self.calc_time(reader, end_time - start_period, end_time)
 
         day_stamp = days[0]
@@ -38,10 +34,7 @@ class ChSpeedRatioCalc(ChannelCalc):
         for _name, _card_type, _spec, _data in gen:
             speed = calc_chspeed(_data, pos_map, end_pos - speed_period, end_pos) / mins
             speed = int(speed)
-            # calc_unback_time(_data, pos_map, end_pos - start_period, end_pos)
             ratio, commit, notify_time, succ_time = calc_chratio(_data, pos_map, end_pos - ratio_period, end_pos)
-            logger.debug(f'{_name}-{_card_type}-{_spec} speed:{speed}')
-
             key = f'{_name}-{_spec}-{_card_type}'
             result[key] = [speed, ratio, commit, notify_time, 0]
             logger.debug("%s-%d-%d speed=%d ratio=%.5f commit=%d notify_time=%.5f succ_time=%.5f",
@@ -50,4 +43,4 @@ class ChSpeedRatioCalc(ChannelCalc):
         if len(result) != 0:
             rclient.set(f"nc_refill_channel_control_model", json.dumps(result))
             rclient.publish('refill', json.dumps({'type': 'channel_control', 'value': 0}))
-        return 0.1
+        return 0.1

+ 7 - 2
plot/refill/DataStream.py

@@ -35,6 +35,11 @@ def open_hdf5(file, is_wirte):
     else:
         return h5py.File(file, 'r', libver='latest') #plot/test_h5py.py
 
+def mktime(strtime):
+    tdata = time.strptime(strtime, "%Y-%m-%d %H:%M:%S")
+    time_stamp = int(time.mktime(tdata))
+    return time_stamp
+
 
 def time_border(interval, time_stamp, lt):
     day = day_stamp(time_stamp)
@@ -77,10 +82,10 @@ def span_days(start_time, end_time):
     return days
 
 def ch_calc_cfgs():
-    ratio_period = 1800
+    start_period = 3600
+    ratio_period = 900
     speed_period = 60
     monitor_period = 600
-    start_period = 3600
     cdf_speed_period = 60
 
     return start_period, ratio_period, speed_period, monitor_period, cdf_speed_period

+ 3 - 1
plot/refill/ch_type_spec.py

@@ -87,8 +87,10 @@ class ch_type_spec(object):
     def init_data(self, data, end_pos):
         logger.debug(f'chname={self._name}')
         start_period, ratio_period, speed_period, monitor_period, cdf_speed_period = ch_calc_cfgs()
+        mins = speed_period / 60
+
         self._price, self._pratio, self._pratio = calc_chprice(data, pos_map, end_pos - speed_period, end_pos)
-        self._speed = calc_chspeed(data, pos_map, end_pos - speed_period, end_pos) / 5
+        self._speed = calc_chspeed(data, pos_map, end_pos - speed_period, end_pos) / mins
         ratio, ratio_commit, self._notify_time, succ_time = calc_chratio(data, pos_map, end_pos - start_period, end_pos)
         monitor_commit = calc_commit(data, pos_map, end_pos - monitor_period, end_pos) / 5
         _commits, _succs, _ratios = calc_chspeed_ratio(data, pos_map, end_pos - start_period, end_pos, cdf_speed_period)

+ 3 - 0
plot/refill/chs_manager.py

@@ -9,6 +9,9 @@ class chs_manager(object):
         pass
 
     def add(self,name, card_type, spec, data,end_pos):
+        if card_type != 4 or spec != 100:
+            return
+
         key_gen = lambda card_type,spec: f'{spec}-{card_type}'
         key = key_gen(card_type,spec)
         if key in self.channels:

+ 7 - 1
plot/refill/chs_type_spec.py

@@ -20,6 +20,7 @@ class type_spec_chs(object):
     def __init__(self, card_type, spec):
         self._card_type = card_type
         self._spec = spec
+        self._no_price = []     #统计时间内第一次使用通道
         self._normal_price = [] #普充通道
         self._over_price = []   #溢价通道
         self._fs = []           #分省通道
@@ -179,6 +180,7 @@ class type_spec_chs(object):
 
             logger.debug(f'card_type={self._card_type} spec={self._spec}')
             item = combination[index]
+
             used, feeds = calc_used(item, min, max)
             return used, feeds
         ##############################################################################################################################################
@@ -189,6 +191,7 @@ class type_spec_chs(object):
         used, feeds = sort_nearst(sumview, combination, total)
         return used, feeds
 
+
     def _fs_optimize(self):
         for chname in self._fs:
             ch_item = self._chs[chname]
@@ -213,10 +216,13 @@ class type_spec_chs(object):
 
         price = ch_item.price()
         pratio = ch_item.pratio()
+
         if price is not None:
             price = int(price * 1000)
 
-        if (price is not None and price >= self._spec * 1000) or (pratio is not None and pratio <= 0):
+        if price is None or pratio is None:
+            self._no_price.append(chname)
+        elif (price is not None and price >= self._spec * 1000) or (pratio is not None and pratio <= 0):
             self._over_price.append(chname)
         elif is_fs(chname):
             self._fs.append(chname)

+ 40 - 6
plot/testPlot.py

@@ -99,17 +99,17 @@ 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)
-        itema = {'channel_name':'zero', 'time':int(time.time()), 'spec':50, 'card_type':4, 'channel_amount':49, 'period':30}
-        itemb = {'channel_name':'xxxxxx', 'time':int(time.time()), 'spec':50, 'card_type':4, 'channel_amount':49, 'period':30,'mch_amount':49.625}
-        chwriter.write('ch_succ',itema)
-        chwriter.write('ch_succ',itemb)
+        itema = {'channel_name': 'zero', 'time': int(time.time()), 'spec': 50, 'card_type': 4, 'channel_amount': 49, 'period': 30}
+        itemb = {'channel_name': 'xxxxxx', 'time': int(time.time()), 'spec': 50, 'card_type': 4, 'channel_amount': 49, 'period': 30,
+                 'mch_amount': 49.625}
+        chwriter.write('ch_succ', itema)
+        chwriter.write('ch_succ', itemb)
 
     def test_netcheck(self):
         from refill import NetchkReader
@@ -260,10 +260,44 @@ class MyTestCase(unittest.TestCase):
                 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
 
+    def testFindLowest(self):
+        #ratios = {'feimingyu_high': 1,'feimingyu_high': 5 / 215, 'lechong': 4 / 2108, 'lechong_high': 4 / 2223, 'weixue': 13 / 17101, 'yunchonggong': 7 / 23276,'yunchonggongx': 1 / 232760}
+        ratios = {'feimingyu_high': 0.05,'feimingyu_high': 5 / 215, 'lechong': 4 / 2108, 'lechong_high': 4 / 2223, 'weixue': 0.1, 'yunchonggong': 7 / 23276,'yunchonggongx': 1 / 232760}
+        # ratios = {'feimingyu_high': 0.9, 'lechong': 4 / 2108, 'lechong_high': 4 / 2223, 'weixue': 13 / 17101, 'yunchonggong': 1 / 23276}
+        # ratios = {'lechong': 4 / 2108, 'lechong_high': 4 / 2223, 'weixue': 13 / 17101, 'yunchonggong': 1 / 23276}
+        # ratios = {'feimingyu_high': 5 / 215, 'lechong': 4 / 2108, 'lechong_high': 4 / 2223, 'weixue': 13 / 17101, 'yunchonggong': 1 / 23276}
+        # ratios = {'feimingyu_high': 1, 'lechong': 4 / 2108, 'lechong_high': 4 / 2223, 'weixue': 13 / 17101, 'yunchonggong': 1 / 23276}
+        # def classify_ratio(ratios):
+        #     result = {}
+        #     for name,ratio in ratios.items():
+        #         if round(ratio,2) >= 0.1:
+        #             result[1] =
+
+        import math,cmath
+
+        def calc_avg(ratios):
+            total = 0.0
+            for name, ratio in ratios.items():
+                x = cmath.log(ratio)
+                log.debug(f'log={x}')
+                total += ratio
+            return total / len(ratios)
+
+        avg = calc_avg(ratios)
+        left = dict()
+        for name, ratio in ratios.items():
+            if ratio < avg:
+                left[name] = ratio
+
+        for name, ratio in ratios.items():
+            rate = ratio / avg
+            alpha = rate * rate
+
+            log.debug(f'{name} rate:{rate} alpha:{alpha}')
 
 if __name__ == '__main__':
     unittest.main()