stanley-king 2 年之前
父節點
當前提交
dbcade0703

+ 2 - 2
data/config/dev/base.ini.php

@@ -55,14 +55,14 @@ if(SSH_TUNEL_PROD ==='local') {
     $config['db'][1]['dbport']       = '3306';
     $config['db'][1]['dbuser']       = 'root';
     $config['db'][1]['dbpwd']        = '55668899';
-    $config['db'][1]['dbname']       = 'xyzshop';
+    $config['db'][1]['dbname']       = 'ylshop';
     $config['db'][1]['dbcharset']    = 'UTF-8';
 
     $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
     $config['db']['slave'][0]['dbport']     = '3306';
     $config['db']['slave'][0]['dbuser']     = 'root';
     $config['db']['slave'][0]['dbpwd']      = '55668899';
-    $config['db']['slave'][0]['dbname']     = 'xyzshop';
+    $config['db']['slave'][0]['dbname']     = 'ylshop';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
 }
 elseif(SSH_TUNEL_PROD === 'xyz') {

文件差異過大導致無法顯示
+ 5378 - 258
data/config/dev/refill.ini.php


+ 6 - 1
helper/refill/RefillBase.php

@@ -452,7 +452,7 @@ class RefillBase
             $spec = $order->spec();
             $quality = $order->cur_quality();
 
-            [$state, $errmsg, $neterr] = $provider->add($card_no, $card_type, $spec, $params,$net_errno);
+            [$state, $errmsg, $neterr] = $provider->add($card_no, $card_type, $spec, $params, $net_errno);
             Log::record(sprintf(" %s add request time=%.6f: state={$state} neterr={$neterr},net_errno={$net_errno}", $channel_name,microtime(true) - $start), Log::DEBUG);
 
             if ($state)
@@ -891,6 +891,11 @@ class RefillBase
         $this->mPolicy->update_mchratios($gross,$detail);
     }
 
+    public function UpdateChctl($params)
+    {
+        $this->mPolicy->update_chctl($params);
+    }
+
     public function UpdateRatio($ratios)
     {
         $this->mPolicy->update_ratios($ratios);

+ 1 - 0
helper/refill/XYZRefillFactory.php

@@ -16,6 +16,7 @@ require_once(BASE_HELPER_PATH . '/refill/policy/try_judge.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/chctlex.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/ctl_itemex.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchoilctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/times_caller.php');

+ 105 - 317
helper/refill/policy/chctlex.php

@@ -86,7 +86,7 @@ class chctlex
                     if($opened == false) continue;
 
                     $key = $this->prefix($name,$amount,$card_type,$quality);
-                    $this->mSpeedtable[$key] = new ctl_item($name,$card_type,$amount,$speed,$sort,0,$opened,$quality);
+                    $this->mSpeedtable[$key] = new ctl_itemex($name,$card_type,$amount,$speed,$sort,0,$opened,$quality);
                     $this->mNameMapQuality["{$name}-{$card_type}-{$amount}"] = $quality;
                 }
             }
@@ -95,32 +95,22 @@ class chctlex
 
     public function update_chctl($params)
     {
+        foreach ($params as $key => $val)
+        {
+            [$name, $spec, $card_type] = explode('-', $key);
 
+            $quality = $this->mNameMapQuality["{$name}-{$card_type}-{$spec}"] ?? 0;
+            if($quality <=0) continue;
 
-    }
-
-    public function update_ratios($ratios)
-    {
-        foreach ($ratios as $key => $ratio)
-        {
-            if(array_key_exists($key,$this->mSpeedtable)) {
-                $item = $this->mSpeedtable[$key];
-                $item->set_ratio($ratio);
-            }
-        }
-    }
+            $prefix = $this->prefix($name,$spec,$card_type,$quality);
+            $ctl = $this->mSpeedtable[$prefix] ?? null;
+            if(is_null($ctl)) continue;
 
-    public function update_speeds($speeds)
-    {
-        foreach ($speeds as $key => $speed)
-        {
-            if(array_key_exists($key,$this->mSpeedtable)) {
-                $item = $this->mSpeedtable[$key];
-                $item->set_speed($speed);
-            }
+            $ctl->update_params($val);
         }
     }
 
+    //
     public function match($names, int $spec, int $card_type, int $quality, $max_inprice)
     {
         $trace = new scope_trace(__METHOD__);
@@ -140,16 +130,12 @@ class chctlex
                     $item = $pThis->mSpeedtable[$key];
 
                     $inPrice = $item->price();
-//                    Log::record("max_price = {$max_inprice},in_price={$inPrice}",Log::DEBUG);
                     if ($max_inprice !== false && $inPrice > $max_inprice) {
                         continue;
                     } else {
                         $ctls[] = $item;
                     }
                 }
-                else {
-//                    Log::record("auto_match speed table key={$key} is empty.",Log::DEBUG);
-                }
             }
             return $ctls;
         };
@@ -162,10 +148,6 @@ class chctlex
             {
                 if($item->opened()) {
                     $usable_items[] = $item;
-                    $item->calc_speed(); //此处必须先计算速率,因为usort函数里面不能使用协程。
-                } else {
-//                    $key = $item->prefix();
-//                    Log::record("key={$key} has not opened",Log::DEBUG);
                 }
             }
 
@@ -181,16 +163,14 @@ class chctlex
             $lproity = $l->priority();
             $rproity = $r->priority();
 
-            //usort 函数内部,不可使用协程等待之类的代码.
             $lover = $l->speed_overload() ? 1 : 0;
             $rover = $r->speed_overload() ? 1 : 0;
 
             if($lover == $rover)
             {
-                if($lover) {
+                if ($lover) {
                     return $lproity > $rproity ? -1 : 1; //如果都过载保优先级高的
-                }
-                else {
+                } else {
                     return $lproity < $rproity ? -1 : 1;
                 }
             }
@@ -234,253 +214,49 @@ class chctlex
         return "{$name}-{$spec}-{$card_type}-{$quality}";
     }
 
-    const feed_minorder = 1;
-    const sleep_ratio   = 0.005;
-
-    const max_sleep_time = 120;
-    const sleep_count = 5;
-
-    const wakeup_commit_count = 10;
-    const sleep_commit_count  = 15;
-    const sleep_notify_count  = 15;
-
-    const profit_count = 90;
-    const avg_order_time = 120;
-
-    private function knockout($ctls,$amount)
-    {
-        $waker = function ($items,$max_sleep_time)
-        {
-            $workers = [];
-            $wakeups = [];
-            $sleeps = [];
-
-            foreach ($items as $item)
-            {
-                [$fSleep,$time] = $item->sleeping();
-                if($fSleep)
-                {
-                    if(time() > $time + $max_sleep_time) {
-                        $item->wakeup();
-                        $wakeups[] = $item;
-                    }
-                    else {
-                        $sleeps[] = $item;
-                    }
-                }
-                else {
-                    $workers[] = $item;
-                }
-            }
-            return [$sleeps,$wakeups,$workers];
-        };
-
-        $sleeper = function($sleeps,$wakeups,$workers)
-        {
-            foreach ($workers as $item)
-            {
-                [$notify_count, $ratio] = $item->notify_ratio();
-                [$commit_count, $commit_succ] = $item->commit_statics();
-
-                if ($commit_succ >= self::sleep_commit_count && $notify_count >= self::sleep_notify_count && $ratio < self::sleep_ratio) {
-                    $item->sleep();
-                    $sleeps[] = $item;
-                } else {
-                    $wakeups[] = $item;
-                }
-            }
-
-            return [$sleeps,$wakeups];
-        };
-
-
-        $desc_profit = function ($l, $r) use($amount)
-        {
-            [$lCount,$lRatio] = $l->notify_ratio();
-            [$rCount,$rRatio] = $r->notify_ratio();
-
-            $lProfit = $amount - $l->price();
-            $rRrofit = $amount - $r->price();
-
-            $lProfitRatio = $lProfit * $lRatio;
-            $rRrofitRatio = $rRrofit * $rRatio;
-
-            if($lProfitRatio > $rRrofitRatio) return -1;
-            elseif($lProfitRatio < $rRrofitRatio) return 1;
-            else return 0;
-        };
-
-        [$sleeps,$wakeups,$workers] = $waker($ctls,self::max_sleep_time);
-        usort($workers, $desc_profit);
-
-        return $sleeper($sleeps,$wakeups,$workers);
-    }
-
-    private function feed_as_lazy_speed($ctls)
-    {
-        //当前提交量计算喂订单
-        $asc_speed = function ($l, $r) {
-            $lspeed = $l->lazy_speed();
-            $rspeed = $r->lazy_speed();
-            return $lspeed < $rspeed ? -1 : 1;
-        };
-        usort($ctls, $asc_speed);
-
-        $feeds = [];
-        $profits = [];
-        foreach ($ctls as $item)
-        {
-            $name = $item->name();
-            [$count,$ratio] = $item->notify_ratio();
-            $lazy_spped = $item->lazy_speed();
-
-//            Log::record("auto_match channel {$name} count = {$count} ratio={$ratio} speed={$lazy_spped}",Log::DEBUG);
-            if($lazy_spped < self::feed_minorder) {
-                $feeds[] = $item;
-            } else {
-                $profits[] = $item;
-            }
-        }
-
-        return [$feeds,$profits];
-    }
-
-    public function feed_as_commit($ctls)
-    {
-        //当前提交量计算喂订单
-        $ascer = function ($l, $r) {
-            [$lCount,$lSucc] = $l->commit_statics();
-            [$rCount,$rSucc] = $r->commit_statics();
-            return $lSucc < $rSucc ? -1 : 1;
-        };
-        usort($ctls, $ascer);
-
-        $feeds = [];
-        $profits = [];
-        foreach ($ctls as $item)
-        {
-            $name = $item->name();
-            [$comit_count,$commit_succ]  = $item->commit_statics();
-            [$notify_count,$notify_succ] = $item->notify_statics();
-            $speed = $item->lazy_speed();
-
-            if($comit_count < self::wakeup_commit_count && $speed < self::feed_minorder) {
-                $feeds[] = $item;
-                $state = 'feed';
-            } else {
-                $profits[] = $item;
-                $state = 'profit';
-            }
-
-//            Log::record("auto_match channel {$name} state={$state} comit_succ={$commit_succ} count={$comit_count} notify_count={$notify_count} notify_succ={$notify_succ} speed={$speed}", Log::DEBUG);
-        }
-
-        return [$feeds,$profits];
-    }
-
     public function auto_match($names, int $spec, int $card_type, int $quality, $out_price, $max_inprice, $left_time): array
     {
-        $formater = function ($val) {
-            return number_format($val,10,'.','');
-        };
-
-        $desctor = function ($item) use($out_price,$formater,$card_type,$spec) {
-            $name = $item->name();
-
-            [$notify_count,$ratio] = $item->notify_ratio();
-            [$commit_count,$commit_succ] = $item->commit_statics();
-
-            $prifit = $out_price - $item->price();
-            $profit_ratio = $formater($prifit * $ratio);
-
-            [$fSleep,$time] = $item->sleeping();
-            if($fSleep) {
-                $state = "sleeping";
-                $time = $time + 120 - time();
-            } else {
-                $state = "waking";
-            }
-
-            return "{$card_type}-{$spec} {$name} {$state} time={$time} commit_count={$commit_count} notify_count={$notify_count} ratio={$ratio} profit_ratio={$profit_ratio}";
-        };
-
-        $left_times = intval($left_time / self::avg_order_time);
-        $left_times = $left_times <= 0 ? 1 : $left_times;
-        Log::record("left_times = {$left_times}",Log::DEBUG);
-
-        $desc_profit = function ($l, $r) use($out_price,$formater,$left_times)
+        $desc_profit = function ($l, $r) use($out_price)
         {
-            [$lCount,$lRatio] = $l->notify_ratio();
-            [$rCount,$rRatio] = $r->notify_ratio();
-
             $lProfit = $out_price - $l->price();
             $rRrofit = $out_price - $r->price();
 
-            $lProfitRatio = $lProfit * $lRatio;
-            $rRrofitRatio = $rRrofit * $rRatio;
-
-            $lProfit = $formater($lProfit);
-            $rRrofit = $formater($rRrofit);
-            $lProfitRatio = $formater($lProfitRatio);
-            $rRrofitRatio = $formater($rRrofitRatio);
-            $lRatio  = $formater($lRatio);
-            $rRatio  = $formater($rRatio);
-
-            $lRatios = intval($lRatio * $left_times + 0.05);
-            $rRatios = intval($rRatio * $left_times + 0.05);
-            $lRatios = $lRatios > 1 ? 1 : $lRatios;
-            $rRatios = $rRatios > 1 ? 1 : $rRatios;
-
-            if($lRatios == $rRatios && $lRatios == 1) { //次数大概率成功,按利润优先
-                if($lProfit > $rRrofit) return -1;
-                elseif($lProfit < $rRrofit) return 1;
-                else return 0;
-            }
-            elseif($lProfitRatio > $rRrofitRatio) return -1;
-            elseif($lProfitRatio < $rRrofitRatio) return 1;
-            elseif($lProfitRatio == 0) //利润获得概率为0,说明成功率或者利润可能性为0
+            $lVal = $l->compile_val($lProfit);
+            $rVal = $r->compile_val($lProfit);
+
+            if ($lVal == $rVal)
             {
-                if($lCount > $rCount) //此时优先喂单
+                if($lVal == 0.0)
                 {
-                    if($rCount >= self::profit_count) //单量都大于阈值,优先利润
-                    {
-                        if($lProfit > $rRrofit) return -1;
-                        elseif($lProfit < $rRrofit) return 1;
-                        else return 0;
-                    }
-                    else {
+                    $lSubmits = $l->submits();
+                    $rSubmits = $r->submits();
+
+                    if($lSubmits > $rSubmits) {
                         return 1;
                     }
-                }
-                elseif($lCount < $rCount)
-                {
-                    if($lCount >= self::profit_count) //单量都大于阈值,优先利润
-                    {
-                        if($lProfit > $rRrofit) return -1;
-                        elseif($lProfit < $rRrofit) return 1;
-                        else return 0;
-                    }
-                    else {
+                    elseif ($lProfit < $rRrofit) {
                         return -1;
                     }
-                }
-                else
-                {
-                    $count = $lCount;
-                    if($count >= self::profit_count) //单量都大于阈值,优先利润
-                    {
-                        if($lProfit > $rRrofit) return -1;
-                        elseif($lProfit < $rRrofit) return 1;
-                        else return 0;
-                    }
                     else {
                         return 0;
                     }
                 }
+                elseif ($lProfit > $rRrofit) {
+                    return -1;
+                }
+                elseif ($lProfit < $rRrofit) {
+                    return 1;
+                }
+                else {
+                    return 0;
+                }
+            }
+            elseif ($lVal > $rVal) {
+                return -1;
+            }
+            else {
+                return 1;
             }
-            elseif ($lRatio > $rRatio) return -1; //以下是利润概率相等,优先成功率保障
-            elseif ($lRatio < $rRatio) return 1;
-            else return 0;
         };
 
 
@@ -494,8 +270,6 @@ class chctlex
                 if(array_key_exists($key,$pThis->mSpeedtable))
                 {
                     $item = $pThis->mSpeedtable[$key];
-                    $item->calc_speed();
-
                     $inPrice = $item->price();
                     if ($max_inprice !== false && $inPrice > $max_inprice) {
                         continue;
@@ -510,78 +284,92 @@ class chctlex
             return $ctls;
         };
 
-        $logger = function ($items,$label) use ($desctor)
+        $ctl_splitor = function ($ctls)
         {
-            foreach ($items as $item) {
-                $msg = $desctor($item);
-                Log::record("auto_match {$label} = {$msg}",Log::DEBUG);
+            $feeds = [];
+            $workers = [];
+            $overs = [];
+
+            foreach ($ctls as $item)
+            {
+                if($item->need_feed()) {
+                    $feeds[] = $item;
+                }
+                elseif($item->speed_overload()) {
+                    $overs[] = $item;
+                }
+                else {
+                    $workers[] = $item;
+                }
             }
-        };
 
-        $names = array_unique($names);
-        Log::record("auto_match outprice= {$out_price} names=" . implode(',', $names), Log::DEBUG);
+            return [$feeds,$workers,$overs];
+        };
 
-        $can_feed = true;
-        $ctls = $price_filter($names,$spec,$card_type,$quality);
-        [$sleeps,$wakeups] = $this->knockout($ctls,$out_price);
+        $assign_feeds = function ($feeds)
+        {
+            if(empty($feeds)) {
+                return [[],[]];
+            }
 
-        $logger($sleeps,'sleeps');
-        $logger($wakeups,'wakeups');
+            $count = count($feeds);
+            $pos = mt_rand(0, $count * 60);
 
-        if(empty($wakeups)) {
-            $ctls = $sleeps;
-            $sleeps = [];
-        } else {
-            $ctls = $wakeups;
-        }
+            $cur_feeds = [];
+            $next_feeds = [];
 
-        //找出需要喂单
-        [$feeds,$profits] = $this->feed_as_commit($ctls);
-        usort($feeds, $desc_profit);
+            $i = 0;
+            foreach ($feeds as $item)
+            {
+                if($i == $pos) {
+                    $cur_feeds[] = $item;
+                } else {
+                    $next_feeds[] = $item;
+                }
+            }
 
-        $profits = array_merge($profits, $sleeps);
-        usort($profits, $desc_profit);
+            return [$cur_feeds,$next_feeds];
+        };
 
-        $normals = [];
-        $overloads = [];
-        foreach ($profits as $item)
+        $time_map = function ($ctls, $left_time)
         {
-            if($item->speed_overload()) {
-                $overloads[] = $item;
-            }
-            else {
-                $normals[] = $item;
+            $header = [];
+            $ender = [];
+            foreach ($ctls as $item)
+            {
+                if($item->notify_time() > $left_time) {
+                    $header[] = $item;
+                } else {
+                    $ender[] = $item;
+                }
             }
-        }
+
+            return array_merge($header,$ender);
+        };
+
+        $names = array_unique($names);
+        Log::record("auto_match outprice= {$out_price} names=" . implode(',', $names), Log::DEBUG);
+        $ctls = $price_filter($names,$spec,$card_type,$quality);
+        [$feeds,$workers,$overloads] = $ctl_splitor($ctls);
+
+        [$cur_feeds,$next_feeds] = $assign_feeds($feeds);
+        usort($workers, $desc_profit);
 
         if(!empty($overloads)) {
             $assigner = new overload_assigner();
             $assigner->add($overloads);
             $overloads = $assigner->assign();
         }
-        $profits = array_merge($normals, $overloads);
 
-        $feed_names = [];
-        foreach ($feeds as $item) {
-            $feed_names[] = $item->name();
-        }
+        $ctls = array_merge($cur_feeds, $workers, $overloads, $next_feeds);
+        $ctls = $time_map($ctls,$left_time);
 
-        $profit_names = [];
-        foreach ($profits as $item) {
-            $profit_names[] = $item->name();
+        $names = [];
+        foreach ($ctls as $item) {
+            $names[] = $item->name();
         }
 
-        if ($can_feed) {
-            $result = array_merge($feed_names, $profit_names);
-        } else {
-            $result = array_merge($profit_names,$feed_names);
-        }
-
-        $scan_feed = $can_feed ? 'true' : 'false';
-        $logger($feeds,'feeds');
-        $logger($profits,'profits');
-
-        Log::record("auto_match {$card_type}-{$spec} can_feed = {$scan_feed} result =" . implode(',',$result),Log::DEBUG);
-        return $result;
+        Log::record("auto_match result names=" . implode(',', $names), Log::DEBUG);
+        return $names;
     }
 }

+ 59 - 41
helper/refill/policy/ctl_itemex.php

@@ -2,12 +2,9 @@
 
 namespace refill;
 
-use Log;
-
-class ctl_item
+class ctl_itemex
 {
-    const speed_secs = 60;
-    const USE_BIGDATA = true;
+    const feed_threshold = 10;
 
     private $mName;
     private $mCardType;
@@ -22,7 +19,12 @@ class ctl_item
     private $mOpened;
     private $mPrice;
 
-    private $mLazySpeed;
+    private $mSpeed;
+    private $mRatio;
+    private $mRatioCommit;
+    private $mNotifyTime;
+    private $mMonitorCommit;
+
 
     public function __construct($chname, $card_type, $amount, $max_speed, $priority, $storge, $opened, $quality)
     {
@@ -37,34 +39,13 @@ class ctl_item
         $this->mPriority = $priority;
         $this->mStorge = $storge;
         $this->mOpened = $opened;
-        $this->mRecords = [];
         $this->mPrice = 0.0;
 
-        $this->mCommitSucc = 0;
-        $this->mCommitFail = 0;
-        $this->mNotifySucc = 0;
-        $this->mNotifyFail = 0;
-        $this->mLazySpeed = 0;
-    }
-
-    public function set_speed($speed)
-    {
-        $this->mLazySpeed = $speed;
-    }
-
-    public function cur_speed(): int
-    {
-        return $this->mLazySpeed;
-    }
-
-    public function speed_overload(): bool
-    {
-        return $this->lazy_speed() >= $this->mMaxSpeed;
-    }
-
-    public function lazy_speed()
-    {
-        return $this->mLazySpeed;
+        $this->mSpeed = 0;
+        $this->mRatio =0.0;
+        $this->mRatioCommit = 0;
+        $this->mNotifyTime = 0;
+        $this->mMonitorCommit = 0;
     }
 
     public function name()
@@ -85,10 +66,6 @@ class ctl_item
     {
         return $this->mOpened;
     }
-    public function max_speed()
-    {
-        return $this->mMaxSpeed;
-    }
     public function quality()
     {
         return $this->mQuality;
@@ -112,12 +89,53 @@ class ctl_item
     public function prefix() {
         return $this->mPrefix;
     }
+    public function update_params($parms)
+    {
+        [$this->mSpeed, $this->mRatio, $this->mRatioCommit, $this->mNotifyTime,$this->mMonitorCommit] = $parms;
+        if($this->mNotifyTime == 0) {
+            $this->mNotifyTime = 1;
+        }
+    }
+    public function max_speed()
+    {
+        return $this->mMaxSpeed;
+    }
+    public function speed_overload(): bool
+    {
+        if ($this->mMaxSpeed < 0) {
+            return false;
+        } elseif ($this->mMaxSpeed == 0) {
+            return true;
+        } else {
+            return $this->mSpeed >= $this->mMaxSpeed;
+        }
+    }
+
+    public function cur_speed()
+    {
+        return $this->mSpeed;
+    }
+    public function notify_ratio() {
+        return $this->mRatio;
+    }
+    public function submits() {
+        return $this->mRatioCommit;
+    }
+    public function notify_time() {
+        return $this->mNotifyTime;
+    }
+    public function need_feed()
+    {
+        if(self::feed_threshold >= $this->mMaxSpeed) {
+            return $this->mMonitorCommit == 0;
+        } else {
+            return $this->mMonitorCommit < self::feed_threshold;
+        }
+    }
 
-    public function set_ratio($ratio)
+    public function compile_val($profit_ratio)
     {
-        $this->mCommitSucc = $ratio[0];
-        $this->mCommitFail = $ratio[1];
-        $this->mNotifySucc = $ratio[2];
-        $this->mNotifyFail = $ratio[3];
+        $val = $this->mRatio * $profit_ratio / $this->mNotifyTime;
+        return round($val,5);
     }
 }

+ 10 - 9
plot/refill/ChSpeedRatioCalc.py

@@ -14,7 +14,7 @@ class ChSpeedRatioCalc(ChannelCalc):
         logger.debug('_calc_handler')
 
         reader = self._reader()
-        end_time = int(time.time())
+        end_time = int(time.time() - 5 * 86400)
         period = 1800
         days, start_time, end_time = self.calc_time(reader, end_time - period, end_time)
 
@@ -22,20 +22,21 @@ class ChSpeedRatioCalc(ChannelCalc):
         tuple_pathes = reader.many_tuple_path(days, card_types=set([4, 5, 6]))
         gen = detail_pathes(reader, tuple_pathes, days)
 
-        speeds = dict()
         start_pos = start_time - day_stamp
         end_pos = end_time - day_stamp
+
+        result = dict()
         for _name, _card_type, _spec, _data in gen:
             speed = calc_chspeed(_data, pos_map, end_pos - 60, end_pos)
-            ratio, commit_count, bak_time = calc_chratio(_data, pos_map, end_pos - period, end_pos)
-            tenmin_commit = calc_commit(_data, pos_map, end_pos - 600, end_pos)
+            ratio, ratio_commit, notify_time = calc_chratio(_data, pos_map, end_pos - period, end_pos)
+            monitor_commit = calc_commit(_data, pos_map, end_pos - 300, end_pos)
 
             key = f'{_name}-{_spec}-{_card_type}'
-            speeds[key] = [speed, ratio, commit_count, bak_time,tenmin_commit]
-            logger.debug("%s-%d-%d speed=%d ratio=%.5f commit_count=%d bak_time=%.5f tenmin_commit=%d", _name, _card_type, _spec, speed, ratio,
-                         commit_count, bak_time, tenmin_commit)
+            result[key] = [speed, ratio, ratio_commit, notify_time, monitor_commit]
+            logger.debug("%s-%d-%d speed=%d ratio=%.5f commit_count=%d notify_time=%.5f monitor_commit=%d", _name, _card_type, _spec, speed, ratio,
+                         ratio_commit, notify_time, monitor_commit)
 
-        if len(speeds) != 0:
-            rclient.set(f"nc_refill_channel_control_model", json.dumps(speeds))
+        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

+ 4 - 19
rdispatcher/codispatcher.php

@@ -81,18 +81,6 @@ function subscribe_message(&$quit, &$redis, $channels)
                         refill\RefillFactory::instance()->load();
                         refill\transfer::instance()->load();
                     }
-                    elseif($type == 'ratio') {
-                        $ins = Cache::getInstance('cacheredis');
-                        $val = $ins->get_org('channel_ratios');
-
-                        if(empty($val)) continue;
-                        $val = json_decode($val,true);
-                        if(empty($val)) continue;
-                        $ratios = $val['ratios'];
-                        if(empty($ratios)) continue;
-
-                        refill\RefillFactory::instance()->UpdateRatio($ratios);
-                    }
                     elseif($type == 'mch_profit_ratio') {
                         $ins = Cache::getInstance('cacheredis');
                         $content = $ins->get_org('refill_merchant_profit_ratio');
@@ -106,15 +94,12 @@ function subscribe_message(&$quit, &$redis, $channels)
 
                         refill\RefillFactory::instance()->UpdateMchRatios($gross,$detail);
                     }
-                    elseif($type == 'channels_speed') {
+                    elseif($type == 'channel_control') {
                         $ins = Cache::getInstance('cacheredis');
-                        $content = $ins->get_org('channels_speed');
-
-                        if(empty($content)) continue;
-                        $speeds = json_decode($content,true);
-                        if(empty($speeds)) continue;
+                        $content = $ins->get_org('refill_channel_control_model');
 
-                        refill\RefillFactory::instance()->UpdateSpeeds($speeds);
+                        $data = json_decode($content,true);
+                        refill\RefillFactory::instance()->UpdateChctl($data);
                     }
                     else {
                         //Log::record("subscribe_message dont not handle mgs:{$sub_type}-{$channel}-{$type}",Log::DEBUG);

+ 29 - 1
test/TestBigData.php

@@ -112,9 +112,37 @@ class TestBigData extends TestCase
         $content = $ins->get_org('refill_channel_control_model');
 
         $data = json_decode($content,true);
+        refill\RefillFactory::instance()->UpdateChctl($data);
+    }
 
+    public function testMtrand()
+    {
+        $feeds = [1, 2, 3, 4, 5];
+        $count = count($feeds);
 
-        refill\RefillFactory::instance()->UpdateMchRatios($gross,$detail);
+        $result = [];
+        for ($i = 0; $i < $count * 2; $i++) {
+            $val = mt_rand(0,$count);
+            $result[] = $val;
+        }
+
+        return $result;
+    }
+
+    public function testEqual()
+    {
+        $l = round(0.000000000009,10);
+        $r = round(0.000000000008,10);
+
+        if($l == $r)
+        {
+            if($l == 0.0) {
+                $i = 2;
+            }
+            else {
+                $i = 1;
+            }
+        }
     }