Subversion Repositories Sites.obs-saisons.fr

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 aurelien 1
<?
2
$jpgraph = "../bibliotheque/jpgraph";
3
include ("$jpgraph/jpgraph.php");
4
include ("$jpgraph/jpgraph_line.php");
5
 
6
include ("../connect.php");
7
 
8
$evenement_id = $_GET['ev'];
9
$commune_id = $_GET['com'];
10
$espece_id=$_GET['esp'];
11
 
12
$req_dates = mysql_query("SELECT DATE_FORMAT(MESURE_DATE,'%j'), DATE_FORMAT(MESURE_DATE,'%Y') as ANNEE FROM MESURE,SEQUENCE".
13
	" where SEQUENCE.SEQUENCE_ID=MESURE.SEQUENCE_ID and".
14
	" EVENEMENT_ID=$evenement_id and ESPECE_ID=$espece_id".
15
	" AND MESURE_DATE!='0000-00-00'".
16
	" and STATION_ID=$commune_id".
17
	" order by ANNEE");
18
 
19
$dates = array();
20
$lastannee = 0;
21
$nbdates = 1;
22
while ($obs = mysql_fetch_row($req_dates)) {
23
 
24
  $jourjulien_crt = $obs[0];
25
  $annee_crt = $obs[1];
26
  if ($obs[1]!=$lastannee) {
27
    //on calcule la moyenne pour l'année précédente :
28
    if ($lastannee != 0)
29
      $dates[$lastannee] = $dates[$lastannee]/$nbdates;
30
    //on initialise les variables pour la nouvelle commune
31
    $nbdates = 1;
32
    $lastannee=$obs[1];
33
    $dates[$lastannee] = $jourjulien_crt;
34
  } else {
35
    $nbdates++;
36
    $dates[$lastannee] += $jourjulien_crt;
37
  }
38
}
39
$dates[$lastannee] = $dates[$lastannee]/$nbdates;
40
 
41
if (sizeof($dates)>0) {
42
  $dateMin = min ($dates);
43
  $dateMax = max ($dates);
44
  $nbDates = sizeof ($dates);
45
}
46
else {
47
  $erreurs[] = "Il n'y a pas encore de données cette année pour cette observation.";
48
}
49
 
50
$jours = array();
51
$annees = array();
52
 
53
foreach ($dates as $annee => $date) {
54
  $annees[] = "$annee";
55
  $jours[] = $date - $dateMin;
56
}
57
 
58
$dateMin = cal_from_jd($dateMin, CAL_GREGORIAN);
59
 
60
// Create the graph. These two calls are always required
61
$graph = new Graph();//600, 800,"auto");
62
$graph->SetScale( "intint");
63
 
64
 
65
//$annees = array('2000','2005','2010');
66
$graph->xaxis->SetTickLabels($annees);
67
//$graph->yaxis->SetTickLabels($tickLabels);
68
 
69
// Create the linear plot
70
$lineplot =new LinePlot($jours);
71
$lineplot ->SetColor("darkgreen");
72
 
73
// Add the plot to the graph
74
$graph->Add( $lineplot);
75
 
76
//Un peu de forme
77
$graph->SetBackgroundGradient('#ffcc55','#ffeb55',3,BGRAD_FRAME);
78
$graph->title->Set("Dates moyennes d'observation");
79
$graph->img->SetMargin(60,20,20,40);
80
$graph->xaxis->title->Set("Année");
81
$graph->yaxis->title->Set("Jours partir du ".$dateMin['day']."/".$dateMin['month']);
82
 $graph->title->SetFont(FF_FONT1,FS_BOLD);
83
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
84
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
85
 $lineplot->mark->SetType(MARK_SQUARE);
86
 
87
// Display the graph
88
$graph->Stroke();
89
 
90
?>