|
@@ -324,10 +324,11 @@ class chctl
|
|
|
foreach ($ctls as $item)
|
|
|
{
|
|
|
$name = $item->name();
|
|
|
- [$comit_count,$commit_succ] = $item->commit_statics();
|
|
|
+ [$comit_count,$commit_succ] = $item->commit_statics();
|
|
|
[$notify_count,$notify_succ] = $item->notify_statics();
|
|
|
+ $speed = $item->lazy_speed();
|
|
|
|
|
|
- if($commit_succ < self::wakeup_commit_count) {
|
|
|
+ if($commit_succ < self::wakeup_commit_count && $speed < self::feed_minorder) {
|
|
|
$feeds[] = $item;
|
|
|
$state = 'feed';
|
|
|
} else {
|
|
@@ -343,34 +344,29 @@ class chctl
|
|
|
|
|
|
public function auto_match($names, int $spec, int $card_type, int $quality, $out_price, $left_time) : array
|
|
|
{
|
|
|
- $names = array_unique($names);
|
|
|
- Log::record("auto_match names=" . implode(',', $names), Log::DEBUG);
|
|
|
+ $formater = function ($val) {
|
|
|
+ return number_format($val,10,'.','');
|
|
|
+ };
|
|
|
|
|
|
-// $can_feed = $left_time > self::timeout_level;
|
|
|
- $can_feed = true;
|
|
|
- $ctls = [];
|
|
|
- foreach ($names as $name)
|
|
|
- {
|
|
|
- $key = $this->prefix($name,$spec,$card_type,$quality);
|
|
|
- if(array_key_exists($key,$this->mSpeedtable)) {
|
|
|
- $item = $this->mSpeedtable[$key];
|
|
|
- $item->calc_speed();
|
|
|
- $ctls[] = $item;
|
|
|
+ $desctor = function ($item) use($out_price,$formater) {
|
|
|
+ $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";
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
-// [$sleeps,$workers] = $this->sleep_item($ctls);
|
|
|
- [$sleeps,$workers] = $this->knockout($ctls,$spec);
|
|
|
- if(empty($workers)) {
|
|
|
- $ctls = $sleeps;
|
|
|
- } else {
|
|
|
- $ctls = $workers;
|
|
|
- }
|
|
|
-// [$feeds,$profits] = $this->feed_as_lazy_speed($ctls);
|
|
|
- [$feeds,$profits] = $this->feed_as_commit($ctls);
|
|
|
|
|
|
- $formater = function ($val) {
|
|
|
- return number_format($val,10,'.','');
|
|
|
+ return "{$name} {$state} time={$time} commit_succ={$commit_succ} notify_count={$notify_count} profit_ratio={$profit_ratio}";
|
|
|
};
|
|
|
|
|
|
$desc_profit = function ($l, $r) use($out_price,$formater) {
|
|
@@ -437,29 +433,43 @@ class chctl
|
|
|
else return 0;
|
|
|
};
|
|
|
|
|
|
- usort($feeds, $desc_profit);
|
|
|
- usort($profits, $desc_profit);
|
|
|
|
|
|
- $desctor = function ($item) use($out_price,$formater) {
|
|
|
- $name = $item->name();
|
|
|
+ $pThis = $this;
|
|
|
+ $speed_locker = function ($names,$spec,$card_type,$quality) use($pThis)
|
|
|
+ {
|
|
|
+ $ctls = [];
|
|
|
+ foreach ($names as $name)
|
|
|
+ {
|
|
|
+ $key = $pThis->prefix($name,$spec,$card_type,$quality);
|
|
|
+ if(array_key_exists($key,$pThis->mSpeedtable)) {
|
|
|
+ $item = $pThis->mSpeedtable[$key];
|
|
|
+ $item->calc_speed();
|
|
|
+ $ctls[] = $item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $ctls;
|
|
|
+ };
|
|
|
|
|
|
- [$notify_count,$ratio] = $item->notify_ratio();
|
|
|
- [$commit_count,$commit_succ] = $item->commit_statics();
|
|
|
+ $names = array_unique($names);
|
|
|
+ Log::record("auto_match names=" . implode(',', $names), Log::DEBUG);
|
|
|
|
|
|
- $prifit = $out_price - $item->price();
|
|
|
- $profit_ratio = $formater($prifit * $ratio);
|
|
|
+// $can_feed = $left_time > self::timeout_level;
|
|
|
+ $can_feed = true;
|
|
|
+ $ctls = $speed_locker($names,$spec,$card_type,$quality);
|
|
|
+ [$sleeps,$workers] = $this->knockout($ctls,$spec);
|
|
|
+ Log::record("auto_match sleeps =" . implode(',',$sleeps),Log::DEBUG);
|
|
|
+ Log::record("auto_match workers =" . implode(',',$workers),Log::DEBUG);
|
|
|
|
|
|
- [$fSleep,$time] = $item->sleeping();
|
|
|
- if($fSleep) {
|
|
|
- $state = "sleeping";
|
|
|
- $time = $time + 120 - time();
|
|
|
- } else {
|
|
|
- $state = "waking";
|
|
|
- }
|
|
|
+ if(empty($workers)) {
|
|
|
+ $ctls = $sleeps;
|
|
|
+ } else {
|
|
|
+ $ctls = $workers;
|
|
|
+ }
|
|
|
|
|
|
+ [$feeds,$profits] = $this->feed_as_commit($ctls);
|
|
|
|
|
|
- return "{$name} {$state} time={$time} commit_succ={$commit_succ} notify_count={$notify_count} profit_ratio={$profit_ratio}";
|
|
|
- };
|
|
|
+ usort($feeds, $desc_profit);
|
|
|
+ usort($profits, $desc_profit);
|
|
|
|
|
|
$feed_names = [];
|
|
|
foreach ($feeds as $item) {
|