if (isset($_GET['timeframe']))
{
$timeframe = $_GET['timeframe'];
if (strcmp($timeframe,"day")==0) {
$query = "select concat(month(t),'/',day(t),' ',hour(t),case when minute(t) div 5 <=1 then '0' else '' end, minute(t) div 5 * 5) Datestamp, round(avg(depth),2) depth, round(case when degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end)))))<0 then degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) + 360 else degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) end,2) twd, round(avg(aws),2) aws,round(max(gust),2) gust from data where t > now() - interval 24 hour group by month(t), day(t), hour(t), minute(t) div 5 order by t asc;";
} else if (strcmp($timeframe,"week")==0) {
$query = "select concat(month(t),'/',day(t),' ',hour(t),'00') Datestamp, round(avg(depth),2) depth, round(case when degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end)))))<0 then degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) + 360 else degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) end,2) twd, round(avg(aws),2) aws,round(max(gust),2) gust from data where t > now() - interval 7 day group by month(t), day(t), hour(t) order by t asc;";
} else if (strcmp($timeframe,"12")==0) {
$query = "select concat(month(t),'/',day(t),' ',hour(t),'00') Datestamp, round(avg(depth),2) depth, round(case when degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end)))))<0 then degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) + 360 else degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) end,2) twd, round(avg(aws),2) aws,round(max(gust),2) gust from data where t > now() - interval 12 hour group by month(t), day(t), hour(t), minute(t) div 5 order by t asc;";
} else if (strcmp($timeframe,"48")==0) {
$query = "select concat(month(t),'/',day(t),' ',hour(t),'00') Datestamp, round(avg(depth),2) depth, round(case when degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end)))))<0 then degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) + 360 else degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) end,2) twd, round(avg(aws),2) aws,round(max(gust),2) gust from data where t > now() - interval 48 hour group by month(t), day(t), hour(t), minute(t) div 5 order by t asc;";
} else {
$query = "select concat(month(t),'/',day(t),' ',hour(t),'00') Datestamp, round(avg(depth),2) depth, round(case when degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end)))))<0 then degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) + 360 else degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) end,2) twd, round(avg(aws),2) aws,round(max(gust),2) gust from data group by month(t), day(t), hour(t) order by t asc;";
}
} else {
$query = "select concat(month(t),'/',day(t),' ',hour(t),'00') Datestamp, round(avg(depth),2) depth, round(case when degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end)))))<0 then degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) + 360 else degrees(atan2(sum(sin(radians(case when twd >= 360 then twd - 360 else twd end))), sum(cos(radians(case when twd >= 360 then twd - 360 else twd end))))) end,2) twd, round(avg(aws),2) aws,round(max(gust),2) gust from data group by month(t), day(t), hour(t) order by t asc;";
};
//print $query;
$datars = $db2->query($query);
$row = $datars->fetch_assoc();
$data = " data: [".$row['twd'];
$aws = " data: [".$row['aws'];
$gust = " data: [".$row['gust'];
$depth = " data: [".$row['depth'];
$label = " labels: [";
while($row = $datars->fetch_assoc()) {
$data .= ",".$row['twd'];
$aws .= ",".$row['aws'];
$gust .= ",".$row['gust'];
$depth .= ",".$row['depth'];
$label = $label . ",\"".$row['Datestamp']."\"";
}
$label .= "],\r\n";
$data .= "],\r\n";
$aws .= "],\r\n";
$gust .= "],\r\n";
$depth .= "],\r\n";
?>
Depth in feet on left, wind speed in knots on right.
Wind angle is 0-360 degrees starting at 0 on the bottom.
Click on the legend up top to show/hide data sets
Last 12 hours Last 24 hours
Last 48 hours Last 7 days
All time
Home