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'];
$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 '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
echo '<table align="center">';
echo '<tr><td>';
- echo 'Минимальное значение за год <b>'.$sensor['min_value'].' '.$sensor['unit'].'</b><br>';
- echo 'Максимальное значение за год <b>'.$sensor['max_value'].' '.$sensor['unit'].'</b><br>';
+ echo 'Минимальное значение за год <b>'.$min_val.' '.$param_unit.'</b><br>';
+ echo 'Максимальное значение за год <b>'.$max_val.' '.$param_unit.'</b><br>';
echo '</td></tr>';
echo '</table>';
$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 '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
echo '<table align="center">';
echo '<tr><td>';
- echo 'Минимальное значение за месяц <b>'.$sensor['min_value'].' '.$sensor['unit'].'</b><br>';
- echo 'Максимальное значение за месяц <b>'.$sensor['max_value'].' '.$sensor['unit'].'</b><br>';
+ echo 'Минимальное значение за месяц <b>'.$min_val.' '.$param_unit.'</b><br>';
+ echo 'Максимальное значение за месяц <b>'.$max_val.' '.$param_unit.'</b><br>';
echo '</td></tr>';
echo '</table>';
if ($curr>$to) {
- $cachefilename='meteo.'.$sensor.'.'.$param.'.'.$from.'-'.$to.'.'.$img_format;
+ $cachefilename='meteo.'.$sensor.'.'.$param.'.'.$to_unit.'.'.$from.'-'.$to.'.'.$img_format;
}
$total_weight=0;
$sum=0;
- $maxdelta = 900;
+ $maxdelta = 1800;
for ($j = $i; $j < count($xdata); ++$j) {
// 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.
$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();
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;
}
$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.
$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);
$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();