1
0

- changed webserver to apiserver

- added webserver
- a lot of debugging
- install shell script
This commit is contained in:
2022-04-07 01:44:17 +02:00
parent 0d35b1ff3f
commit f8fc3f63ec
28 changed files with 463 additions and 223 deletions

View File

@@ -8,21 +8,32 @@
function displayStats($socket, $argList)
{
global $indexFriendlyNames;
global $indexFriendlyNames, $mohaDB;
logger(INFO, "Function displayStats", __FILE__ . ":" . __LINE__);
// Validation of the dates
if (validateDate($argList["startDate"]) && validateDate($argList["finalDate"]))
{
$query = "SELECT date, value FROM logs WHERE device='" . indexFriendlyNames[$argList->device] . "' AND property='" . $$argList["property"] . "' AND '" . $argList["startDate"] . ">= date AND '" . $argList["finalDate"] . "' <= date";
if(!$this->result = $this->query($query))
if (!array_key_exists($argList["fn"], $indexFriendlyNames))
{
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
htmlSend($socket, $argList["fn"] . _(" not found: Verify the syntax"));
}elseif(!array_key_exists($argList["property"], $indexFriendlyNames[$argList["fn"]]->properties))
{
htmlSend($socket, $argList["property"] . _(" not found : Verify the syntax"));
}else
{
$query = "SELECT date, value FROM logs WHERE device='" . $indexFriendlyNames[$argList["fn"]]->ieeeAddress . "' AND property='" . $argList["property"] . "' AND '" . $argList["startDate"] . "'>= date AND '" . $argList["finalDate"] . "' <= date ORDER BY date";
logger(DEBUG, _("query : ") . $query, __FILE__ . ":" . __LINE__);
if(!($mohaDB->result = $mohaDB->query($query)))
{
logger(ERROR, _("mysql query error: ") . $mohaDB->error, __FILE__ . ":" . __LINE__);
}
$datas = $mohaDB->result->fetch_all(MYSQLI_ASSOC);
htmlSend($socket, diagramDisplay($datas));
}
$datas = $this->result->fetch_all(MYSQLI_ASSOC);
diagramDisplay($datas);
}else
{
htmlSend($socket, _("Dates are not of the form: YYYY-MM-DD"));
htmlSend($socket, _("Dates are not of the form: YYYY-MM-DD 00:00:00"));
}
}
@@ -39,8 +50,11 @@ function diagramDisplay($datas)
global $months;
$ndata = count($datas);
$min = min($datas);
$max = max($datas);
$i = $ndata;
$tmp = min($datas);
$min = $tmp["value"];
$tmp = max($datas);
$max = $tmp["value"];
//Type mime de l'image
//Chemin vers le police à utiliser
$font_file = '/usr/share/fonts/TTF/dejavu/DejaVuSans.ttf';
@@ -64,6 +78,7 @@ function diagramDisplay($datas)
//Tracer l'axe des ordonnées
imageline($courbe, 50, $hauteur - $absis, 50, 20, $noir);
//Decaler 10px vers le haut le si le minimum est différent de 0
$a = 0;
if($min != 0)
{
$absis += 10;
@@ -94,14 +109,17 @@ function diagramDisplay($datas)
$j = -1;
$pasX = 90;
//Parcourir le tableau pour le traçage de la diagramme
foreach ($datas as $mois => $quantite)
foreach ($datas as $row)
{
$date = $row["date"];
$quantite = $row["value"];
//calculer la hateur du point par rapport à sa valeur
$y = ($hauteur) - (($quantite - $min) * ($echelleY / $py)) - $absis;
//dessiner le point
imagefilledellipse($courbe, $pasX, $y, 6, 6, $rouge);
//Afficher le mois en français avec une inclinaison de 315°
imagefttext($courbe, 10, 315, $pasX, $hauteur - $absis + 20, $noir, $font_file, $months[$mois-1]);
printf("pasx = %d hauteur = %d absis = %d noir= %d", $pasX, $hauteur, $absis, $noir);
imagefttext($courbe, 10, 315, $pasX, $hauteur - $absis + 20, $noir, $font_file, $date);
//Tacer une ligne veticale de l'axe de l'abscisse vers le point
imageline($courbe, $pasX, $hauteur - $absis + $a, $pasX, $y, $noir);
if($j!==-1)
@@ -118,8 +136,12 @@ function diagramDisplay($datas)
$pasX +=$echelleX;
}
//Envoyer le flux de l'image
imagepng($courbe);
//Desallouer le memoire utiliser par l'image
//header('Content-Type: image/png');
$file = tempnam("php://temp", "moha-");
imagepng($courbe,$file);
return '<img src="/' . basename($file) . '">';
//Desallouer la mémoire utiliser par l'image
imagedestroy($courbe);
}
?>