<?
include ("connection.php");
include ("frames_header.php");
?>

<?
$version=$_GET["version"];

print "<strong><u>ANISEED stats <b>VERSION $version.0</b></u></strong>";
print "<br>";

//Nombre total de connexions entre 2 jours
$requete2="SELECT \"DATE\" from \"LOG\" where \"VERSION\"='$version' order by \"DATE\" asc";
$stmt2=pg_query($c,$requete2);
$row2=pg_fetch_array($stmt2);
$datedebut=$row2["DATE"];
for ($i=1;$i<pg_num_rows($stmt2);$i++) $row2=pg_fetch_array($stmt2);
$datefin=$row2["DATE"];
print "<em>Number of connections ( between $datedebut and $datefin )</em> :&nbsp;&nbsp;";
$requete="SELECT count(*) as \"COUNT\" from \"LOG\" where \"VERSION\"='$version'";
$stmt=pg_query($c,$requete);
while ($row=pg_fetch_array($stmt))
{
print "<strong>".$row["COUNT"]."</strong><bR>";
$totalcon=$row["COUNT"];
}
print "<hr>";

//Nombre de connexions par jour
print "<em><u>Connections by days</u></em><br>";
//pour le graphique
$conday="";
$requete="select count(\"DATE\") as score, \"DATE\" from \"LOG\" where  \"VERSION\"='$version' group by \"DATE\" order by \"DATE\",score DESC;";
$stmt=pg_query($c,$requete);
while ($row=pg_fetch_array($stmt))
{
$conday.=$row["DATE"]."@".$row["score"]."!";
print "<b>".$row["DATE"]."</b> : <b>".$row["score"]."</b> connections <br>";
}
print "<hr>";

//Nombre de connexions par pays
print "<em><u>Connections by countries</u></em><br>";
$requete="SELECT count(\"COUNTRY\") as score, \"COUNTRY\" from \"LOG\" where  \"VERSION\"='$version' group by \"COUNTRY\" order by score desc";
$stmt=pg_query($c,$requete);
$i=0;
$concoun="";
while ($row=pg_fetch_array($stmt))
{
$concoun.=$row["COUNTRY"]."@".$row["score"]."!";
if ($i==0) print "<img width=30 border=0 src=\"pictures/flags/".$row["COUNTRY"].".gif\"> &nbsp;<font color=\"cyan\"><em>".$row["COUNTRY"]."</em> - <strong>".$row["score"]."</strong> connections <br></font>";
else print "<img width=30 border=0 src=\"pictures/flags/".$row["COUNTRY"].".gif\"> &nbsp;<em>".$row["COUNTRY"]."</em> - <strong>".$row["score"]."</strong> connections <br>";
$i++;
}
print "<hr>";

//Pic de connexion
print "<em>Connection peak</em> : ";
$requete="select count(\"DATE\") as score,\"DATE\" from \"LOG\" where  \"VERSION\"='$version' group by \"DATE\" order by score DESC;";
$stmt=pg_query($c,$requete);
if ($row=pg_fetch_array($stmt))
{
print "<b>".$row["DATE"]."</b> with <b>".$row["score"]."</b> connections <br>";
}
print "<hr>";

//Record de connexion par IP
print "<em>Peak by IP</em> : ";
$requete="select count(\"IP\") as score,\"IP\",\"COUNTRY\" from \"LOG\" where  \"VERSION\"='$version' group by \"IP\",\"COUNTRY\" order by score desc";
$stmt=pg_query($c,$requete);
if ($row=pg_fetch_array($stmt))
{
print "<b>".$row["IP"]."</b> ( from <em>".$row["COUNTRY"]."</em> ) with <b>".$row["score"]."</b> connections <br>";
}
print "<hr>";


print "<strong>Connection by days</strong><br>";



$requete="select count(\"DATE\") as score,\"DATE\" from \"LOG\" where  \"VERSION\"='$version' group by \"DATE\" order by score DESC;";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$maxcon=$row["score"];


$requete="select count(distinct(\"DATE\")) as score2 from \"LOG\" where  \"VERSION\"='$version'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$day=$row["score2"];

//print "$conday";

//print ">".$day." ".$maxcon."<";

$requete="select avg(\"COMPTE\") as \"AVG\" from (select count(\"IP\") as \"COMPTE\" from \"LOG\" where  \"VERSION\"='$version' group by \"DATE\") as foo ";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$avg=$row["AVG"];

print "<img src=\"logpng.php?day=$day&maxcon=$maxcon&conday=$conday&avg=$avg\" />";



print "<br><br><b>Mean connection</b>: <em>".round($avg)."</em><br>";

/*print "<img src=\"logpng2.php?day=$day&maxcon=$maxcon&conday=$conday\" />";*/
print "<br><br><b>Connection by country</b><br>";
print "<img src=\"logpng3.php?maxcon=$totalcon&concoun=$concoun\" />";

print "<hr>";
/*
print "<u>STAT SUR LES OUTILS</u><br>";
$requete="select distinct \"TOOL\" from \"LOG_TOOL\"";
$stmt=pg_query($c,$requete);
while ($row=pg_fetch_array($stmt))
{
print "Analyzed TOOL:".$row["TOOL"]."<br>";
$requete2="select \"COMMENTS\" from \"LOG_TOOL\" where \"TOOL\"='".$row["TOOL"]."'";
$stmt2=pg_query($c,$requete2);
$count=0;
while ($row2=pg_fetch_array($stmt2))
	{
	print ($count++)."- COMMENTS:<b>".$row2["COMMENTS"]."</b><br>";
	}
print "<br>";
}
*/




?>

<?
include ("frames_footer.php");
?>