File "debug_multiple.php"
Full Path: /home/analogde/www/Bookmarks/CHESS_ON/debug_multiple.php
File size: 15.35 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start();
include('database.php');
DB_connexion();
header('Content-Type: text/html; charset=utf-8');
$_SESSION['chessmaster'] = "clone_chessmaster_new";
$_SESSION['classement'] = "clone_classement_new";
$_SESSION['parties'] = "clone_parties_new";
$_SESSION['evolution'] = "clone_evolution_new";
$_SESSION['membres'] = "membres";
$_SESSION['elo_affectation'] = "clone_elo_affectation";
$J1 = "HenriqueF"; //$_GET["J1"];
$J2 = "FranckV"; //$_GET["J2"];
//$J1 = $_POST["J1"];
//$J2 = $_POST["J2"];
/*
$ret = findIdPlayer($J1);
echo "J1 : " .$ret;
echo "<br>";
if(is_null($ret))
{
$J1_id = -1;;
}
else
{
$J1_id = $ret;
}
$ret = findIdPlayer($J2);
echo "J2 : " .$ret;
echo "<br>";
if(is_null($ret))
{
$J2_id = -1;;
}
else
{
$J2_id = $ret;
}
//echo " ---> " .$J1_id ." ---- " .$J2_id;
*/
$tab = findIdPlayer($J1,$J2);
//echo $tab[0] ." " .$tab[1];
if( $tab[0] != -1 && $$tab[1] != -1 )
// if( $J1_id != -1 && $J2_id != -1 )
{
generation_data($tab[0], $tab[1]);
}
/***************************************************************/
function generation_data($J1_id, $J2_id)
{
//$playerID = $J1_id; //"12";
$J1_data = extract_data($J1_id);
//echo "<pre>";
//print_r($J1_data);
//echo "</pre>";
//$playerID = $J2_id; //"9";
$J2_data = extract_data($J2_id);
//echo "<pre>";
//print_r($J2_data);
//echo "</pre>";
/**/
$J1_nb_parties = count($J1_data);
//echo "NB " .$J1_nb_parties;
//echo "<br><br>";
$J1_start_timestamp = $J1_data[0]["aaa"];
$J1_start_date = $J1_data[0]["bbb"];
//echo "Start " .$J1_start_timestamp ." " .$J1_start_date;
//echo "<br><br>";
$J1_stop_timestamp = $J1_data[$J1_nb_parties-1]["aaa"];
$J1_stop_date = $J1_data[$J1_nb_parties-1]["bbb"];
//echo "Stop " .$J1_stop_timestamp ." " .$J1_stop_date;
//echo "<br><br>";
/**/
$J2_nb_parties = count($J2_data);
//echo "NB " .$J2_nb_parties;
//echo "<br><br>";
$J2_start_timestamp = $J2_data[0]["aaa"];
$J2_start_date = $J2_data[0]["bbb"];
//echo "Start " .$J2_start_timestamp ." " .$J2_start_date;
//echo "<br><br>";
$J2_stop_timestamp = $J2_data[$J2_nb_parties-1]["aaa"];
$J2_stop_date = $J2_data[$J2_nb_parties-1]["bbb"];
//echo "Stop " .$J2_stop_timestamp ." " .$J2_stop_date;
//echo "<br><br>";
if( $J1_start_timestamp < $J2_start_timestamp)
{
$date_start = $J1_start_date;
}
else
{
$date_start = $J2_start_date;
}
if( $J1_stop_timestamp < $J2_stop_timestamp)
{
$date_stop = $J2_stop_date;
}
else
{
$date_stop = $J1_stop_date;
}
//echo " +++ " .$date_start ." " .$date_stop;
$tab_timestamp = interval( date_formatted($date_start), date_formatted($date_stop));
//echo "<pre>";
//print_r($tab_timestamp);
//echo "</pre>";
/************/
$J1_elo_data = array();
//for ($i = 0; $i <= count($tab_timestamp)-1; $i++)
for ($i = 0; $i < count($tab_timestamp); $i++)
{
$timestamp = strtotime($tab_timestamp[$i]);
$tmp =array( $timestamp, "J1", "val");
$J1_elo_data[] = $tmp;
}
//echo " J1 data";
//echo "<br><br>";
//echo "<pre>";
//print_r($J1_elo_data);
//echo "</pre>";
//echo "<br><br>";
$J2_elo_data = array();
//for ($i = 0; $i <= count($tab_timestamp)-1; $i++)
for ($i = 0; $i < count($tab_timestamp); $i++)
{
$timestamp = strtotime($tab_timestamp[$i]);
$tmp =array( $timestamp, "J2", "val");
$J2_elo_data[] = $tmp;
}
//echo " J2 data";
//echo "<br><br>";
//echo "<pre>";
//print_r($J2_elo_data);
//echo "</pre>";
//echo "<br><br>";
/************/
//$cpt = 1;
for ($i = 0; $i < count($J1_elo_data); $i++)
{
$find_timestamp = $J1_elo_data[$i][0];
$find = 0;
for ($j = 0; $j < count($J1_data); $j++)
{
$key = "aaa";
if( $J1_data[$j][$key] == $find_timestamp)
{
//echo " +++++ " .$cpt . " " .$find_timestamp . " " .$J1_data[$j]["ccc"];
//echo "<br>";
//$cpt++;
$find = 1;
$J1_elo_data[$i][2] = $J1_data[$j]["ccc"];
break;
}
}
if( $find == 0)
{
if($i == 0)
{
$J1_elo_data[$i][2] = "1400";
}
else
{
$J1_elo_data[$i][2] = $J1_elo_data[$i-1][2];
}
}
}
//echo "------ J1 ---------";
//echo "<br><br>";
//echo "<pre>";
//print_r($J1_elo_data);
//echo "</pre>";
/************/
//$cpt = 1;
for ($i = 0; $i < count($J2_elo_data); $i++)
{
$find_timestamp = $J2_elo_data[$i][0];
$find = 0;
for ($j = 0; $j < count($J2_data); $j++)
{
$key = "aaa";
if( $J2_data[$j][$key] == $find_timestamp)
{
//echo " +++++ " .$cpt . " " .$find_timestamp . " " .$J2_data[$j]["ccc"];
//echo "<br>";
//$cpt++;
$find = 1;
$J2_elo_data[$i][2] = $J2_data[$j]["ccc"];
break;
}
}
if( $find == 0)
{
if($i == 0)
{
$J2_elo_data[$i][2] = "1400";
}
else
{
$J2_elo_data[$i][2] = $J2_elo_data[$i-1][2];
}
}
}
//echo "------ J2 ---------";
//echo "<br><br>";
//echo "<pre>";
//print_r($J2_elo_data);
//echo "</pre>";
/************/
$parties_timestamp_identique = array();
for ($i = 0; $i < count($J1_elo_data); $i++)
{
$time_search = $J1_elo_data[$i][0];
$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE date = '$time_search' ";
//echo $sql;
//echo "<br>";
$results = mysql_query($sql);
$nb_parties = mysql_num_rows($results);
$white = array();
$black = array();
$tab_players = array();
if( $nb_parties > 1)
{
while ($row = mysql_fetch_array($results))
{
$tab = array();
$white_id = $row['w_playerID'];
$white_joueur = $row['w_name'];
$black_id = $row['b_playerID'];
$black_joueur = $row['b_name'];
$white_avant = $row['w_brating'];
$white_apres = $row['w_arating'];
$black_avant = $row['b_brating'];
$black_apres = $row['b_arating'];
$resultat = $row['result'];
$date = $row['date'];
$tab[0] = $row['w_playerID'];
$tab[1] = $row['w_name'];
$tab[2] = $row['b_playerID'];
$tab[3] = $row['b_name'];
$tab[4] = $row['w_brating'];
$tab[5] = $row['w_arating'];
$tab[6] = $row['b_brating'];
$tab[7] = $row['b_arating'];
$tab[8] = $row['result'];
$tab[9] = $row['date'];
$data[] = $tab;
$white[] = $tab[0];
$black[] = $tab[2];
$tab_players[] = $tab[0];
$tab_players[] = $tab[2];
$str = $white_id ." " .$white_joueur ." " .$black_id ." " .$black_joueur ." " .$white_avant ." " .$white_apres ." " .$black_avant ." " .$black_apres ." " .$resultat ." " .$date ;
//echo $str ."<br>";
}
//echo "<pre>";
//print_r($data);
//echo "</pre>";
/* pas utile
//echo "<pre>";
//print_r($white);
//echo "</pre>";
//echo "<pre>";
//print_r($black);
//echo "</pre>";
//echo "<pre>";
//print_r($tab_players);
//echo "</pre>";
*/
$occurences_joueurs = array_count_values($tab_players);
//echo "<pre>";
//print_r($occurences_joueurs);
//echo "</pre>";
foreach($occurences_joueurs as $key=>$val)
{
// on recherche les joeurs qui ont disputés plusieurs parties le même jour
// un joueur a t-il joué plusieurs parties le même jour ???
if( $val > 1 )
{
//echo $key.'=>'.$val;
//echo "<br>";
//echo " ----- " .count($data);
$score = 0;
for ($i = 0; $i < count($data); $i++)
{
if( $data[$i][0] == $key )
{
$score = $score + $data[$i][5];
}
if( $data[$i][2] == $key )
{
$score = $score + $data[$i][7];
}
}
////// faire une moyenne
$moy = $score / count($data);
//echo " Moy " . $moy;
//echo "<br>";
}
}
}
/************/
for ($i = 0; $i < count($J1_elo_data); $i++)
{
$transformation = date('d-M-Y', $J1_elo_data[$i][0]);
$J1_elo_data[$i][0] = $transformation;
$J2_elo_data[$i][0] = $transformation;
}
/************/
$elo_combine = array();
for ($i = 0; $i < count($J1_elo_data); $i++)
{
$elo_combine[] = $J1_elo_data[$i];
$elo_combine[] = $J2_elo_data[$i];
}
$json = json_encode($elo_combine);
file_put_contents("elo_combine.json", $json);
echo $json;
}
/***************************************************************/
/*function findIdPlayer($joueur1,$joueur2)
{
//echo $joueur1 ." " .$joueur2;
//echo "<br><br>";
$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE w_name = '$joueur1' AND b_name = '$joueur2' "; // desc LIMIT 20";
//echo $sql;
$results = mysql_query($sql);
$nb_parties = mysql_num_rows($results);
if( $nb_parties != 0)
{
while ($row = mysql_fetch_array($results))
{
$id_J1 = $row["w_playerID"];
$id_J2 = $row["b_playerID"];
break;
}
}
else
{
$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE w_name = '$joueur2' AND b_name = '$joueur1' "; // desc LIMIT 20";
//echo $sql;
$results = mysql_query($sql);
$nb_parties = mysql_num_rows($results);
if( $nb_parties != 0)
{
while ($row = mysql_fetch_array($results))
{
$id_J2 = $row["w_playerID"];
$id_J1 = $row["b_playerID"];
break;
}
}
}
return array($id_J1 ,$id_J2 );
}
/***************************************************************/
/*function notUsedfindIdPlayer($joueur)
{
//$joueur = "Henrique";
//$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE w_name = '$joueur' "; //OR b_name = '$joueur' "; // desc LIMIT 20";
//$sql = "SELECT * FROM parties_new WHERE w_name = '$joueur' "; // OR b_name = '$joueur' "; // desc LIMIT 20";
$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE w_name = '$joueur' "; // OR b_name = '$joueur' "; // desc LIMIT 20";
//echo $sql;
$results = mysql_query($sql);
$nb_parties = mysql_num_rows($results);
//echo " ++++ " .$nb_parties;
if( $nb_parties != 0)
{
while ($row = mysql_fetch_array($results))
{
$result = $row["w_playerID"];
//echo " **** " .$result;
break;
}
}
else
{
//$sql = "SELECT * FROM parties_new WHERE b_name = '$joueur' "; // OR b_name = '$joueur' "; // desc LIMIT 20";
$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE b_name = '$joueur' "; // OR b_name = '$joueur' "; // desc LIMIT 20";
$nb_parties = mysql_num_rows($results);
if( $nb_parties != 0)
{
while ($row = mysql_fetch_array($results))
{
$result = $row["w_playerID"];
break;
}
}
else
{
//echo "Pas de partie disputées !.";
$result = NULL;
}
}
return $result;
}*/
/***************************************************************/
/*function extract_data($playerID)
{
//$sql = "SELECT * FROM parties_new WHERE w_playerID = '$playerID' OR b_playerID = '$playerID' ORDER by date asc ";
$sql = "SELECT * FROM " .$_SESSION['parties'] ." WHERE w_playerID = '$playerID' OR b_playerID = '$playerID' ORDER by date asc ";
//echo $sql;
//echo "<br><br>";
$graph_data = array();
$result = mysql_query($sql);
//$retid = mysql_query($sql);
//$id = 1;
while ($row = mysql_fetch_array($result))
{
$white = $row["w_playerID"];
$w_name=$row["w_name"];
$black = $row["b_playerID"];
$b_name=$row["b_name"];
$w_rating = $row["w_arating"];
$b_rating = $row["b_arating"];
$w_brating = $row["w_brating"];
$b_brating = $row["b_brating"];
$result=$row["result"];
//$date =$row["date"];
//$date=date("d F Y",$date);
//$date_convert = strftime('%d-%m-%Y',strtotime($date));
$timestamp = $row["date"];
$date= date("d F Y",$timestamp);
$date_convert = strftime('%d-%h-%Y',strtotime($date));
$diff_w = $w_rating - $w_brating;
$diff_b = $b_rating - $b_brating;
if($white==$playerID)
{
if ($result==1)
{
//$pipo =array( $timestamp, $date_convert , $w_rating);
$pipo = array("aaa"=>$timestamp,"bbb"=>$date_convert,"ccc"=>$w_rating);
}
if($result==2)
{
//$pipo =array($timestamp, $date_convert , $w_rating);
$pipo = array("aaa"=>$timestamp,"bbb"=>$date_convert,"ccc"=>$w_rating);
}
if ($result==3)
{
//$pipo =array( $timestamp, $date_convert , $w_rating);
$pipo = array("aaa"=>$timestamp,"bbb"=>$date_convert,"ccc"=>$w_rating);
}
}
if ($black==$playerID)
{
if($result==1)
{
//$pipo =array( $timestamp, $date_convert , $b_rating);
$pipo = array("aaa"=>$timestamp,"bbb"=>$date_convert,"ccc"=>$b_rating);
}
if ($result==2)
{
//$pipo =array( $timestamp, $date_convert , $b_rating);
$pipo = array("aaa"=>$timestamp,"bbb"=>$date_convert,"ccc"=>$b_rating);
}
if ($result==3)
{
//$pipo =array( $timestamp, $date_convert , $b_rating);
$pipo = array("aaa"=>$timestamp,"bbb"=>$date_convert,"ccc"=>$b_rating);
}
}
$graph_data[] = $pipo;
//$id = $id + 1;
}
return $graph_data;
}
/***************************************************************/
/*function interval($date1, $date2)
{
$array = array();
$variable1 = strtotime($date1);
$variable2 = strtotime($date2);
// 86400 sec = 24 hrs = 60*60*24 = 1 day
for ($currentDate = $variable1; $currentDate <= $variable2; $currentDate += (86400))
{
$store = date('Y-m-d', $currentDate);
$array[] = $store;
}
return $array;
}*/
/***************************************************************/
/*function date_formatted($date)
{
$pieces = explode("-", $date);
switch ($pieces[1])
{
case 'Jan':
$detected_month = "01";
break;
case 'Feb':
$detected_month = "02";
break;
case 'Mar':
$detected_month = "03";
break;
case 'Apr':
$detected_month = "04";
break;
case 'May':
$detected_month = "05";
break;
case 'Jun':
$detected_month = "06";
break;
case 'Jul':
$detected_month = "07";
break;
case 'Aug':
$detected_month = "08";
break;
case 'Sep':
$detected_month = "09";
break;
case 'Oct':
$detected_month = "10";
break;
case 'Nov':
$detected_month = "11";
break;
case 'Dec':
$detected_month = "12";
break;
}
$date_str = $pieces[2] ."-" .$detected_month ."-" .$pieces[0];
return $date_str;
} */
/***************************************************************/
echo "zoulou";
?>