1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__avion-poeme/gestion/stats.php
2021-10-30 12:37:27 +02:00

95 lines
2.7 KiB
PHP

<?php
require_once '../session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'log.php';
$db = new db();
$db->open();
function totaltotal() //nombre d'avions poèmes créés depuis le début
{
global $db;
$query = "SHOW TABLE STATUS LIKE 'avionpoeme'";
$db->query($query);
$result = $db->result->fetch_assoc();
return $result['Auto_increment']-1;
}
function total() //nombre d'avions poèmes présents dans la base
{
global $db;
$query = "SELECT COUNT(*) as nAvion FROM avionpoeme";
$db->query($query);
$result = $db->result->fetch_assoc();
return $result["nAvion"];
}
function totalenvol() //nombre d'avions poèmes en vol
{
global $db;
$query = "SELECT COUNT(*) as n FROM avionpoeme WHERE atteri!=1";
$db->query($query);
$result = $db->result->fetch_assoc();
return $result["n"];
}
function alea($nAvionEnvoye)
{
global $db;
$query = "SELECT DISTINCT deliveryMethod FROM avionpoeme";
$db->query($query);
$result = $db->result->fetch_all(MYSQLI_ASSOC);
//var_dump($result);
foreach ( $result as $method )
{
$query = "SELECT COUNT(*) as nAvion FROM avionpoeme WHERE deliveryMethod='" . $method["deliveryMethod"] . "'";
$db->query($query);
$result = $db->result->fetch_assoc();
echo "Méthode => " . $method["deliveryMethod"] . " nombre d'avion poèmes => " . $result["nAvion"] . " => " . round($result["nAvion"]/$nAvionEnvoye*100,2) . "%" . EOLH;
}
}
function anonymous() //nombre d'avions poèmes envoyés anonymement
{
global $db;
$query = "SELECT COUNT(*) as n FROM avionpoeme WHERE expeknown='0'";
$db->query($query);
$result = $db->result->fetch_assoc();
return $result["n"];
}
function deleted()
{
global $db;
$query = "SELECT COUNT(*) as n FROM avionpoeme WHERE public='2'";
$db->query($query);
$result = $db->result->fetch_assoc();
return $result["n"];
}
$nAvionEnvoye = totaltotal();
if ($nAvionEnvoye == 0)
{
echo "Aucun avion-poème envoyé pour l'instant";
}else
{
echo "Nombre total d'avions-poème : " . $nAvionEnvoye . EOLH;
$total = total();
$avionSupp = $nAvionEnvoye-$total;
echo "Nombre d'avion supprimés : " . $avionSupp . " => " . round($avionSupp/$nAvionEnvoye*100,2) . "%" . EOLH;
$nAvionenvol = totalenvol();
echo "Nombre d'avions-poème en vol : " . $nAvionenvol . " => " . round($nAvionenvol/$nAvionEnvoye*100,2) . "%" . EOLH;
$anonymous = anonymous();
echo "Nombre d'envois anonymes : " . $anonymous . " => " . round($anonymous/$nAvionEnvoye*100,2) . "%" . EOLH;
$deleted = deleted();
echo "Nombre d'avions anonymisés(effacés) : " . $deleted . " => " . round($deleted/$nAvionEnvoye*100,2) . "%" . EOLH;
alea($nAvionEnvoye);
}
$db->close();