X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/3a48d89e76fd2ab87dabf08632474c529cf77ad4..e4e1557426f8e5ca10ca616140528939d86426cd:/web/image_minmax.php?ds=inline diff --git a/web/image_minmax.php b/web/image_minmax.php index a0a6326..3736221 100644 --- a/web/image_minmax.php +++ b/web/image_minmax.php @@ -16,6 +16,15 @@ if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_sche } +$supported = imagetypes(); +if( $supported & IMG_PNG ) $img_format="png"; +elseif( $supported & IMG_GIF ) $img_format="gif"; +elseif( $supported & IMG_JPG ) $img_format="jpeg"; +elseif( $supported & IMG_WBMP ) $img_format="wbmp"; +elseif( $supported & IMG_XPM ) $img_format="xpm"; + +$cachefilename = NULL; + $db -> exec('SET CHARACTER SET utf8'); $type = $_REQUEST['type']; @@ -78,7 +87,15 @@ if ($type and $param) { if ($month==13) { $next_year++; - $month=1; + $next_month=1; + + } + + $curr = date("Ym"); + + if ($curr>$next_year.$next_month) { + + $cachefilename='meteo.month.'.$sensor.'.'.$param.'.'.$year.'-'.$month.'.'.$img_format; } @@ -86,19 +103,20 @@ if ($type and $param) { ' select x, - unitconv(min(value),'.$from_unit.','.$to_unit.') min_value, - unitconv(max(value),'.$from_unit.','.$to_unit.') max_value + unitconv(min(min),'.$from_unit.','.$to_unit.') min_value, + unitconv(max(max),'.$from_unit.','.$to_unit.') max_value from ( select - unix_timestamp(cast(timestamp as date)) x, - value + unix_timestamp(day) x, + min, + max from - sensor_values + sensors_ranges where - timestamp>=str_to_date(\''.$year.$month.'\',\'%Y%m\') - and timestamp=str_to_date(\''.$year.$month.'\',\'%Y%m\') + and day$next_year) { + + $cachefilename='meteo.year.'.$sensor.'.'.$param.'.'.$year.'.'.$img_format; + + } + $q = $db -> prepare( ' select x, - unitconv(min(value),'.$from_unit.','.$to_unit.') min_value, - unitconv(max(value),'.$from_unit.','.$to_unit.') max_value + unitconv(min(min),'.$from_unit.','.$to_unit.') min_value, + unitconv(max(max),'.$from_unit.','.$to_unit.') max_value from ( select unix_timestamp( - DATE_SUB(cast(timestamp as date), INTERVAL DAYOFWEEK(cast(timestamp as date))-1 DAY) + DATE_SUB(day, INTERVAL DAYOFWEEK(day)-1 DAY) ) x, - value + min, + max from - sensor_values + sensors_ranges where - timestamp>=str_to_date(\''.$year.'\',\'%Y\') - and timestamp=str_to_date(\''.$year.'\',\'%Y\') + and daycache->IsValid($cachefilename)) { + + $g->cache->StreamImgFile($g->img,$cachefilename); + return; + + } else { + + $timeout = 8640000; + $g->SetupCache($cachefilename,$timeout); + + } + } + + $q -> execute(); while ($row = $q -> fetch(PDO::FETCH_ASSOC)) { @@ -144,7 +188,6 @@ if ($type and $param) { // Create the graph - $g = new Graph(640,480); $g->graph_theme = null; //$g->img->SetAntiAliasing();