<?php /** * Created by PhpStorm. * User: lunweiwei * Date: 16/9/5 * Time: 下午6:51 */ /** * @param $str * @return int */ function atoi($str) { $arr = str_split($str); $sign = null; $result = 0; foreach ($arr as $item) { if (!isset($sign) && in_array($item, ['-', '+'])) { $sign = $item == '-'; } if (is_numeric($item)) { $result = $result * 10 + $item; } } return $sign ? -$result : $result; } $res = atoi('1278561'); var_dump($res);
$task_list[$i] = $task; $task_assigned_users[$i] = $task->assignees($task_id); $i++; } $Ntasks = $i; $user_usage = array(); $task_dates = array(); $actual_date = $start_date; $days_header = ""; // we will save days title here if (strtolower($max_levels) == 'max') { $max_levels = -1; } elseif ($max_levels == '') { $max_levels = -1; } else { $max_levels = atoi($max_levels); } if ($max_levels == 0) { $max_levels = 1; } if ($max_levels < 0) { $max_levels = -1; } if (count($task_list) == 0) { echo '<p>' . $AppUI->_('No data available') . '</p>'; } else { $sss = $ss; $sse = $se; if (!$use_period) { $sss = -1; $sse = -1;
function __access() { atoi($rand_name); }
function Contest_Save($id, $clear = false) { global $noarchive; $contest = WT_contest_by_id($id); $name = FormPOSTValue('name', 'ContestSettings'); if (trim($name) == '') { add_info('Название контеста не может быть пустым.'); return false; } $settings = $contest['settings']; $settings['rules'] = atoi(FormPOSTValue('rules', 'ContestSettings')); $settings['duration'] = atoi(FormPOSTValue('duration', 'ContestSettings')); $settings['freezetime'] = atoi(FormPOSTValue('freezetime', 'ContestSettings')); $settings['penalty'] = atoi(FormPOSTValue('penalty', 'ContestSettings')); $settings['trycount'] = atoi(FormPOSTValue('trycount', 'ContestSettings')); $settings['unfrozen'] = atoi(FormPOSTValue('unfrozen', 'ContestSettings')); $settings['viewdetail'] = atoi(FormPOSTValue('viewdetail', 'ContestSettings')); $settings['show_last_accepted'] = atoi(FormPOSTValue('show_last_accepted', 'ContestSettings')); $settings['ignore_ce'] = atoi(FormPOSTValue('ignore_ce', 'ContestSettings')); $settings['autostart'] = $_POST['contest_autostart']; if ($settings['autostart']) { $date = new CDCDate(); $date->Init(); $date->ReceiveValue('contest_autostart_date'); $settings['autostart.date'] = $date->GetValue(); $time = new CDCDate(); $time->Init(); $time->ReceiveValue('contest_autostart_time'); $settings['autostart.time'] = $time->GetValue(); } if (!$noarchive) { if ($_FILES['archive']['name'] != '') { file_unlink_encrypted($settings['archive']); $data = $_FILES['archive']; if (WT_contest_running($id) || WT_contest_finished($id)) { $blocked = 0; } else { $blocked = 1; } $settings['archive'] = file_store_encrypted($data, 1, $blocked); } } else { file_unlink_encrypted($settings['archive']); $settings['archive'] = ''; } $update = array('name' => db_html_string($name), 'settings' => db_string(serialize($settings))); db_update('tester_contests', $update, "`id`={$id}"); return true; }
function Contest_Save($id, $clear = false) { global $noarchive; if (!$this->GetAllowed('CONTEST.MANAGE')) { return; } $contest = WT_contest_by_id($id); $name = FormPOSTValue('name', 'ContestSettings'); if (trim($name) == '') { add_info('Название контеста не может быть пустым.'); return false; } $settings = $contest['settings']; $settings['duration'] = atoi(FormPOSTValue('duration', 'ContestSettings')); $settings['timelimit'] = atoi(FormPOSTValue('timelimit', 'ContestSettings')); $settings['trycount'] = atoi(FormPOSTValue('trycount', 'ContestSettings')); $settings['autostart'] = $_POST['contest_autostart']; if ($settings['autostart']) { $date = new CDCDate(); $date->Init(); $date->ReceiveValue('contest_autostart_date'); $settings['autostart.date'] = $date->GetValue(); $time = new CDCDate(); $time->Init(); $time->ReceiveValue('contest_autostart_time'); $settings['autostart.time'] = $time->GetValue(); } $update = array('name' => db_html_string($name), 'settings' => db_string(serialize($settings))); db_update('tester_contests', $update, "`id`={$id}"); return true; }
printf("\nMean Value Analysis algorithm for single class workload\n"); while (TRUE) { printf("\n(Hit RETURN to exit) "); printf("Enter no. of centers (K): "); gets($input); if ($input == "") { break; } else { $K = atoi($input); } for ($k = 1; $k <= $K; $k++) { printf("Enter demand at center %d (D[%d]): ", $k, $k); gets($input); $D[$k] = atof($input); } printf("Enter think time (Z):"); gets($input); $Z = atof($input); while (TRUE) { printf("\n(Hit RETURN to stop) "); printf("Enter no. of terminals (N): "); gets($input); if ($input == "") { break; } else { $N = atoi($input); mva(); } } } // main
function updateRow($region, $key, $base_url, $host, $username, $password, $database, $summoner_array) { // Connect to the database $mysqli = new mysqli($host, $username, $password); $mysqli->select_db($database); $na = $_POST['summonerName']; $qu = "SELECT createDate,gameId FROM games WHERE summonerName='{$na}' ORDER BY gameId ASC"; $result = $mysqli->query($qu); debug('in update row'); if ($result) { $num_old_games = $result->num_rows; debug("num_old_games: " . $num_old_games); // this is guaranteed the oldest because they are queried in ascending order of game date. // therefore, the FIRST row will be the oldest one. $oldest_row = $result->fetch_assoc(); $oldest_game = $oldest_row['createDate']; } else { debug("no result in finding the num old games and oldest game date"); } $result->free(); // Count how many games are grabbed/nommed/parsed. $gamesSuccessfullyParsed = 0; // reset fields before the initial iteration if (true) { /** Fields can be found at sql_fields.txt */ $primaryKey = 73577357; $accountId = 7357; // int $summonerName = 'test'; // string $ranked = '0'; // bool $level = 7357; // int $userServerPing = 7357; // int $createDate = '7357'; // string $gameId = 0; // int $ipEarned = 7357; // int $experienceEarned = 7357; // int $gameMapId = 7357; // int $leaver = false; // bool $timeInQueue = 7357; // int $premadeTeam = false; // bool $premadeSize = 7357; // int $gameMode = '7357'; // string $gameType = '7357'; // string $gameTypeEnum = '7357'; // string $queueType = '7357'; // string $subType = '7357'; // string $teammate0 = '0'; // string $teammate0champ = '0'; // string $teammate1 = '0'; // string $teammate1champ = '0'; // string $teammate2 = '0'; // string $teammate2champ = '0'; // string $teammate3 = '0'; // string $teammate3champ = '0'; // string $championId = 7357; // int $spell1 = 7357; // int $spell2 = 7357; // int $win = 0; // int $lose = 0; // int $largestMultiKill = 0; // int $largestKillingSpree = 0; // int $championsKilled = 0; // int $numDeaths = 0; // int $assists = 0; // int $minionsKilled = 0; // int $goldEarned = 7357; // int $neutralMinionsKilled = 0; // int $turretsKilled = 0; // int $barracksKilled = 0; // int $sightWardsBoughtInGame = 0; // int $totalHeal = 0; // int $item0 = 0; // int $item1 = 0; // int $item2 = 0; // int $item3 = 0; // int $item4 = 0; // int $item5 = 0; // int $totalDamageDealt = 7357; // int $physicalDamageDealtPlayer = 7357; // int $magicDamageDealtPlayer = 7357; // int $largestCriticalStrike = 0; // int $totalDamageTaken = 7357; // int $physicalDamageTaken = 7357; // int $magicDamageTaken = 7357; // int $totalTimeSpentDead = 0; // int } // Get at recent games data $account_id_arr = array('accountId' => $summoner_array['acctId']); $recent_games = getEloData($base_url, $region, $key, 'getRecentGames', $account_id_arr, TRUE); //echo $recent_games; $rec_arr = (array) json_decode($recent_games); // for each field in recent games foreach ($rec_arr as $i_key => $i_val) { // gamestatistics if ($i_key == 'gameStatistics') { $all_games = (array) $rec_arr[$i_key]; // for each game in gamestatistics, start with the MOST RECENT (9/9) moving towards OLDEST (0/9); for ($game_num = count($all_games) - 1; $game_num >= 0; $game_num--) { $cur_game = (array) $all_games[$game_num]; // for each field in the current game foreach ($cur_game as $field => $value) { // if it is fellowPlayers if ($field == 'fellowPlayers') { // get the players array $players = (array) $cur_game[$field]; $teammatesCount = 0; // for each player for ($p_id = 0; $p_id < count($players); $p_id++) { // get the current player $cur_player = (array) $players[$p_id]; // if this person is on my team, then add them to teammates $my_teamId = $cur_game['teamId']; if ($cur_player['teamId'] == $my_teamId) { // teammates switch ($teammatesCount) { case 0: // this is the first teammate found $teammate0 = $cur_player['summonerName']; $teammate0champ = $cur_player['championId']; break; case 1: // this is the second teammate found $teammate1 = $cur_player['summonerName']; $teammate1champ = $cur_player['championId']; break; case 2: // this is the third teammate found $teammate2 = $cur_player['summonerName']; $teammate2champ = $cur_player['championId']; break; case 3: // this is the fourth teammate found $teammate3 = $cur_player['summonerName']; $teammate3champ = $cur_player['championId']; break; } $teammatesCount++; } // for each field in the current player foreach ($cur_player as $p_field => $p_value) { $str_p_value = var_export($p_value, TRUE); // echo "cur_player => $p_id, p_field => $p_field, p_value => $str_p_value <br>"; } } // else if it is statistics } else { if ($field == 'statistics') { // get the statistics array $stats = (array) $cur_game[$field]; // for each statistic for ($s_id = 0; $s_id < count($stats); $s_id++) { // get the current stat $cur_stat = (array) $stats[$s_id]; $statName = $cur_stat['statType']; $statValue = $cur_stat['value']; // apply values to all of the sql variables via switch case on the field switch ($statName) { case "WIN": // WIN - bool bit - is represented by 0 or 1 in the JSON though $win = $statValue; break; case "LOSE": // LOSE - bool bit - is represented by 0 or 1 in the JSON though $lose = $statValue; break; case "LARGEST_MULTI_KILL": // LARGEST_MULTI_KILL - int $largestMultiKill = atoi($statValue); break; case "LARGEST_KILLING_SPREE": // LARGEST_KILLING_SPREE - int $largestKillingSpree = atoi($statValue); break; case "CHAMPIONS_KILLED": // CHAMPIONS_KILLED - int $championsKilled = atoi($statValue); break; case "NUM_DEATHS": // NUM_DEATHS - int $numDeaths = atoi($statValue); break; case "ASSISTS": // ASSISTS - int $assists = atoi($statValue); break; case "MINIONS_KILLED": // MINIONS_KILLED - int $minionsKilled = atoi($statValue); break; case "GOLD_EARNED": // GOLD_EARNED - int $goldEarned = atoi($statValue); break; case "NEUTRAL_MINIONS_KILLED": // NEUTRAL_MINIONS_KILLED - int $neutralMinionsKilled = atoi($statValue); break; case "TURRETS_KILLED": // TURRETS_KILLED - int $turretsKilled = atoi($statValue); break; case "BARRACKS_KILLED": // BARRACKS_KILLED - int $barracksKilled = atoi($statValue); break; case "SIGHT_WARDS_BOUGHT_IN_GAME": // SIGHT_WARDS_BOUGHT_IN_GAME - int $sightWardsBoughtInGame = atoi($statValue); break; case "TOTAL_HEAL": // TOTAL_HEAL - int $totalHeal = atoi($statValue); break; case "ITEM0": // ITEM0 - int $item0 = atoi($statValue); break; case "ITEM1": // ITEM1 - int $item1 = atoi($statValue); break; case "ITEM2": // ITEM2 - int $item2 = atoi($statValue); break; case "ITEM3": // ITEM3 - int $item3 = atoi($statValue); break; case "ITEM4": // ITEM4 - int $item4 = atoi($statValue); break; case "ITEM5": // ITEM5 - int $item5 = atoi($statValue); break; case "TOTAL_DAMAGE_DEALT": // TOTAL_DAMAGE_DEALT - int $totalDamageDealt = atoi($statValue); break; case "PHYSICAL_DAMAGE_DEALT_PLAYER": // PHYSICAL_DAMAGE_DEALT_PLAYER - int $physicalDamageDealtPlayer = atoi($statValue); break; case "MAGIC_DAMAGE_DEALT_PLAYER": // MAGIC_DAMAGE_DEALT_PLAYER - int $magicDamageDealtPlayer = atoi($statValue); break; case "LARGEST_CRITICAL_STRIKE": // LARGEST_CRITICAL_STRIKE - int $largestCriticalStrike = atoi($statValue); break; case "TOTAL_DAMAGE_TAKEN": // TOTAL_DAMAGE_TAKEN - int $totalDamageTaken = atoi($statValue); break; case "PHYSICAL_DAMAGE_TAKEN": // PHYSICAL_DAMAGE_TAKEN - int $physicalDamageTaken = atoi($statValue); break; case "MAGIC_DAMAGE_TAKEN": // MAGIC_DAMAGE_TAKEN - int $magicDamageTaken = atoi($statValue); break; case "TOTAL_TIME_SPENT_DEAD": // TOTAL_TIME_SPENT_DEAD - int $totalTimeSpentDead = atoi($statValue); break; } // for each field in the current stats foreach ($cur_stat as $s_field => $s_value) { $str_s_value = var_export($s_value, TRUE); // echo "field =>$s_field, val => $str_s_value <br>"; } } // else if it is NOT an arry, i.e. a general field } else { $str_value = var_export($value, TRUE); // apply values to all of the sql variables via switch case on the field switch ($field) { case "ranked": // ranked - bool $ranked = atob($str_value); break; case "gameType": // gameType - string $gameType = atosql($str_value); break; case "experienceEarned": // experienceEarned - int $experienceEarned = atoi($str_value); break; case "gameMapId": // gameMapId - int $gameMapId = atoi($str_value); break; case "leaver": // leaver - bool $leaver = atob($str_value); break; case "spell1": // spell1 - int $spell1 = atoi($str_value); break; case "spell2": // spell2 - int $spell2 = atoi($str_value); break; case "gameTypeEnum": // gameTypeEnum - string $gameTypeEnum = atosql($str_value); break; case "level": // level - int $level = atoi($str_value); break; case "createDate": // createDate - string $createDate = atosql($str_value); break; case "userServerPing": // userServerPing - int $userServerPing = atoi($str_value); break; case "gameId": // gameId - int $gameId = atoi($str_value); break; case "timeInQueue": // timeInQueue - int $timeInQueue = atoi($str_value); break; case "ipEarned": // ipEarned - int $ipEarned = atoi($str_value); break; case "gameMode": // gameMode - string $gameMode = atosql($str_value); break; case "subType": // subType - string $subType = atosql($str_value); break; case "queueType": // queueType - string $queueType = atosql($str_value); break; case "premadeSize": // premadeSize - int $premadeSize = atoi($str_value); break; case "premadeTeam": // premadeTeam - bool $premadeTeam = atob($str_value); break; case "championId": // championId - int $championId = atoi($str_value); break; } // echo "general field => $field, general value => $str_value <br>"; } } } // do the query here (for each game) // set $query if (true) { /* Fields can be found at sql_fields.txt */ /** Do fixes on fields that report weird values HERE */ // fix the killing spree (if it isn't > 1, it doesn't get returned by Elophant) // therefore, if you have at least one kill but no killing spree, your spree must be 1. if ($championsKilled > 0 && $largestKillingSpree == 0) { $largestKillingSpree = 1; } // fix the premade size value - for some reason, when you play a ranked 5v5 // game it gets reported as zero. Obviously this isn't right. if ($queueType == 'RANKED_TEAM_5x5') { $premadeSize = 5; } // fix weird custom game thing where it gets reported as 0 if ($premadeSize == 0) { $premadeSize = 1; } // Set the accountId $accountId = $summoner_array['acctId']; // Set the summonerName $summonerName = $summoner_array['name']; // SET THE PRIMARY KEY $pkey = strval($gameId) . strval($accountId); // Set the query $query = "INSERT INTO games VALUES (\n '{$pkey}',\n '{$accountId}',\n '{$summonerName}',\n '{$ranked}',\n '{$level}',\n '{$userServerPing}',\n '{$createDate}',\n '{$gameId}',\n '{$ipEarned}',\n '{$experienceEarned}',\n '{$gameMapId}',\n '{$leaver}',\n '{$timeInQueue}',\n '{$premadeTeam}',\n '{$premadeSize}',\n '{$gameMode}',\n '{$gameType}',\n '{$gameTypeEnum}',\n '{$queueType}',\n '{$subType}',\n '{$teammate0}',\n '{$teammate0champ}',\n '{$teammate1}',\n '{$teammate1champ}',\n '{$teammate2}',\n '{$teammate2champ}',\n '{$teammate3}',\n '{$teammate3champ}',\n '{$championId}',\n '{$spell1}',\n '{$spell2}',\n '{$win}',\n '{$lose}',\n '{$largestMultiKill}',\n '{$largestKillingSpree}',\n '{$championsKilled}',\n '{$numDeaths}',\n '{$assists}',\n '{$minionsKilled}',\n '{$goldEarned}',\n '{$neutralMinionsKilled}',\n '{$turretsKilled}',\n '{$barracksKilled}',\n '{$sightWardsBoughtInGame}',\n '{$totalHeal}',\n '{$item0}',\n '{$item1}',\n '{$item2}',\n '{$item3}',\n '{$item4}',\n '{$item5}',\n '{$totalDamageDealt}',\n '{$physicalDamageDealtPlayer}',\n '{$magicDamageDealtPlayer}',\n '{$largestCriticalStrike}',\n '{$totalDamageTaken}',\n '{$physicalDamageTaken}',\n '{$magicDamageTaken}',\n '{$totalTimeSpentDead}'\n );"; } // execute the query $total_games = $num_old_games + $gamesSuccessfullyParsed; debug('total_games: ' . $total_games); debug('oldest_game: ' . $oldest_game); $q_err = $mysqli->query($query) or die(json_encode(array('total_games' => $total_games, 'parsed_games' => $gamesSuccessfullyParsed, 'oldest_game' => $oldest_game, 'name' => $summoner_array['name']))); $gamesSuccessfullyParsed++; // clear all the values back to test or 7357 or 0 if (true) { /** Fields can be found at sql_fields.txt */ $primaryKey = 73577357; $accountId = 7357; // int $summonerName = 'test'; // string $ranked = '0'; // bool $level = 7357; // int $userServerPing = 7357; // int $createDate = '7357'; // string $gameId = 0; // int $ipEarned = 7357; // int $experienceEarned = 7357; // int $gameMapId = 7357; // int $leaver = false; // bool $timeInQueue = 7357; // int $premadeTeam = false; // bool $premadeSize = 7357; // int $gameMode = '7357'; // string $gameType = '7357'; // string $gameTypeEnum = '7357'; // string $queueType = '7357'; // string $subType = '7357'; // string $teammate0 = '0'; // string $teammate0champ = '0'; // string $teammate1 = '0'; // string $teammate1champ = '0'; // string $teammate2 = '0'; // string $teammate2champ = '0'; // string $teammate3 = '0'; // string $teammate3champ = '0'; // string $championId = 7357; // int $spell1 = 7357; // int $spell2 = 7357; // int $win = 0; // int $lose = 0; // int $largestMultiKill = 0; // int $largestKillingSpree = 0; // int $championsKilled = 0; // int $numDeaths = 0; // int $assists = 0; // int $minionsKilled = 0; // int $goldEarned = 7357; // int $neutralMinionsKilled = 0; // int $turretsKilled = 0; // int $barracksKilled = 0; // int $sightWardsBoughtInGame = 0; // int $totalHeal = 0; // int $item0 = 0; // int $item1 = 0; // int $item2 = 0; // int $item3 = 0; // int $item4 = 0; // int $item5 = 0; // int $totalDamageDealt = 7357; // int $physicalDamageDealtPlayer = 7357; // int $magicDamageDealtPlayer = 7357; // int $largestCriticalStrike = 0; // int $totalDamageTaken = 7357; // int $physicalDamageTaken = 7357; // int $magicDamageTaken = 7357; // int $totalTimeSpentDead = 0; // int } } $total_games = $num_old_games + $gamesSuccessfullyParsed; debug('total_games: ' . $total_games); debug('oldest game: ' . $oldest_game); echo json_encode(array('total_games' => $total_games, 'parsed_games' => $gamesSuccessfullyParsed, 'oldest_game' => $oldest_game, 'name' => $summoner_array['name'])); } } $mysqli->close(); }