예제 #1
0
/**
 * Recommend champion by provided primary/secondary roles
 *
 * @param $primary_role string the primary role to search by
 * @param $secondary_role string the secondary role to search by, or null if not applicable
 * @return string the champion that has the highest winrate in the roles provided
 */
function recommend_by_role($primary_role, $secondary_role)
{
    $response = file_get_contents('https://global.api.pvp.net/api/lol/static-data/na/v1.2/champion?champData=tags&api_key=7fd3b97d-df0c-4ced-b7d8-810a89c8e874');
    $arr = json_decode($response, true);
    $champions = [];
    foreach ($arr["data"] as $champion => $champ_data) {
        if ($secondary_role == null) {
            if ($champ_data["tags"][0] == $primary_role && $champ_data["tags"][1] == null) {
                $champions[$champion] = get_winrate_for_champ($champion);
            }
        } else {
            if ($champ_data["tags"][0] == $primary_role && $champ_data["tags"][1] == $secondary_role) {
                $champions[$champion] = get_winrate_for_champ($champion);
            }
        }
    }
    $best_winrate = 0;
    foreach ($champions as $winrate) {
        if ($winrate > $best_winrate) {
            $best_winrate = $winrate;
        }
    }
    echo array_search($best_winrate, $champions);
    /*$data = [];
        $data['Assassin'] = [];
        $data['Fighter'] = [];
        $data['Mage'] = [];
        $data['Support'] = [];
        $data['Tank'] = [];
        $data['Marksman'] = [];
     
        foreach($arr["data"] as $champion){
            //if champion has only one role, assign it to first tier of array
            if ($champion["tags"][1] == null) {
                array_push($data[$champion["tags"][0]], $champion["name"]);
            }
            //if champion has two roles, assign it to a second tier based off of secondary role
            else{
                //if haven't already created the secondary role array, create it
                if($data[$champion["tags"][0]][$champion["tags"][1]] == null){
                    $data[$champion["tags"][0]][$champion["tags"][1]] = [];
                }
                array_push($data[$champion["tags"][0]][$champion["tags"][1]], $champion["name"]);
            }
        }*/
    /*foreach($data as $primaryRole => $role){
          foreach($role as $secondaryRole => $champion){
              if (is_array($champion)){
                  foreach($champion as $c){
                      echo $c . ' has role of ' . $primaryRole . ' and ' . $secondaryRole . '<br>';
                  }
              }
              else{
                  echo $champion . ' has role of ' . $primaryRole . '<br>';
              }
          }
      }*/
}
예제 #2
0
include 'recommend_champ.php';
$servername = "pickachamp.web.engr.illinois.edu";
$serverUser = "******";
$serverPassword = "******";
$dbname = "pickacha_db";
//Create connection
$conn = new mysqli($servername, $serverUser, $serverPassword, $dbname);
//Check connection
if (mysqli_connect_error()) {
    die("Database failed: " . mysqli_connect_error());
}
$sql = "SELECT name FROM championList";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // update each row
    while ($row = $result->fetch_assoc()) {
        $name = $row["name"];
        $sql = "UPDATE championList SET winrate=" . get_winrate_for_champ($name) . "WHERE name=\"{$name}\"";
        echo $sql;
        if ($conn->query($sql) === TRUE) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . $conn->error;
        }
    }
} else {
    //echo "0 results";
}
$conn->close();
return 0;