X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/065f212afe549f1dfc2fee1e42349b725d8e40c5..255f5e76130a14358c33c81384726a93a30904d9:/web/archive.php?ds=inline 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 '
';