Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
Bookmarks
/
CHESS_ON
:
compute_chart_elo_single.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php session_start(); include('database.php'); DB_connexion(); header('Content-Type: text/html; charset=utf-8'); //$playerID = "1"; $_SESSION['chessmaster'] = "clone_chessmaster_new"; $_SESSION['classement'] = "clone_classement_new"; $_SESSION['parties'] = "clone_parties_new"; $_SESSION['evolution'] = "clone_evolution_new"; $playerID = $_POST["id_joueur"]; //$playerID = "5"; $J1_data = extract_data($playerID); //echo "<pre>"; //print_r($J1_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>"; /**/ //echo " +++ " .$J1_start_date ." " .$J1_stop_date; $tab_timestamp = interval( date_formatted($J1_start_date), date_formatted($J1_stop_date)); //echo "<pre>"; //print_r($tab_timestamp); //echo "</pre>"; $J1_elo_data = array(); for ($i = 0; $i <= count($tab_timestamp)-1; $i++) { $timestamp = strtotime($tab_timestamp[$i]); $tmp =array( $timestamp, "val"); $J1_elo_data[] = $tmp; } // echo "<pre>"; // print_r($J1_elo_data); // echo "</pre>"; $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][1] = $J1_data[$j]["ccc"]; break; } } if( $find == 0) { $J1_elo_data[$i][1] = $J1_elo_data[$i-1][1]; } } 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; } // echo "<pre>"; // print_r($J1_elo_data); // echo "</pre>"; $json = json_encode($J1_elo_data); file_put_contents("elo_data.json", $json); echo $json; 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($retid)) { $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) { //$date1 = '01-10-2010'; //$date2 = '05-10-2010'; // Declare an empty array $array = array(); // Use strtotime function $variable1 = strtotime($date1); $variable2 = strtotime($date2); // Use for loop to store dates into array // 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; } ?>