Subversion Repositories Sites.obs-saisons.fr

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 1

/obs_saisons/SPIP-v1-8-3/modules/graphiques/gen_graphbon.php
New file
0,0 → 1,138
<?
$jpgraph = "/usr/local/lib/php/jpgraph-1.17";
//$jpgraph = "/home/fiastre/Desktop/jpgraph-2.1.2/src";
include ("$jpgraph/jpgraph.php");
include ("$jpgraph/jpgraph_line.php");
//include ("$jpgraph/jpgraph_utils.inc");
/*echo "{".$_SESSION['observation']['espece_id'];
echo $_SESSION['observation']['evenement_id'];
echo $_SESSION['observation']['commune_id']."}";
*/
 
// Some data
//$ydata = array(11,3, 8,12,5 ,1,9, 13,5,7 );
include ("../connect.php");
 
$evenement_id = $_GET['ev'];
$commune_id = $_GET['com'];
$espece_id=$_GET['esp'];
 
$req_dates = mysql_query("SELECT DATE_FORMAT(MESURE_DATE,'%d%m'), DATE_FORMAT(MESURE_DATE,'%Y') as ANNEE FROM MESURE,SEQUENCE".
" where SEQUENCE.SEQUENCE_ID=MESURE.SEQUENCE_ID and".
" EVENEMENT_ID=$evenement_id and ESPECE_ID=$espece_id".
" AND MESURE_DATE!='0000-00-00'".
" and STATION_ID=$commune_id".
" order by ANNEE");
$dates = array();
$lastannee = 0;
$nbdates = 1;
while ($obs = mysql_fetch_row($req_dates)) {
$jour_crt = substr($obs[0],0,2);
$mois_crt = substr($obs[0],2,2);
$annee_crt = $obs[1];
if ($obs[1]!=$lastannee) {
//on calcule la moyenne pour la commune précédente :
if ($lastannee != 0)
$dates[$lastannee] = $dates[$lastannee]/$nbdates;
//on initialise les variables pour la nouvelle commune
$nbdates = 1;
$lastannee=$obs[1];
$dates[$lastannee] = mktime(0,0,0,$mois_crt,$jour_crt);
} else {
$nbdates++;
$dates[$lastannee] += mktime(0,0,0,$mois_crt,$jour_crt);
}
}
$dates[$lastannee] = $dates[$lastannee]/$nbdates;
 
if (sizeof($dates)>0) {
$dateMin = min ($dates);
$dateMax = max ($dates);
$nbDates = sizeof ($dates);
}
else {
$erreurs[] = "Il n'y a pas encore de données cette année pour cette observation.";
}
 
$jours = array();
$annees = array();
 
foreach ($dates as $annee => $date) {
$annees[] = "$annee";
$jours[] = $date;
 
}
 
//on définit les labels pour les dates
$labelsjours = array();
$nbDemiMois = 0;
while ($dateMin + $nbDemiMois*1209600 <= $dateMax) {
$labelsjours[$nbDemiMois] = date('d/m',$dateMin+$nbDemiMois*1209600);
$nbDemiMois++;
}
 
/*foreach ($labelsjours as $l)
echo $l;
 
/*list($tickPositions,$minTickPositions) =
DateScaleUtils::GetTicks($jours);
*/
$mois = $gDateLocale->GetShortMonth();
//on tente de trouver l'indice du mois de la date min
$moisMin = date('m',$dateMin);
$derniersMois = array_slice($mois,$moisMin-1);
//on prend le tableau à l'envers : dec, nov, oct, sept etc.
//l'indice où couper est : la taille du tableau moins l'indice du mois
//on réinverse le tableau et obtient au final les premiers mois
$premiersMois = array_reverse(array_slice(
array_reverse($mois),sizeof($mois)-$moisMin));
$tickLabels = array_merge($derniersMois,$premiersMois);
 
/*$tickPositions = array();
$tickLabels = array();
$tickPositions[0] = 0;
$tickLabels[0] = $dateMin;
foreach ($dates as $date) {
$tickPositions[] = $date;
$tickLabels[] = date('d/m',$date);
}*/
 
/*$annees = array('2006','2007');
$jours = array(1508,3008);
for ($i=0; $i<sizeof($annees); $i++) {
echo "année ".$annees[$i]." : ".$jours[$i].":".is_numeric($jours[$i]).",";
}
*/
 
 
// Create the graph. These two calls are always required
$graph = new Graph(600, 800,"auto");
$graph->SetScale( "textint",$dateMin,$dateMax);
$graph->yscale->ticks->Set(1209600,86400);
 
 
//$annees = array('2000','2005','2010');
$graph->xaxis->SetTickLabels($annees);
$graph->yaxis->SetTickLabels($tickLabels);
 
// Create the linear plot
$lineplot =new LinePlot($jours);
$lineplot ->SetColor("blue");
 
// Add the plot to the graph
$graph->Add( $lineplot);
 
//Un peu de forme
$graph->title->Set("Date de floraison du pommier");
$graph->img->SetMargin(80,20,20,40);
$graph->xaxis->title->Set("Année");
//$graph->yaxis->title->Set("Date observée");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$lineplot->mark->SetType(MARK_SQUARE);
 
// Display the graph
$graph->Stroke();
 
?>