АННОТАЦИЯ

В данном документе приведён текст программы системы усреднения данных с приборов сети измерений кафедры К3 МФ МГТУ им. Н. Э. Баумана.

ПРОГРАММНЫЙ КОД ВЕБ-ПРИЛОЖЕНИЯ

Корневой каталог веб-приложения

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Home page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="nav nav-default">
<h3>Навигация</h3>
<a href="/request.html">Примеры запросов для выгрузки данных</a>
<a href="/conn.php">Дебаг-монитор для дневных значений</a>
<a href="/conn_hour.php">Дебаг-монитор для часовых значений</a>
<a href="/conn_minutes.php">Дебаг-монитор для пятнадцатиминутных значений</a>
<a href="/fileexport.html">Выгрузка файла</a>
</nav>
</body>
</html>

<?php
function cmp($a, $b)
{
return strcmp($a[0], $b[0]);
}
//ini_set('display_errors','1');
//ini_set('display_startup_errors','1');
//error_reporting(E_ALL);
$pgi = pg_connect("host=localhost port=5432 dbname=averobo user=averobo password=*****");
?>
<!DOCTYPE html>
<style>
th {
text-indent: 0px;
border-collapse: collapse;
background: #e8edfa;
border-bottom: 1px solid #fff;
color: #500;
font-weight: 700;
border-top: 0px solid transparent;
padding: 2px;
text-align:center;
}
td {
text-indent: 0px;
border-collapse: collapse;
background: #e8edff;
border-bottom: 1px solid #fff;
color: #500;
border-top: 0px solid transparent;
padding: 2px;
text-align:center;
}
tr:hover td {background: #eeddff;}
tr{text-indent: 1px;}
</style>
<?php
if (!$pgi)
{
die ("Error!");
pg_close($pgi);
//	echo 'yes';
}
else
{
$query = 'SELECT average, json_file, date, name
FROM main_table
WHERE name NOT LIKE \'Сервер%\' AND date >= now()::date - interval \'1 day\'
ORDER BY date DESC';
$result = pg_query($pgi, "$query");
if(!$result)
{
die("Wrong query!");
}
else
{
$t_mas = array();
while($myrow = pg_fetch_assoc($result))
{
if(!in_array($myrow['average'], $t_mas))
{
array_push($t_mas, $myrow['average']);
}
}
rsort($t_mas);
array_unshift($t_mas, "name","date");
pg_result_seek($result, 0);
$i = 0;
while($infrow = pg_fetch_assoc($result))
{
$i++;
$flag = -100;
for($j=1; $j<$i; $j++)
{
if ($infrow["name"] == $mass[$j][0])
{
$flag = $j;
}
}
unset($j);
if ($flag != -100)
{
$mass[$flag][array_search($infrow['average'], $t_mas)] = $infrow['json_file'];
$i--;
} else
{
$mass[$i][array_search($infrow['average'], $t_mas)] = $infrow['json_file'];
$mass[$i][array_search("name", $t_mas)] = $infrow['name'];
$mass[$i][array_search("date", $t_mas)] = $infrow['date'];
}
}
usort($mass, "cmp");
unset($i);
$title = '<thead><tr>';
for($i=0; $i<count($t_mas); $i++)
{
$title .= '<th>'.$t_mas[$i].'</th>';
}
unset($i);
$max = '';
for($i=1; $i<count($mass)+1; $i++)
{
$max .= '<tr>';
for($j=0; $j<count($t_mas); $j++)
{
$max .= '<td>'.$mass[$i][$j].'</td>';
}
$max .= '</tr>';
}
$list = $title.'</tr></thead><tbody>'.$max.'</tbody>';
echo '<table width="100%" style="font-size: 11px">'.$list.'</table>';
}
}
pg_close($pgi);
?>

<?php
function cmp($a, $b)
{
return strcmp($a[0], $b[0]);
}
//ini_set('display_errors','1');
//ini_set('display_startup_errors','1');
//error_reporting(E_ALL);
$pgi = pg_connect("host=localhost port=5432 dbname=averobo user=averobo password=*****");
?>
<!DOCTYPE html>
<style>
th {
text-indent: 0px;
border-collapse: collapse;
background: #e8edfa;
border-bottom: 1px solid #fff;
color: #500;
font-weight: 700;
border-top: 0px solid transparent;
padding: 2px;
text-align:center;
}
td {
text-indent: 0px;
border-collapse: collapse;
background: #e8edff;
border-bottom: 1px solid #fff;
color: #500;
border-top: 0px solid transparent;
padding: 2px;
text-align:center;
}
tr:hover td {background: #eeddff;}
tr{text-indent: 1px;}
</style>
<?php
if (!$pgi)
{
die ("Error!");
pg_close($pgi);
}
else
{
$query = 'SELECT average, json_file, date, name
FROM table_with_time
WHERE name NOT LIKE \'Сервер%\' AND date >= now()::date - interval \'1 hour\' AND (average = \'maximum_in_hour\' OR average = \'minimum_in_hour\' OR average = \'aver_hour\')
ORDER BY date DESC';
$result = pg_query($pgi, "$query");
if(!$result)
{
die("Wrong query!");
}
else
{
$t_mas = array();
while($myrow = pg_fetch_assoc($result))
{
if(!in_array($myrow['average'], $t_mas))
{
array_push($t_mas, $myrow['average']);
}
}
rsort($t_mas);
array_unshift($t_mas, "name","date");
pg_result_seek($result, 0);
$i = 0;
while($infrow = pg_fetch_assoc($result))
{
$i++;
$flag = -100;
for($j=1; $j<$i; $j++)
{
if ($infrow["name"] == $mass[$j][0])
{
$flag = $j;
}
}
unset($j);
if ($flag != -100)
{
$mass[$flag][array_search($infrow['average'], $t_mas)] = $infrow['json_file'];
$i--;
} else
{
$mass[$i][array_search($infrow['average'], $t_mas)] = $infrow['json_file'];
$mass[$i][array_search("name", $t_mas)] = $infrow['name'];
$mass[$i][array_search("date", $t_mas)] = $infrow['date'];
}
}
usort($mass, "cmp");
unset($i);
$title = '<thead><tr>';
for($i=0; $i<count($t_mas); $i++)
{
$title .= '<th>'.$t_mas[$i].'</th>';
}
unset($i);
$max = '';
for($i=1; $i<count($mass)+1; $i++)
{
$max .= '<tr>';
for($j=0; $j<count($t_mas); $j++)
{
$max .= '<td>'.$mass[$i][$j].'</td>';
}
$max .= '</tr>';
}
$list = $title.'</tr></thead><tbody>'.$max.'</tbody>';
echo '<table width="100%" style="font-size: 11px">'.$list.'</table>';
}
}
pg_close($pgi);
?>

<?php
function cmp($a, $b)
{
return strcmp($a[0], $b[0]);
}
//ini_set('display_errors','1');
//ini_set('display_startup_errors','1');
//error_reporting(E_ALL);
$pgi = pg_connect("host=localhost port=5432 dbname=averobo user=averobo password=genshin2021alena2021");
?>
<!DOCTYPE html>
<style>
th {
text-indent: 0px;
border-collapse: collapse;
background: #e8edfa;
border-bottom: 1px solid #fff;
color: #500;
font-weight: 700;
border-top: 0px solid transparent;
padding: 2px;
text-align:center;
}
td {
text-indent: 0px;
border-collapse: collapse;
background: #e8edff;
border-bottom: 1px solid #fff;
color: #500;
border-top: 0px solid transparent;
padding: 2px;
text-align:center;
}
tr:hover td {background: #eeddff;}
tr{text-indent: 1px;}
</style>
<?php
if (!$pgi)
{
die ("Error!");
pg_close($pgi);
}
else
{
$query = 'SELECT average, json_file, date, name
FROM table_with_time
WHERE name NOT LIKE \'Сервер%\' AND date >= now()::date - interval \'15 minutes\' AND (average = \'minimum_in_15min\' OR average = \'maximum_in_15max\' OR average = \'aver_15min\')
ORDER BY date DESC';
$result = pg_query($pgi, "$query");
if(!$result)
{
die("Wrong query!");
}
else
{
$t_mas = array();
while($myrow = pg_fetch_assoc($result))
{
if(!in_array($myrow['average'], $t_mas))
{
array_push($t_mas, $myrow['average']);
}
}
rsort($t_mas);
array_unshift($t_mas, "name","date");
pg_result_seek($result, 0);
$i = 0;
while($infrow = pg_fetch_assoc($result))
{
$i++;
$flag = -100;
for($j=1; $j<$i; $j++)
{
if ($infrow["name"] == $mass[$j][0])
{
$flag = $j;
}
}
unset($j);
if ($flag != -100)
{
//echo "yes";
$mass[$flag][array_search($infrow['average'], $t_mas)] = $infrow['json_file'];
$i--;
} else
{
$mass[$i][array_search($infrow['average'], $t_mas)] = $infrow['json_file'];
$mass[$i][array_search("name", $t_mas)] = $infrow['name'];
$mass[$i][array_search("date", $t_mas)] = $infrow['date'];
}
}
usort($mass, "cmp");
unset($i);
$title = '<thead><tr>';
for($i=0; $i<count($t_mas); $i++)
{
$title .= '<th>'.$t_mas[$i].'</th>';
}
unset($i);
$max = '';
for($i=1; $i<count($mass)+1; $i++)
{
$max .= '<tr>';
for($j=0; $j<count($t_mas); $j++)
{
$max .= '<td>'.$mass[$i][$j].'</td>';
}
$max .= '</tr>';
}
$list = $title.'</tr></thead><tbody>'.$max.'</tbody>';
echo '<table width="100%" style="font-size: 11px">'.$list.'</table>';
}
}
pg_close($pgi);
?>