[update] Judge

This commit is contained in:
lkeme 2021-10-16 15:44:56 +08:00
parent 7467b9f2bf
commit eb06f55fa0

View File

@ -46,23 +46,20 @@ class Judge
if (!self::jury()) { if (!self::jury()) {
self::setLock(mt_rand(60, 120) * 60); self::setLock(mt_rand(60, 120) * 60);
} }
// // 任务
if (empty(self::$wait_case)) { if (empty(self::$wait_case)) {
// 获取任务 // 获取
$case_id = self::caseObtain(); $case_id = self::caseObtain();
self::caseCheck($case_id); self::caseCheck($case_id);
// 如果没有设置时间 就设置个默认时间 可能在一秒钟内处理完 所以 <=
if (self::getLock() <= time()) {
self::setLock(1 * 60 + 5);
}
} else { } else {
// 执行
$case = array_pop(self::$wait_case); $case = array_pop(self::$wait_case);
self::vote($case['id'], $case['vote']); self::vote($case['id'], $case['vote']);
}
// 如果没有设置时间 就设置个默认时间 可能在一秒钟内处理完 所以 <= // 如果没有设置时间 就设置个默认时间 可能在一秒钟内处理完 所以 <=
if (self::getLock() <= time()) { if (self::getLock() <= time()) {
self::setLock(mt_rand(15, 30) * 60); self::setLock(mt_rand(15, 30) * 60);
} }
}
} }
@ -74,13 +71,14 @@ class Judge
*/ */
private static function caseCheck($case_id) private static function caseCheck($case_id)
{ {
if ($case_id == "") { if ($case_id == '') {
return true; return true;
} }
$case_info = self::caseInfo($case_id); $case_info = self::caseInfo($case_id);
$case_opinion = self::caseOpinion($case_id); $case_opinion = self::caseOpinion($case_id);
if (!$case_opinion && empty($case_opinion)) { if (!$case_opinion && empty($case_opinion)) {
$vote_info = $case_info[array_rand($case_info)]; // $vote_info = $case_info[array_rand($case_info)];
$vote_info = $case_info[self::probability()];
} else { } else {
$vote_info = $case_opinion[array_rand($case_opinion)]; $vote_info = $case_opinion[array_rand($case_opinion)];
@ -89,6 +87,7 @@ class Judge
$vote_text = $vote_info['vote_text']; $vote_text = $vote_info['vote_text'];
Log::info("案件 $case_id 的预测投票结果:$vote($vote_text)"); Log::info("案件 $case_id 的预测投票结果:$vote($vote_text)");
array_push(self::$wait_case, ["id" => $case_id, 'vote' => $vote]); array_push(self::$wait_case, ["id" => $case_id, 'vote' => $vote]);
self::setLock(1 * 60 + 5);
} }
/** /**
@ -112,7 +111,8 @@ class Judge
]; ];
$raw = Curl::post('pc', $url, $payload, $headers); $raw = Curl::post('pc', $url, $payload, $headers);
$de_raw = json_decode($raw, true); $de_raw = json_decode($raw, true);
//{"code":0,"message":"0","ttl":1} // {"code":0,"message":"0","ttl":1}
// {"code":25018,"message":"不能进行此操作","ttl":1}
if (isset($de_raw['code']) && $de_raw['code']) { if (isset($de_raw['code']) && $de_raw['code']) {
Log::warning("案件 $case_id 投票失败 $raw"); Log::warning("案件 $case_id 投票失败 $raw");
} else { } else {
@ -303,4 +303,25 @@ class Judge
return implode("", $temp); return implode("", $temp);
} }
/**
* @use 概率
* @return int
*/
private static function probability(): int
{
$result = 0;
$prize_arr = [0 => 25, 1 => 40, 2 => 25, 3 => 10];
// 概率数组的总概率精度
$sum = array_sum($prize_arr);
// 概率数组循环
foreach ($prize_arr as $key => $value) {
if (mt_rand(1, $sum) <= $value) {
$result = $key;
break;
}
$sum -= $value;
}
return $result;
}
} }