problem with winddirection graph and mysqlweather.php

Forum for english speaking users
grug

Message par grug »

ok, it works now, but still the radargraph either plots a circle or nothing, depending on which data i select to display.
any hints on this one?
Avatar de l’utilisateur
jturlier
Membre
Messages : 3149
Inscription : mar. août 22, 2006 8:38 am
Localisation : 34410 Sérignan - Languedoc
Contact :

Message par jturlier »

Hi Grug
Is Wind direction in degrees ?
Jean

Station : VP2 Pro Console Vue + anémomètre à Ultra-sons
Logiciels : Cumulus 1.9.4 + Cumulus2SQL
Serveur local : Apache + MySQL +PHP
PC : W10
Support Audio : FR

http://meteoserignan.ddns.net
Image
"Aide-toi d'abord toi-même et les autres t'aideront ... peut-être"
grug

Message par grug »

yeah, in my db the winddata looks like "22.5" or "67.5" or "337.5"
grug

Message par grug »

forgot to say, the wind direction in the db seems to be rounded in 16 steps with 22.5 degrees each (0,22.5,45,67.5,.....337,5)
Avatar de l’utilisateur
jturlier
Membre
Messages : 3149
Inscription : mar. août 22, 2006 8:38 am
Localisation : 34410 Sérignan - Languedoc
Contact :

Message par jturlier »

I don't see any reason why it would not work. It is normal to have 16 steps of 22.5° because HeavyWeather gives directions from 0 to 16 and it's converted in the db loading to make it compatible with GraphWeather. In fact I should have never asked this question because I knew the answer. Excuse me Grug.
I think that now it's Antoine competencies which are needed ... Antoine your turn !
Jean

Station : VP2 Pro Console Vue + anémomètre à Ultra-sons
Logiciels : Cumulus 1.9.4 + Cumulus2SQL
Serveur local : Apache + MySQL +PHP
PC : W10
Support Audio : FR

http://meteoserignan.ddns.net
Image
"Aide-toi d'abord toi-même et les autres t'aideront ... peut-être"
Avatar de l’utilisateur
TiToine
Site Admin
Messages : 3356
Inscription : lun. mars 20, 2006 11:16 am
Localisation : Montréal
Contact :

Message par TiToine »

Could you make some screenshots of graph and database field (with values) ?
Grug
Nouveau membre
Messages : 2
Inscription : mar. déc. 18, 2007 7:18 pm

Message par Grug »

ok, here are some screenshots:
Image
Image
(copy image address for larger view)
And some code(which i didn't change):

Code : Tout sélectionner

$sql="SELECT `";
$sql.=$MYSQL_FIELD['absolute_pressure']."`,`";
$sql.=$MYSQL_FIELD['outdoor_humidity']."`,`";
$sql.=$MYSQL_FIELD['outdoor_temperature']."`,`";
$sql.=$MYSQL_FIELD['dew_point']."`,`";
$sql.=$MYSQL_FIELD['wind_chill']."`,`";
$sql.=$MYSQL_FIELD['wind_direction']."`,`";
$sql.=$MYSQL_FIELD['wind_speed']."`,`";
$sql.=$MYSQL_FIELD['total_rainfall']."`,`";
$sql.=$MYSQL_FIELD['timestamp']."`";
$sql.=" FROM ".$MYSQL_TABLE." WHERE ".$MYSQL_FIELD['timestamp']."<='".$StopDate."' AND ".$MYSQL_FIELD['timestamp'].">='".$StartDate."'";
$query=mysql_query($sql) or die ("MYSQL error : ".mysql_error());
mysql_close();
for ($i=0;$i<16;$i++) $count[$i]=0;
$i=0;
while ($list=mysql_fetch_array($query))
{	
	$y1data[$i]=$list[0];
	$y2data[$i]=$list[1];
	$y3data[$i]=$list[2];
	$y4data[$i]=$list[3];
	$y5data[$i]=$list[4];
	$count[round($list[5])]=$count[round($list[5])]+1;
	$y6data[$i]=$list[6];
	$y7data[$i]=$list[7];
	switch($MYSQL_TIMESTAMP)
	{
		case 0 :
			$timestamp[$i]=$list[8];
			break;
		default: case 1:
			sscanf($list[8],"%4d%2d%2d%2d%2d%2d",$a_year,$a_month,$a_day,$a_hours,$a_minutes,$a_seconds);
			$timestamp[$i]=intval(mktime($a_hours,$a_minutes,$a_seconds,$a_month,$a_day,$a_year,-1));
			break;
	}
	$i++;
}

$y1max=max($y1data);
$y2max=max($y2data);
$y3max=max($y3data);
$y4max=max($y4data);
$y5max=max($y5data);
$y6max=max($y6data);
$YMAX=max($y3max,$y4max,$y5max);

$y1min=min($y1data);
$y2min=min($y2data);
$y3min=min($y3data);
$y4min=min($y4data);
$y5min=min($y5data);
$YMIN=min($y3min,$y4min,$y5min);

$YMAX=round($YMAX+($YMAX-$YMIN)*0.1);
$YMIN=round($YMIN-($YMAX-$YMIN)*0.1);

$ticks_number=($HEIGHT1-$MARGIN_TOP1-$MARGIN_BOTTOM1)/20; //inter tick 40px
$YTICK_INTERVAL=round(($YMAX-$YMIN)/$ticks_number); 

for($i=0;$i<count($y2data);$i++)
{
	$y2data[$i]=$y2data[$i]*($YMAX-$YMIN)/100+$YMIN;
}


$total_rainfall=$y7data[count($y7data)-1]-$y7data[0];
for($i=0;$i<count($y7data)-1;$i++)
{
	$y7data[$i]=$y7data[$i+1]-$y7data[$i];
}
$y7data[count($y7data)-1]=$y7data[count($y7data)-2]; //last value


$STATS.="sql=".($timer->Pop()/1000)."s ";

.
.
.
.
.
// ----------------------------------------------------------------------
// - GRAPH3 : PREVAILING WIND
// ----------------------------------------------------------------------

// Reverse values
$new_count[0]=$count[0];
for ($i=1;$i<16;$i++)
{
	$new_count[$i]=$count[16-$i];
}


$graph3 = new RadarGraph($WIDTH3,$HEIGHT3,"auto");
$graph3->SetCenter(0.17,0.5);

$graph3->SetColor($BACKGROUND_COLOR);
$graph3->SetMargin($MARGIN_LEFT3,$MARGIN_RIGHT3,$MARGIN_TOP3,$MARGIN_BOTTOM3);
$graph3->title->SetFont(FF_FONT1,FS_NORMAL,11);
$graph3->title->Set("vorherrschende Windrichtung");
$graph3->title->SetAlign("left");
$graph3->axis->SetFont(FF_FONT1,FS_NORMAL,8);
$graph3->axis->title->SetFont(FF_FONT1,FS_NORMAL,8);
$graph3->SetFrame(true,'black',0);
$graph3->SetTitles(array("N","NN0","N0","0N0","0","0S0","S0","SS0","S","SSE","SE","ESE","E","ENE","NE","NNE","N"));
$graph3->grid->Show ();
$graph3->grid-> SetLineStyle( "solid");

$polar = new RadarPlot($new_count);
$polar->SetFillColor('blue@0.8');
$polar->SetColor('blue@0.6');
$graph3->Add($polar);
$graph3->AddText($minmax);
$graph3->AddText($db_infos);
$graph3->AddText($legend);

$handle3 = $graph3->Stroke(_IMG_HANDLER);

$STATS.="graph=".($timer->Pop()/1000)."s ";
Hope this helps;-)
Avatar de l’utilisateur
TiToine
Site Admin
Messages : 3356
Inscription : lun. mars 20, 2006 11:16 am
Localisation : Montréal
Contact :

Message par TiToine »

Hi,

This line is false :
$count[round($list[5])]=$count[round($list[5])]+1;
since we have a decoded wind direction.

You should try this :
$count[$list[5]/22.5]=$count[$list[5]/22.5]+1;

or this (exactly the same result but optimized) :
$count[$list[5]/22.5]++;

Antoine.
Grug
Nouveau membre
Messages : 2
Inscription : mar. déc. 18, 2007 7:18 pm

Message par Grug »

Hi Antoine, it works. Thank you so much.
Great work, your script!!!
Répondre