1 |
aurelien |
1 |
<?
|
|
|
2 |
$jpgraph = "/usr/local/lib/php/jpgraph-1.17";
|
|
|
3 |
//$jpgraph = "/home/fiastre/Desktop/jpgraph-2.1.2/src";
|
|
|
4 |
include ("$jpgraph/jpgraph.php");
|
|
|
5 |
include ("$jpgraph/jpgraph_line.php");
|
|
|
6 |
//include ("$jpgraph/jpgraph_utils.inc");
|
|
|
7 |
/*echo "{".$_SESSION['observation']['espece_id'];
|
|
|
8 |
echo $_SESSION['observation']['evenement_id'];
|
|
|
9 |
echo $_SESSION['observation']['commune_id']."}";
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
// Some data
|
|
|
13 |
//$ydata = array(11,3, 8,12,5 ,1,9, 13,5,7 );
|
|
|
14 |
include ("../connect.php");
|
|
|
15 |
|
|
|
16 |
$evenement_id = $_GET['ev'];
|
|
|
17 |
$commune_id = $_GET['com'];
|
|
|
18 |
$espece_id=$_GET['esp'];
|
|
|
19 |
|
|
|
20 |
$req_dates = mysql_query("SELECT DATE_FORMAT(MESURE_DATE,'%d%m'), DATE_FORMAT(MESURE_DATE,'%Y') as ANNEE FROM MESURE,SEQUENCE".
|
|
|
21 |
" where SEQUENCE.SEQUENCE_ID=MESURE.SEQUENCE_ID and".
|
|
|
22 |
" EVENEMENT_ID=$evenement_id and ESPECE_ID=$espece_id".
|
|
|
23 |
" AND MESURE_DATE!='0000-00-00'".
|
|
|
24 |
" and STATION_ID=$commune_id".
|
|
|
25 |
" order by ANNEE");
|
|
|
26 |
$dates = array();
|
|
|
27 |
$lastannee = 0;
|
|
|
28 |
$nbdates = 1;
|
|
|
29 |
while ($obs = mysql_fetch_row($req_dates)) {
|
|
|
30 |
$jour_crt = substr($obs[0],0,2);
|
|
|
31 |
$mois_crt = substr($obs[0],2,2);
|
|
|
32 |
$annee_crt = $obs[1];
|
|
|
33 |
if ($obs[1]!=$lastannee) {
|
|
|
34 |
//on calcule la moyenne pour la commune précédente :
|
|
|
35 |
if ($lastannee != 0)
|
|
|
36 |
$dates[$lastannee] = $dates[$lastannee]/$nbdates;
|
|
|
37 |
//on initialise les variables pour la nouvelle commune
|
|
|
38 |
$nbdates = 1;
|
|
|
39 |
$lastannee=$obs[1];
|
|
|
40 |
$dates[$lastannee] = mktime(0,0,0,$mois_crt,$jour_crt);
|
|
|
41 |
} else {
|
|
|
42 |
$nbdates++;
|
|
|
43 |
$dates[$lastannee] += mktime(0,0,0,$mois_crt,$jour_crt);
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
$dates[$lastannee] = $dates[$lastannee]/$nbdates;
|
|
|
47 |
|
|
|
48 |
if (sizeof($dates)>0) {
|
|
|
49 |
$dateMin = min ($dates);
|
|
|
50 |
$dateMax = max ($dates);
|
|
|
51 |
$nbDates = sizeof ($dates);
|
|
|
52 |
}
|
|
|
53 |
else {
|
|
|
54 |
$erreurs[] = "Il n'y a pas encore de données cette année pour cette observation.";
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
$jours = array();
|
|
|
58 |
$annees = array();
|
|
|
59 |
|
|
|
60 |
foreach ($dates as $annee => $date) {
|
|
|
61 |
$annees[] = "$annee";
|
|
|
62 |
$jours[] = $date;
|
|
|
63 |
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
//on définit les labels pour les dates
|
|
|
67 |
$labelsjours = array();
|
|
|
68 |
$nbDemiMois = 0;
|
|
|
69 |
while ($dateMin + $nbDemiMois*1209600 <= $dateMax) {
|
|
|
70 |
$labelsjours[$nbDemiMois] = date('d/m',$dateMin+$nbDemiMois*1209600);
|
|
|
71 |
$nbDemiMois++;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/*foreach ($labelsjours as $l)
|
|
|
75 |
echo $l;
|
|
|
76 |
|
|
|
77 |
/*list($tickPositions,$minTickPositions) =
|
|
|
78 |
DateScaleUtils::GetTicks($jours);
|
|
|
79 |
*/
|
|
|
80 |
$mois = $gDateLocale->GetShortMonth();
|
|
|
81 |
//on tente de trouver l'indice du mois de la date min
|
|
|
82 |
$moisMin = date('m',$dateMin);
|
|
|
83 |
$derniersMois = array_slice($mois,$moisMin-1);
|
|
|
84 |
//on prend le tableau à l'envers : dec, nov, oct, sept etc.
|
|
|
85 |
//l'indice où couper est : la taille du tableau moins l'indice du mois
|
|
|
86 |
//on réinverse le tableau et obtient au final les premiers mois
|
|
|
87 |
$premiersMois = array_reverse(array_slice(
|
|
|
88 |
array_reverse($mois),sizeof($mois)-$moisMin));
|
|
|
89 |
$tickLabels = array_merge($derniersMois,$premiersMois);
|
|
|
90 |
|
|
|
91 |
/*$tickPositions = array();
|
|
|
92 |
$tickLabels = array();
|
|
|
93 |
$tickPositions[0] = 0;
|
|
|
94 |
$tickLabels[0] = $dateMin;
|
|
|
95 |
foreach ($dates as $date) {
|
|
|
96 |
$tickPositions[] = $date;
|
|
|
97 |
$tickLabels[] = date('d/m',$date);
|
|
|
98 |
}*/
|
|
|
99 |
|
|
|
100 |
/*$annees = array('2006','2007');
|
|
|
101 |
$jours = array(1508,3008);
|
|
|
102 |
for ($i=0; $i<sizeof($annees); $i++) {
|
|
|
103 |
echo "année ".$annees[$i]." : ".$jours[$i].":".is_numeric($jours[$i]).",";
|
|
|
104 |
}
|
|
|
105 |
*/
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
// Create the graph. These two calls are always required
|
|
|
109 |
$graph = new Graph(600, 800,"auto");
|
|
|
110 |
$graph->SetScale( "textint",$dateMin,$dateMax);
|
|
|
111 |
$graph->yscale->ticks->Set(1209600,86400);
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
//$annees = array('2000','2005','2010');
|
|
|
115 |
$graph->xaxis->SetTickLabels($annees);
|
|
|
116 |
$graph->yaxis->SetTickLabels($tickLabels);
|
|
|
117 |
|
|
|
118 |
// Create the linear plot
|
|
|
119 |
$lineplot =new LinePlot($jours);
|
|
|
120 |
$lineplot ->SetColor("blue");
|
|
|
121 |
|
|
|
122 |
// Add the plot to the graph
|
|
|
123 |
$graph->Add( $lineplot);
|
|
|
124 |
|
|
|
125 |
//Un peu de forme
|
|
|
126 |
$graph->title->Set("Date de floraison du pommier");
|
|
|
127 |
$graph->img->SetMargin(80,20,20,40);
|
|
|
128 |
$graph->xaxis->title->Set("Année");
|
|
|
129 |
//$graph->yaxis->title->Set("Date observée");
|
|
|
130 |
$graph->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
131 |
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
132 |
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
133 |
$lineplot->mark->SetType(MARK_SQUARE);
|
|
|
134 |
|
|
|
135 |
// Display the graph
|
|
|
136 |
$graph->Stroke();
|
|
|
137 |
|
|
|
138 |
?>
|