Exemple #1
0
function printScoreDetails()
{
    global $appProfDet;
    $appProfDet = fetchApplicationProfileById($_GET['profile']);
    $ids = explode(",", $_GET['experiments']);
    $sessie = $_SESSION["experiments"];
    $timeout = 5;
    echo "\n\t<table class=\"table table-hover\">\n\t\t<thead>\n\t\t\t<tr>\n\t\t\t\t<th>SUT</th>\n\t\t\t\t<th colspan='2'>Point accuracy<br/><font size='-1' color='grey'>" . $appProfDet['PA_type'] . "</font></th>\n\t\t\t\t<th colspan='2'>Room accuracy<br/><font size='-1' color='grey'>Average</font></th>\n\t\t\t\t<th colspan='2'>Latency<br/><font size='-1' color='grey'>" . $appProfDet['LA_type'] . "</font></th>\n\t\t\t\t<th colspan='2'>Energy<br/><font size='-1' color='grey'>" . $appProfDet['EN_type'] . "</font</th>\n\t\t\t\t<th></th>\n\t\t\t\t<th><b>TOTAL</b></th>\n\t\t\t</tr>\n\t\t</thead>\n\t\t<tbody>";
    foreach ($ids as $e) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $sessie[$e - 1]->url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        $ce = json_decode($data);
        echo "\t<tr>\n\t\t\t\t<td style='vertical-align: middle;'>" . $ce->sut->sut_name . "</td>\n\t\t\t\t<td width='65px'  style='vertical-align: middle;'><font size='+2'>" . calculatePointAccuracy($ce) . "</font></td>\n\t\t\t\t<td width='100px' style='vertical-align: middle;'>x " . $appProfDet['PA_weight'] . "</td>\n\t\t\t\t<td width='65px'  style='vertical-align: middle;'><font size='+2'>" . calculateRoomAccuracy($ce) . "</font></td>\n\t\t\t\t<td width='100px' style='vertical-align: middle;'>x " . $appProfDet['RA_weight'] . "</td>\n\t\t\t\t<td width='65px'  style='vertical-align: middle;'><font size='+2'>" . calculateLatency($ce) . "</font></td>\n\t\t\t\t<td width='100px' style='vertical-align: middle;'>x " . $appProfDet['LA_weight'] . "</td>\n\t\t\t\t<td width='65px'  style='vertical-align: middle;'><font size='+2'>" . calculateEnergy($ce) . "</font></td>\n\t\t\t\t<td width='60px'  style='vertical-align: middle;'>x " . $appProfDet['EN_weight'] . "</td>\n\t\t\t\t<td width='10px'  style='vertical-align: middle;'><font size='+2'>=</font></td>\n\t\t\t\t<td width='100px' style='vertical-align: middle;'><font size='+3'><b>" . calculateTotalScore($ce) . "</b></font></td>\n\t\t\t</tr>";
    }
    echo "\n\t\t</tbody>\n\t</table>\n\t</br>";
}
function printOutPlayerInfoOnTeam($playerID, $gameID, $teamID, $playerTitle)
{
    $teamName = getTeamNameForTeamId($teamID);
    $playerName = getPlayerNameForPlayerId($playerID);
    echo '<tr>';
    if ($_SESSION['player_id'] == $playerID) {
        $conn = connectToDatabase();
        //get number of last frame
        $frameNumber = 1;
        $query = "SELECT max(Frame_Number) as 'max' FROM Frame WHERE player_ID = {$playerID} AND Game_ID = {$gameID} AND Team_ID = {$teamID}";
        $allFrames = $conn->query($query);
        $temp = $allFrames->fetch_assoc();
        $maxFrame = $temp['max'];
        $gameIsDone = 0;
        //set current frame number and roll ID
        $rollID = '';
        if ($maxFrame == 10) {
            //on the tenth frame
            //see if game is done, in case of tenth frame
            $query = "SELECT * FROM Frame WHERE player_ID = {$playerID} AND Game_ID = {$gameID} AND Team_ID = {$teamID} AND Frame_Number = {$maxFrame}";
            $result = $conn->query($query);
            if ($result) {
                //frame exists
                $row = $result->fetch_assoc();
                $rollOneID = $row['Roll_One_ID'];
                $query = "SELECT * FROM Roll WHERE Roll_ID = {$rollOneID}";
                $result2 = $conn->query($query);
                if ($result2) {
                    //roll one exists
                    $pinsDown1 = getNumberOfPinsHitForRollID($rollOneID);
                    if ($pinsDown1 > 0) {
                        //roll one is full
                        //look for roll 2
                        $rollTwoID = $row['Roll_Two_ID'];
                        $query = "SELECT * FROM Roll WHERE Roll_ID = {$rollTwoID}";
                        $result2 = $conn->query($query);
                        if ($result2) {
                            //roll two exists
                            $pinsDown2 = getNumberOfPinsHitForRollID($rollTwoID);
                            if ($pinsDown2 > 0) {
                                //roll two is full
                                //check if roll three should be set
                                $pinsDown1 = getNumberOfPinsHitForRollID($row['Roll_One_ID']);
                                $pinsDown2 = getNumberOfPinsHitForRollID($row['Roll_Two_ID']);
                                $total = $pinsDown1 + $pinsDown2;
                                if ($total >= 10) {
                                    //roll three needed
                                    //check if roll three is set
                                    $rollThreeID = $row['Roll_Three_ID'];
                                    $query = "SELECT * FROM Roll WHERE Roll_ID = {$rollThreeID}";
                                    $result2 = $conn->query($query);
                                    if ($result2) {
                                        //roll three exists
                                        $gameIsDone = 1;
                                    } else {
                                        //roll three does not exist
                                        $gameIsDone = 0;
                                    }
                                } else {
                                    //roll three should be null, game is done
                                    $gameIsDone = 1;
                                }
                            } else {
                                //roll two is empty
                                $rollID = $rollTwoID;
                                $frameNumber = $maxFrame;
                            }
                        } else {
                            //roll two doesn't exist
                            $rollID = $rollTwoID;
                            $frameNumber = $maxFrame;
                        }
                    } else {
                        //row one is empty
                        $rollID = $rollOneID;
                        $frameNumber = $maxFrame;
                    }
                }
            }
        } else {
            if ($maxFrame > 0) {
                //max is less than 10
                //see if game is done, in case of normal frame
                $query = "SELECT * FROM Frame WHERE player_ID = {$playerID} AND Game_ID = {$gameID} AND Team_ID = {$teamID} AND Frame_Number = {$maxFrame}";
                $result = $conn->query($query);
                if ($result) {
                    //frame exists
                    $row = $result->fetch_assoc();
                    $rollOneID = $row['Roll_One_ID'];
                    $query = "SELECT * FROM Roll WHERE Roll_ID = {$rollOneID}";
                    $result2 = $conn->query($query);
                    if ($result2) {
                        //roll one exists
                        $pinsDown1 = getNumberOfPinsHitForRollID($rollOneID);
                        if ($pinsDown1 > 0) {
                            //roll one is full
                            if ($pinsDown1 == 10) {
                                // roll one is a strike
                                //look to next frame
                                $frameNumber = $maxFrame + 1;
                            } else {
                                //roll one is not a strike
                                //look for roll 2
                                $rollTwoID = $row['Roll_Two_ID'];
                                $query = "SELECT * FROM Roll WHERE Roll_ID = {$rollTwoID}";
                                $result2 = $conn->query($query);
                                if ($result2) {
                                    //roll two exists
                                    $pinsDown2 = getNumberOfPinsHitForRollID($rollTwoID);
                                    if ($pinsDown2 > 0) {
                                        //roll two is full
                                        //look to next frame
                                        $frameNumber = $maxFrame + 1;
                                    } else {
                                        //roll two is empty
                                        $rollID = $rollTwoID;
                                        $frameNumber = $maxFrame;
                                    }
                                } else {
                                    //frame two doesn't exist
                                    $rollID = $rollTwoID;
                                    $frameNumber = $maxFrame;
                                }
                            }
                        } else {
                            //row one is empty
                            $rollID = $rollOneID;
                            $frameNumber = $maxFrame;
                        }
                    } else {
                        //frame one doesn't exist
                        $rollID = $rollOneID;
                        $frameNumber = $maxFrame;
                    }
                }
            }
        }
        //if maxFrames is 0, then frame number stays as 1
        //check if button shows
        if (!$gameIsDone) {
            //show button
            //            echo "current frame = $frameNumber";
            //            echo "roll ID = $rollID";
            echo "<th colspan=6 rowspan=2><form action='addRoll.php' method='post'>\n                <input type='hidden' name='gameID' value='{$gameID}'>\n                <input type='hidden' name='teamID' value='{$teamID}'>\n                <input type='hidden' name='playerID' value='{$playerID}'>\n                <input type='hidden' name='frameNumber' value='{$frameNumber}'>\n                <input type='hidden' name='rollID' value='{$rollID}'>\n                <input type='submit' value='Add Roll'>";
            echo "</form></th>";
            echo "<th colspan=6 rowspan=2>{$teamName}<br>{$playerTitle}: {$playerName}</th>";
        } else {
            //show normal box
            echo "<th colspan=12 rowspan=2>{$teamName}<br>{$playerTitle}: {$playerName}</th>";
        }
    } else {
        //not the logged in player
        echo "<th colspan=12 rowspan=2>{$teamName}<br>{$playerTitle}: {$playerName}</th>";
    }
    printRollsInformation($playerID, $gameID, $teamID);
    $game = calculateTotalScore($playerID, $gameID, $teamID);
    $score = $game->score();
    echo "<th colspan='6' rowspan=2>{$score}</th>";
    printOutFrameTotals($playerID, $gameID, $teamID, $game->score_by_frame());
    echo '</tr>';
}