Exemple #1
0
 static function computeNewScores($id_set_type, $init_score_player_1_win, $init_score_player_2_win, $init_score_player_1_lose, $init_score_player_2_lose, $init_nb_sets_player_1_win, $init_nb_sets_player_2_win, $init_nb_sets_player_1_lose, $init_nb_sets_player_2_lose, &$new_score_player_1_win, &$new_score_player_2_win, &$new_score_player_1_lose, &$new_score_player_2_lose)
 {
     if (ModelSetType::isSingles($id_set_type)) {
         if ($init_score_player_1_win - $init_score_player_1_lose > 10) {
             // winner already had a much bigger score than loser => scores unchanged
             $new_score_player_1_win = $init_score_player_1_win;
             $new_score_player_1_lose = $init_score_player_1_lose;
         } else {
             // new winner score
             $nb_sets_for_average = min($init_nb_sets_player_1_win, MAX_SETS_FOR_AVERAGE);
             $new_score_player_1_win = ($init_score_player_1_win * $nb_sets_for_average + 10 + $init_score_player_1_lose) / ($nb_sets_for_average + 1);
             $new_score_player_1_win = max($init_score_player_1_win, $new_score_player_1_win);
             // only >= 0 variations
             // new loser score
             $nb_sets_for_average = min($init_nb_sets_player_1_lose, MAX_SETS_FOR_AVERAGE);
             $new_score_player_1_lose = ($init_score_player_1_lose * $nb_sets_for_average + max(0, $init_score_player_1_win - 10)) / ($nb_sets_for_average + 1);
             $new_score_player_1_lose = min($init_score_player_1_lose, $new_score_player_1_lose);
             // only <= 0 variations
         }
     } else {
         $init_score_winning_team = ($init_score_player_1_win + $init_score_player_2_win) / 2;
         $init_score_losing_team = ($init_score_player_1_lose + $init_score_player_2_lose) / 2;
         if ($init_score_winning_team - $init_score_losing_team > 10) {
             // winners already had a much bigger score than losers => scores unchanged
             $new_score_player_1_win = $init_score_player_1_win;
             $new_score_player_2_win = $init_score_player_2_win;
             $new_score_player_1_lose = $init_score_player_1_lose;
             $new_score_player_2_lose = $init_score_player_2_lose;
         } else {
             // new winners scores
             $nb_sets_for_average = min($init_nb_sets_player_1_win, MAX_SETS_FOR_AVERAGE);
             $new_score_player_1_win = ($init_score_player_1_win * $nb_sets_for_average + 10 + $init_score_losing_team) / ($nb_sets_for_average + 1);
             $new_score_player_1_win = max($init_score_player_1_win, $new_score_player_1_win);
             // only >= 0 variations
             $nb_sets_for_average = min($init_nb_sets_player_2_win, MAX_SETS_FOR_AVERAGE);
             $new_score_player_2_win = ($init_score_player_2_win * $nb_sets_for_average + 10 + $init_score_losing_team) / ($nb_sets_for_average + 1);
             $new_score_player_2_win = max($init_score_player_2_win, $new_score_player_2_win);
             // only >= 0 variations
             // new losers scores
             $nb_sets_for_average = min($init_nb_sets_player_1_lose, MAX_SETS_FOR_AVERAGE);
             $new_score_player_1_lose = ($init_score_player_1_lose * $nb_sets_for_average + max(0, $init_score_winning_team - 10)) / ($nb_sets_for_average + 1);
             $new_score_player_1_lose = min($init_score_player_1_lose, $new_score_player_1_lose);
             // only <= 0 variations
             $nb_sets_for_average = min($init_nb_sets_player_2_lose, MAX_SETS_FOR_AVERAGE);
             $new_score_player_2_lose = ($init_score_player_2_lose * $nb_sets_for_average + max(0, $init_score_winning_team - 10)) / ($nb_sets_for_average + 1);
             $new_score_player_2_lose = min($init_score_player_2_lose, $new_score_player_2_lose);
             // only <= 0 variations
         }
     }
 }
 /**
  * @dataProvider testProvider
  */
 function test($id_set_type, $init_score_player_1_win, $init_score_player_2_win, $init_score_player_1_lose, $init_score_player_2_lose, $init_nb_sets_player_1_win, $init_nb_sets_player_2_win, $init_nb_sets_player_1_lose, $init_nb_sets_player_2_lose, $expected_new_score_player_1_win, $expected_new_score_player_2_win, $expected_new_score_player_1_lose, $expected_new_score_player_2_lose)
 {
     $new_score_player_1_win = 0;
     $new_score_player_1_lose = 0;
     if (ModelSetType::isSingles($id_set_type)) {
         $new_score_player_2_win = 'NULL';
         $new_score_player_2_lose = 'NULL';
     } else {
         $new_score_player_2_win = 0;
         $new_score_player_2_lose = 0;
     }
     Scoring::computeNewScores($id_set_type, $init_score_player_1_win, $init_score_player_2_win, $init_score_player_1_lose, $init_score_player_2_lose, $init_nb_sets_player_1_win, $init_nb_sets_player_2_win, $init_nb_sets_player_1_lose, $init_nb_sets_player_2_lose, $new_score_player_1_win, $new_score_player_2_win, $new_score_player_1_lose, $new_score_player_2_lose);
     $this->assertEquals($expected_new_score_player_1_win, $new_score_player_1_win, '', 0.01);
     $this->assertEquals($expected_new_score_player_2_win, $new_score_player_2_win, '', 0.01);
     $this->assertEquals($expected_new_score_player_1_lose, $new_score_player_1_lose, '', 0.01);
     $this->assertEquals($expected_new_score_player_2_lose, $new_score_player_2_lose, '', 0.01);
 }
Exemple #3
0
 /**
  * @data array with indexes:
  * - 'id_set_type': integer
  * - 'id_player_1_win': integer
  * - 'id_player_2_win': integer or NULL
  * - 'id_player_1_lose': integer
  * - 'id_player_2_lose': integer or NULL
  * - 'creation_datetime': string at format 'YYYY-MM-DD HH:MM:SS', OPTIONAL
  */
 static function add($data)
 {
     $id_set_type = $data['id_set_type'];
     $id_player_1_win = $data['id_player_1_win'];
     $id_player_2_win = $data['id_player_2_win'];
     $id_player_1_lose = $data['id_player_1_lose'];
     $id_player_2_lose = $data['id_player_2_lose'];
     $init_score_player_1_win = ModelSet::getLatestScore($id_player_1_win, $id_set_type);
     $init_score_player_1_lose = ModelSet::getLatestScore($id_player_1_lose, $id_set_type);
     $init_nb_sets_player_1_win = ModelSet::getNbSets($id_player_1_win, $id_set_type);
     $init_nb_sets_player_1_lose = ModelSet::getNbSets($id_player_1_lose, $id_set_type);
     $new_score_player_1_win = DEFAULT_SCORE;
     $new_score_player_1_lose = DEFAULT_SCORE;
     if (ModelSetType::isDoubles($id_set_type)) {
         $init_score_player_2_win = ModelSet::getLatestScore($id_player_2_win, $id_set_type);
         $init_score_player_2_lose = ModelSet::getLatestScore($id_player_2_lose, $id_set_type);
         $init_nb_sets_player_2_win = ModelSet::getNbSets($id_player_2_win, $id_set_type);
         $init_nb_sets_player_2_lose = ModelSet::getNbSets($id_player_2_lose, $id_set_type);
         $new_score_player_2_win = DEFAULT_SCORE;
         $new_score_player_2_lose = DEFAULT_SCORE;
     } else {
         // set scoring data for doubles to NULL
         $init_score_player_2_win = 'NULL';
         $init_score_player_2_lose = 'NULL';
         $init_nb_sets_player_2_win = 'NULL';
         $init_nb_sets_player_2_lose = 'NULL';
         $new_score_player_2_win = 'NULL';
         $new_score_player_2_lose = 'NULL';
     }
     Scoring::computeNewScores($id_set_type, $init_score_player_1_win, $init_score_player_2_win, $init_score_player_1_lose, $init_score_player_2_lose, $init_nb_sets_player_1_win, $init_nb_sets_player_2_win, $init_nb_sets_player_1_lose, $init_nb_sets_player_2_lose, $new_score_player_1_win, $new_score_player_2_win, $new_score_player_1_lose, $new_score_player_2_lose);
     $row = array('id_set_type' => $id_set_type, 'id_player_1_win' => $id_player_1_win, 'id_player_2_win' => $id_player_2_win === NULL ? 'NULL' : $id_player_2_win, 'id_player_1_lose' => $id_player_1_lose, 'id_player_2_lose' => $id_player_2_lose === NULL ? 'NULL' : $id_player_2_lose, 'init_score_player_1_win' => $init_score_player_1_win, 'init_score_player_2_win' => $init_score_player_2_win, 'init_score_player_1_lose' => $init_score_player_1_lose, 'init_score_player_2_lose' => $init_score_player_2_lose, 'init_nb_sets_player_1_win' => $init_nb_sets_player_1_win, 'init_nb_sets_player_2_win' => $init_nb_sets_player_2_win, 'init_nb_sets_player_1_lose' => $init_nb_sets_player_1_lose, 'init_nb_sets_player_2_lose' => $init_nb_sets_player_2_lose, 'new_score_player_1_win ' => $new_score_player_1_win, 'new_score_player_2_win ' => $new_score_player_2_win, 'new_score_player_1_lose' => $new_score_player_1_lose, 'new_score_player_2_lose' => $new_score_player_2_lose);
     if (isset($data['creation_datetime'])) {
         $row['creation_datetime'] = "'" . Database::escape($data['creation_datetime']) . "'";
     }
     Database::insert(array('table' => 'bad_set', 'row' => $row));
 }
Exemple #4
0
<?php

include_once 'model/SetType.php';
include_once 'model/Player.php';
// retrieve set types
$raw_set_types = ModelSetType::get(array('order_by' => 'name'));
$set_types = array('' => 'Choisir...');
foreach ($raw_set_types as $row) {
    $set_types[$row['id']] = $row['name'];
}
// retrieve players
$raw_players = ModelPlayer::get(array('order_by' => 'first_name, last_name'));
$players = array('' => 'Aucun');
foreach ($raw_players as $row) {
    $players[$row['id']] = $row['first_name'] . ' ' . $row['last_name'];
}
$form_url = Routing::getUrlFor(array('module' => $g_current_module, 'action' => $g_current_action));
?>
<h2>Ajouter un set</h2>

<form id="form_add_set" class="form-horizontal" action="<?php 
echo htmlspecialchars($form_url);
?>
" method="post" onsubmit="return checkDistinctPlayers(this);">

  <div class="form-group">
    <label for="id_set_type" class="col-sm-2 control-label">Type de set</label>
    <div class="col-sm-10">
      <?php 
Helper::buildSelect(array('name' => 'id_set_type', 'options' => $set_types));
?>
Exemple #5
0
 static function getForPlayer($id_player)
 {
     // not perf wise for this first version
     $result_rankings = array();
     $set_types = ModelSetType::get(array('order_by' => 'name'));
     foreach ($set_types as $type) {
         $ranking = self::get($type['id']);
         $player_found = FALSE;
         $pos = 1;
         foreach ($ranking as $player_data) {
             if ($player_data['id'] == $id_player) {
                 $player_found = TRUE;
                 break;
             }
             $pos++;
         }
         if (!$player_found) {
             continue;
         }
         // skip to next 'set type'
         $result_rankings[] = array('category_name' => $type['name'], 'category_abbreviation' => $type['abbreviation'], 'player_rank' => $player_data['rank'], 'player_fair_rank' => $player_data['fair_rank'], 'total_players' => count($ranking), 'player_score' => $player_data['score'], 'player_nb_sets' => $player_data['nb_sets']);
     }
     return $result_rankings;
 }
Exemple #6
0
   <th>Nb sets initial G1</th>
   <th>Nb sets initial G2</th>
   <th>Nb sets initial P1</th>
   <th>Nb sets initial P2</th>
   -->
 </tr>
 </thead>
 <tbody>
 <?php 
   foreach ($rows as $row) {
       // compute & format variations
       $str_var_w1 = Helper::getHTMLCodeForScoreVariation($row['new_score_player_1_win'], $row['init_score_player_1_win']);
       $str_var_l1 = Helper::getHTMLCodeForScoreVariation($row['new_score_player_1_lose'], $row['init_score_player_1_lose']);
       $row['new_score_player_1_win'] = number_format($row['new_score_player_1_win'], 1);
       $row['new_score_player_1_lose'] = number_format($row['new_score_player_1_lose'], 1);
       if (ModelSetType::isDoubles($row['id_set_type'])) {
           $str_var_w2 = Helper::getHTMLCodeForScoreVariation($row['new_score_player_2_win'], $row['init_score_player_2_win']);
           $str_var_l2 = Helper::getHTMLCodeForScoreVariation($row['new_score_player_2_lose'], $row['init_score_player_2_lose']);
           $row['new_score_player_2_win'] = number_format($row['new_score_player_2_win'], 1);
           $row['new_score_player_2_lose'] = number_format($row['new_score_player_2_lose'], 1);
       } else {
           $str_var_w2 = '';
           $str_var_l2 = '';
       }
       $creation_datetime = new DateTime($row['creation_datetime']);
       echo '
     <tr>
       <!-- <td>' . $row['id'] . '</td> -->
       <td>' . $creation_datetime->format('j/n/Y - H:i') . '</td>
       <td class="center">' . $row['st_abbreviation'] . '</td>