diff --git a/webapp/controller/ToolsController.class.php b/webapp/controller/ToolsController.class.php index b61b07b7..fda4184e 100644 --- a/webapp/controller/ToolsController.class.php +++ b/webapp/controller/ToolsController.class.php @@ -4,6 +4,7 @@ require_once('phpcommon/bignumber.php'); require_once('phpcommon/sqlhelper.php'); require_once('services/BlockChainService.php'); +use models\Battle; use phpcommon\SqlHelper; use services\BlockChainService; @@ -12,10 +13,10 @@ class ToolsController extends BaseController { public function _handlePre() { parent::_handlePre(); - if (SERVER_ENV == _ONLINE) { - die("can't create ToolsController"); - return; - } +// if (SERVER_ENV == _ONLINE) { +// die("can't create ToolsController"); +// return; +// } } public function test() @@ -256,4 +257,184 @@ class ToolsController extends BaseController { fclose($fp); } + + public function geneTestBattleData(){ +// $data = json_decode($this->testBattleData,JSON_OBJECT_AS_ARRAY); + $str = '{ + "abandon_battle": 0, + "account_id": "6513_2006_qWceQesI1syq80htV04BokwUS4FtN7C4", + "alive_time": 156050, + "assist": 8, + "damage_in": 236, + "damage_out": 15004, + "dead": 0, + "destory_car_times": 0, + "diving_times": 0, + "full_level_idx": 0, + "game_duration": 160, + "game_time": 1710920097, + "head": "", + "head_frame": 0, + "hero_id": 30800, + "hero_uniid": "50366", + "heros": "", + "is_mvp": 0, + "is_run_away": 0, + "kills": 4, + "max_hero_skill_lv": 0, + "move_distance": 6156.5, + "name": "alkl", + "open_airdrop_times": 0, + "pvp_assist": 8, + "pvp_damage": 15004, + "pvp_kill": 4, + "pvp_personal_rank": 1, + "pvp_recover": 151, + "pvp_rescue": 0, + "pvp_survia_time": 156050, + "ranked": 1, + "recover_hp": 151, + "rescue_teammate_times": 0, + "ride_car_kills": 0, + "ride_car_move_distance": 0, + "sex": 0, + "skin_id": 40801, + "use_camouflage_times": 0, + "use_medicine_times": 0, + "use_skill_times": 7, + "weapon_uuid1": "0", + "weapon_uuid2": "0", + "weapons_slot": "20711:77|30204:2|", + "weapons_type": "20711:4:13906:0|", + "battle_uuid": "1011223897643738990592", + "map_id": 2004, + "moba_enemy_team_kills": 2, + "moba_my_team_kills": 12, + "pvp_alive_human_num": -11, + "pvp_match_mode": 0, + "pvp_settelement_color": 1, + "pvp_settelement_type": 1, + "pvp_team_kills": 12, + "pvp_team_rank": 1, + "pvp_total_human_num": 8, + "pvp_total_team_num": 2, + "room_mode": 2, + "room_uuid": "1011223897612059412480", + "team_id": 1 + }'; + $data = json_decode($str,JSON_OBJECT_AS_ARRAY); + for ($i = 0 ;$i<100;$i++){ + $hisBattleData = array(); + if (!isset($hisBattleData['data'])) { + $hisBattleData['data'] = array( + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + } + $account = "6666_2006_testAccount".$i.rand(11111111,99999999); + $data['pvp_team_rank'] = rand(1,10); + $data['kills'] = rand(0,10); + $data['damage_out'] = rand(100,1000); + $data['damage_in'] = rand(100,1000); + $data['recover_hp'] = rand(0,200); + $data['alive_time'] = rand(100000,400000); + $data['pvp_assist'] = rand(5,20); + $this->apply($hisBattleData['data'],$data); + + if (!isset($hisBattleData['moba_data'])) { + $hisBattleData['moba_data'] = array( + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + } + $data['pvp_team_rank'] = rand(1,2); + $data['kills'] = rand(0,15); + $data['damage_out'] = rand(5000,50000); + $data['damage_in'] = rand(100,1000); + $data['recover_hp'] = rand(0,200); + $data['alive_time'] = rand(100000,400000); + $data['pvp_assist'] = rand(0,10); + $data['hero_lv'] = rand(1,10); + $this->apply($hisBattleData['moba_data'],$data); + + SqlHelper::upsert + (myself()->_getMysql("6513_2006_qWceQesI1syq80htV04BokwUS4FtN7C4"), + 't_battle', + array( + 'account_id' => $account, + ), + array( + 'battle_data' => json_encode($hisBattleData), + 'modifytime' => myself()->_getNowTime(), + ), + array( + 'account_id' => $account, + 'battle_data' => json_encode($hisBattleData), + 'kills_modifytime' => myself()->_getNowTime(), + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + } + private function apply(&$battleData,$battleInfo) + { + //战斗次数 + $this->incValue($battleData, 'total_battle_times', 1); + //排名 + $ranked = getXVal($battleInfo,'pvp_team_rank', 0); + if ($ranked == 1) { + //吃鸡次数 + $this->incValue($battleData, 'total_win_times', 1); + } + //击杀总次数 + $kills = getXVal($battleInfo,'kills', 0); + $this->incValue($battleData, 'total_kills_times', $kills); + //输出 + $damageOut = getXVal($battleInfo,'damage_out', 0); + $this->incValue($battleData, 'total_damage_out', $damageOut); + //承伤 + $damageIn = getXVal($battleInfo,'damage_in', 0); + $this->incValue($battleData, 'total_damage_in', $damageIn); + //回复 + $recoverHp = getXVal($battleInfo,'recover_hp', 0); + $this->incValue($battleData, 'total_recover_hp', $recoverHp); + //存活时间 + $aliveTime = getXVal($battleInfo,'alive_time', 0); + $this->incValue($battleData, 'total_alive_time', $aliveTime); + //助攻次数 + $assistTime = getXVal($battleInfo,'pvp_assist', 0); + $this->incValue($battleData, 'total_assist_time', $assistTime); + //等级 + $level = getXVal($battleInfo,'hero_lv', 1); + $this->incValue($battleData, 'total_level', $level); + + //救援次数 + $this->incValue($battleData, 'rescue_teammate_times', getXVal($battleInfo,'rescue_teammate_times', 0)); + //潜水次数 + $this->incValue($battleData, 'diving_times', getXVal($battleInfo,'diving_times', 0)); + //开启空投次数 + $this->incValue($battleData, 'open_airdrop_times', getXVal($battleInfo,'open_airdrop_times', 0)); + //使用药品次数 + $this->incValue($battleData, 'use_medicine_times', getXVal($battleInfo,'use_medicine_times', 0)); + //击毁机甲次数 + $this->incValue($battleData, 'destory_car_times', getXVal($battleInfo,'destory_car_times', 0)); + //使用伪装次数 + $this->incValue($battleData, 'use_camouflage_times', getXVal($battleInfo,'use_camouflage_times', 0)); + //使用技能次数 + $this->incValue($battleData, 'use_skill_times', getXVal($battleInfo,'use_skill_times', 0)); + //驾驶机甲移动距离 + $this->incValue($battleData, 'ride_car_move_distance', getXVal($battleInfo,'ride_car_move_distance', 0)); + //驾驶机甲击杀数 + $this->incValue($battleData, 'ride_car_kills', getXVal($battleInfo,'ride_car_kills', 0)); + } + + private function incValue(&$battleData, $key, $val) + { + if ($val > 0) { + $battleData[$key] = getXVal($battleData, $key, 0) + $val; + } + } + + } diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index 8323c1a5..250dc9c5 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -654,7 +654,7 @@ class UserController extends BaseAuthedController { $mobaDataInfo = isset($battleData) ? getXVal($battleData, 'moba_data', array()) : array(); $gameTimesMoba = getXVal($mobaDataInfo, 'total_battle_times', 0); $winTimesMoba = getXVal($mobaDataInfo, 'total_win_times', 0); - $totalLevelMoba = getXVal($mobaDataInfo, 'total_level', 0); + $totalLevelMoba = getXVal($mobaDataInfo, 'total_level', 1); $levelPerMoba = $gameTimesMoba > 0 ? intval($totalLevelMoba / $gameTimesMoba) : 0; $totalKillsMoba = getXVal($mobaDataInfo, 'total_kills_times', 0); $killsPerMoba = $gameTimesMoba > 0 ? intval($totalKillsMoba / $gameTimesMoba) : 0; @@ -733,7 +733,7 @@ class UserController extends BaseAuthedController { "pvp_damage_avg" => round($totalDamagePerPvp / $number,2), "pvp_recover_avg" => round($totalRecoverHpPerPvp / $number,2), ); - $userChartData["pvp_state"] = $totalGameTimesPvp > Battle::VALID_BATTLE_COUNT ? 1 :0; + $userChartData["pvp_state"] = $totalGameTimesPvp >= Battle::VALID_BATTLE_COUNT ? 1 :0; if ($userChartData['pvp_server_data']['pvp_alive_avg'] == 0 || $userChartData['pvp_server_data']['pvp_kills_avg'] == 0 || $userChartData['pvp_server_data']['pvp_assist_avg'] == 0 || @@ -742,15 +742,13 @@ class UserController extends BaseAuthedController { $userChartData["pvp_state"] = 0; } $userChartData['moba_server_data'] = array( - "moba_level_avg" => round($totalLevelPerMoba / $number,2), "moba_kills_avg" => round($totalKillsPerMoba / $number,2), "moba_assist_avg" => round($totalAssistPerMoba / $number,2), "moba_damage_avg" => round($totalDamagePerMoba / $number,2), "moba_recover_avg" => round($totalRecoverHpPerMoba / $number,2), ); - $userChartData["moba_state"] = $totalGameTimesMoba > Battle::VALID_BATTLE_COUNT ? 1 :0; - if ( $userChartData['moba_server_data']['moba_level_avg'] == 0 || - $userChartData['moba_server_data']['moba_kills_avg'] == 0 || + $userChartData["moba_state"] = $totalGameTimesMoba >= Battle::VALID_BATTLE_COUNT ? 1 :0; + if ( $userChartData['moba_server_data']['moba_kills_avg'] == 0 || $userChartData['moba_server_data']['moba_assist_avg'] == 0 || $userChartData['moba_server_data']['moba_damage_avg'] == 0 || $userChartData['moba_server_data']['moba_recover_avg'] == 0 ){ @@ -762,20 +760,20 @@ class UserController extends BaseAuthedController { $r = (2*$param-1) / (1-$param); if ($gameTimes >= Battle::VALID_GAME_TIMES){ // t=x/u r=(2s-1)/(1-s) - $t1 = $userChartData['pvp_server_data']['pvp_kills_avg']>0 ? intval($killsPer / $userChartData['pvp_server_data']['pvp_kills_avg']) :0; + $t1 = $userChartData['pvp_server_data']['pvp_kills_avg']>0 ? ($killsPer / $userChartData['pvp_server_data']['pvp_kills_avg']) :0; $pvpData['star_kills'] = round((pow($r,$t1) - 1) / (pow($r,$t1)+$r-2),2); - $t2 = $userChartData['pvp_server_data']['pvp_alive_avg']>0 ? intval($alivePer / $userChartData['pvp_server_data']['pvp_alive_avg']) :0; + $t2 = $userChartData['pvp_server_data']['pvp_alive_avg']>0 ? ($alivePer / $userChartData['pvp_server_data']['pvp_alive_avg']) :0; $pvpData['star_alive'] = round((pow($r,$t2) - 1) / (pow($r,$t2)+$r-2),2); - $t3 = $userChartData['pvp_server_data']['pvp_assist_avg']>0 ? intval($assistPer / $userChartData['pvp_server_data']['pvp_assist_avg']) :0; + $t3 = $userChartData['pvp_server_data']['pvp_assist_avg']>0 ? ($assistPer / $userChartData['pvp_server_data']['pvp_assist_avg']) :0; $pvpData['star_assist'] = round((pow($r,$t3) - 1) / (pow($r,$t3)+$r-2),2); - $t4 = $userChartData['pvp_server_data']['pvp_damage_avg']>0 ? intval($damagePer / $userChartData['pvp_server_data']['pvp_damage_avg']) :0; + $t4 = $userChartData['pvp_server_data']['pvp_damage_avg']>0 ? ($damagePer / $userChartData['pvp_server_data']['pvp_damage_avg']) :0; $pvpData['star_damage'] = round((pow($r,$t4) - 1) / (pow($r,$t4)+$r-2),2); - $t5 = $userChartData['pvp_server_data']['pvp_recover_avg']>0 ? intval($recoverHpPer / $userChartData['pvp_server_data']['pvp_recover_avg']) :0; + $t5 = $userChartData['pvp_server_data']['pvp_recover_avg']>0 ? ($recoverHpPer / $userChartData['pvp_server_data']['pvp_recover_avg']) :0; $pvpData['star_recover'] = round((pow($r,$t5) - 1) / (pow($r,$t5)+$r-2),2); } if ($gameTimesMoba >= Battle::VALID_GAME_TIMES){ - $t6 = $userChartData['moba_server_data']['moba_kills_avg']>0 ? intval($killsPerMoba / $userChartData['moba_server_data']['moba_kills_avg']) :0; + $t6 = $userChartData['moba_server_data']['moba_kills_avg']>0 ? ($killsPerMoba / $userChartData['moba_server_data']['moba_kills_avg']) :0; $mobaData['star_kills'] = round((pow($r,$t6) - 1) / (pow($r,$t6)+$r-2),2); $t8 = $userChartData['moba_server_data']['moba_assist_avg']>0 ? intval($assistPerMoba / $userChartData['moba_server_data']['moba_assist_avg']) :0; $mobaData['star_assist'] = round((pow($r,$t8) - 1) / (pow($r,$t8)+$r-2),2); diff --git a/webapp/models/Battle.php b/webapp/models/Battle.php index 22fd242b..101bd620 100644 --- a/webapp/models/Battle.php +++ b/webapp/models/Battle.php @@ -8,7 +8,7 @@ use phpcommon\SqlHelper; class Battle extends BaseModel { const VALID_GAME_TIMES = 5; - const VALID_BATTLE_COUNT = 1000; + const VALID_BATTLE_COUNT = 100; public static function find($accountId){ $row = SqlHelper::ormSelectOne( @@ -76,6 +76,7 @@ class Battle extends BaseModel { public static function getBattleDataLimit(){ $limit = self::VALID_BATTLE_COUNT; return myself()->_getSelfMysql()->execQuery("SELECT idx,account_id,battle_data FROM t_battle ORDER BY idx DESC LIMIT {$limit}"); + } }