From: Roman Bazalevsky Date: Thu, 25 Sep 2014 18:18:02 +0000 (+0400) Subject: Visual enhancements X-Git-Url: https://git.rvb.name/weathermon.git/commitdiff_plain/ee2fccf67428124c6ae125e5c35064c6ccae7a7b?ds=inline;hp=--cc Visual enhancements --- ee2fccf67428124c6ae125e5c35064c6ccae7a7b diff --git a/web/archive.php b/web/archive.php index 79ef6c4..031bce7 100644 --- a/web/archive.php +++ b/web/archive.php @@ -32,6 +32,64 @@ include('config_local.php'); include('calendar.php'); +function get_unit($db,$param) { + + $qug = $db -> prepare( + 'select u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id' + ); + $qug -> execute(); + + while ($row = $qug -> fetch(PDO::FETCH_ASSOC)) { + $from_unit = $row['id']; + $unit_group = $row['unit_group']; + } + + if (!empty($_COOKIE['unit_'.$unit_group])) { + $to_unit=intval($_COOKIE['unit_'.$unit_group]); + } else { + $to_unit=$from_unit; + } + + $qu = $db -> prepare( + 'select u.name_short from units u where u.id='.$to_unit + ); + $qu -> execute(); + + while ($row = $qu -> fetch(PDO::FETCH_ASSOC)) { + $param_unit = $row['name_short']; + } + + return Array( + 'from' => $from_unit, + 'to' => $to_unit, + 'name' => $param_unit + ); + +} + +function convert_unit($db,$value,$from,$to) { + + if ($from==$to) { + + $val = $value; + + } else { + + $qv = $db -> prepare( + 'select round(unitconv('.$value.','.$from.','.$to.'),2) res' + ); + $qv -> execute(); + + while ($row = $qv -> fetch(PDO::FETCH_ASSOC)) { + $val = $row['res']; + } + + } + + return $val; + +} + $year = $_REQUEST['year']; $month = $_REQUEST['month']; $day = $_REQUEST['day']; @@ -136,12 +194,20 @@ if (! $year) { $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { - + + $units = get_unit($db,$sensor['param']); + $from_unit = $units['from']; + $to_unit = $units['to']; + $param_unit = $units['name']; + + $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit); + $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit); + echo '

'.$sensor['param_name'].'('.$sensor['sensor_name'].')

'; echo ''; echo ''; echo '
'; - echo 'Минимальное значение за год '.$sensor['min_value'].' '.$sensor['unit'].'
'; - echo 'Максимальное значение за год '.$sensor['max_value'].' '.$sensor['unit'].'
'; + echo 'Минимальное значение за год '.$min_val.' '.$param_unit.'
'; + echo 'Максимальное значение за год '.$max_val.' '.$param_unit.'
'; echo '
'; @@ -221,12 +287,20 @@ if (! $year) { $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { + + $units = get_unit($db,$sensor['param']); + $from_unit = $units['from']; + $to_unit = $units['to']; + $param_unit = $units['name']; + + $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit); + $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit); echo '

'.$sensor['param_name'].'('.$sensor['sensor_name'].')

'; echo ''; echo ''; echo '
'; - echo 'Минимальное значение за месяц '.$sensor['min_value'].' '.$sensor['unit'].'
'; - echo 'Максимальное значение за месяц '.$sensor['max_value'].' '.$sensor['unit'].'
'; + echo 'Минимальное значение за месяц '.$min_val.' '.$param_unit.'
'; + echo 'Максимальное значение за месяц '.$max_val.' '.$param_unit.'
'; echo '
'; diff --git a/web/image.php b/web/image.php index eaa6fda..0e513a1 100644 --- a/web/image.php +++ b/web/image.php @@ -93,7 +93,7 @@ if ($type and $param) { if ($curr>$to) { - $cachefilename='meteo.'.$sensor.'.'.$param.'.'.$from.'-'.$to.'.'.$img_format; + $cachefilename='meteo.'.$sensor.'.'.$param.'.'.$to_unit.'.'.$from.'-'.$to.'.'.$img_format; } @@ -135,7 +135,7 @@ if ($type and $param) { $total_weight=0; $sum=0; - $maxdelta = 900; + $maxdelta = 1800; for ($j = $i; $j < count($xdata); ++$j) { @@ -167,13 +167,14 @@ if ($type and $param) { // Create the graph $g->graph_theme = null; - //$g->img->SetAntiAliasing(); + $g->img->SetAntiAliasing(); - // We need a linlin scale since we provide both - // x and y coordinates for the data points. + // We need a datlin scale since we provide both + // x and y coordinates for the data points, but x is unix timestamp. $g->SetScale('datlin'); $g->xaxis->SetLabelAngle(90); $g->xaxis->SetPos("min"); + $g->xaxis->scale->SetTimeAlign( HOURADJ_1 ); // We use a scatterplot to illustrate the original // contro points. @@ -196,6 +197,11 @@ if ($type and $param) { $g->title->SetFont(FF_DV_SANSSERIF,FS_BOLD,12); $g->SetMarginColor('silver'); + $g->xgrid->Show(); + $g->xgrid->SetLineStyle('dotted'); + $g->ygrid->Show(); + $g->ygrid->SetLineStyle('dotted'); + // Add the plots to the graph and stroke $g->Stroke(); diff --git a/web/image_minmax.php b/web/image_minmax.php index 3736221..dfa66d2 100644 --- a/web/image_minmax.php +++ b/web/image_minmax.php @@ -95,7 +95,7 @@ if ($type and $param) { if ($curr>$next_year.$next_month) { - $cachefilename='meteo.month.'.$sensor.'.'.$param.'.'.$year.'-'.$month.'.'.$img_format; + $cachefilename='meteo.month.'.$sensor.'.'.$param.'.'.$to_unit.'.'.$year.'-'.$month.'.'.$img_format; } @@ -197,6 +197,7 @@ if ($type and $param) { $g->SetScale('datlin'); $g->xaxis->SetLabelAngle(90); $g->xaxis->SetPos("min"); + $g->xaxis->scale->SetTimeAlign( MINADJ_1 ); // We use a scatterplot to illustrate the original // contro points. @@ -204,14 +205,14 @@ if ($type and $param) { $bplot = new LinePlot($maxdata,$xdata); $g->Add($bplot); $bplot->SetColor($fill_color_top); - $bplot->SetFillGradient($fill_color_top,$fill_color_bottom,100,TRUE); + $bplot->SetFillGradient($fill_color_top.'@0.2',$fill_color_bottom.'@0.9',100,TRUE); $bplot->SetFillFromYMin(TRUE); $bplot->SetWeight(4); $aplot = new LinePlot($mindata,$xdata); $g->Add($aplot); $aplot->SetColor($fill_color_bottom); - $aplot->SetFillGradient($fill_color_bottom,'white',100,TRUE); + $aplot->SetFillGradient($fill_color_bottom.'@0.2','white@0.9',100,TRUE); $aplot->SetFillFromYMin(TRUE); $aplot->SetWeight(4); @@ -222,6 +223,11 @@ if ($type and $param) { $g->subtitle->SetColor('darkred'); $g->SetMarginColor('silver'); + $g->xgrid->Show(); + $g->xgrid->SetLineStyle('dotted'); + $g->ygrid->Show(); + $g->ygrid->SetLineStyle('dotted'); + // Add the plots to the graph and stroke $g->Stroke();