Subversion Repositories Sites.obs-saisons.fr

Rev

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

<?
$jpgraph = "../bibliotheque/jpgraph";
include ("$jpgraph/jpgraph.php");
include ("$jpgraph/jpgraph_line.php");

include ("../connect.php");

$evenement_id = $_GET['ev'];
$commune_id = $_GET['com'];
$espece_id=$_GET['esp'];

$req_dates = mysql_query("SELECT DATE_FORMAT(MESURE_DATE,'%j'), 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)) {
        
  $jourjulien_crt = $obs[0];
  $annee_crt = $obs[1];
  if ($obs[1]!=$lastannee) {
    //on calcule la moyenne pour l'année 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] = $jourjulien_crt;
  } else {
    $nbdates++;
    $dates[$lastannee] += $jourjulien_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 - $dateMin;
}

$dateMin = cal_from_jd($dateMin, CAL_GREGORIAN);

// Create the graph. These two calls are always required
$graph = new Graph();//600, 800,"auto");    
$graph->SetScale( "intint");


//$annees = array('2000','2005','2010');
$graph->xaxis->SetTickLabels($annees); 
//$graph->yaxis->SetTickLabels($tickLabels); 

// Create the linear plot
$lineplot =new LinePlot($jours);
$lineplot ->SetColor("darkgreen");

// Add the plot to the graph
$graph->Add( $lineplot);

//Un peu de forme
$graph->SetBackgroundGradient('#ffcc55','#ffeb55',3,BGRAD_FRAME);
$graph->title->Set("Dates moyennes d'observation");
$graph->img->SetMargin(60,20,20,40);
$graph->xaxis->title->Set("Année");
$graph->yaxis->title->Set("Jours partir du ".$dateMin['day']."/".$dateMin['month']);
 $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(); 

?>