Compare commits

...

5 Commits

6 changed files with 162 additions and 113 deletions

View File

@ -15,15 +15,15 @@
}
},
"require": {
"php": ">=7.4.0",
"php": ">=8.0",
"ext-json": "*",
"ext-mbstring": "*",
"ext-rrd": "*",
"phpmailer/phpmailer": "^6.4",
"phpmailer/phpmailer": "^6.5",
"twig/twig": "^3.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0"
"friendsofphp/php-cs-fixer": "^3.2"
},
"license": "MIT",
"authors": [

122
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9c1a38df70a4ffb7cbf9c4d9f7fed95c",
"content-hash": "fcf932155c8963e13d7886067a859a26",
"packages": [
{
"name": "phpmailer/phpmailer",
@ -323,16 +323,16 @@
"packages-dev": [
{
"name": "composer/semver",
"version": "3.2.5",
"version": "3.2.6",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
"reference": "31f3ea725711245195f62e54ffa402d8ef2fdba9"
"reference": "83e511e247de329283478496f7a1e114c9517506"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/semver/zipball/31f3ea725711245195f62e54ffa402d8ef2fdba9",
"reference": "31f3ea725711245195f62e54ffa402d8ef2fdba9",
"url": "https://api.github.com/repos/composer/semver/zipball/83e511e247de329283478496f7a1e114c9517506",
"reference": "83e511e247de329283478496f7a1e114c9517506",
"shasum": ""
},
"require": {
@ -384,7 +384,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/semver/issues",
"source": "https://github.com/composer/semver/tree/3.2.5"
"source": "https://github.com/composer/semver/tree/3.2.6"
},
"funding": [
{
@ -400,7 +400,7 @@
"type": "tidelift"
}
],
"time": "2021-05-24T12:41:47+00:00"
"time": "2021-10-25T11:34:17+00:00"
},
{
"name": "composer/xdebug-handler",
@ -620,16 +620,16 @@
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v3.2.1",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
"reference": "13ae36a76b6e329e44ca3cafaa784ea02db9ff14"
"reference": "06bdbdfcd619183dd7a1a6948360f8af73b9ecec"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/13ae36a76b6e329e44ca3cafaa784ea02db9ff14",
"reference": "13ae36a76b6e329e44ca3cafaa784ea02db9ff14",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/06bdbdfcd619183dd7a1a6948360f8af73b9ecec",
"reference": "06bdbdfcd619183dd7a1a6948360f8af73b9ecec",
"shasum": ""
},
"require": {
@ -638,18 +638,19 @@
"doctrine/annotations": "^1.12",
"ext-json": "*",
"ext-tokenizer": "*",
"php": "^7.2 || ^8.0",
"php": "^7.2.5 || ^8.0",
"php-cs-fixer/diff": "^2.0",
"symfony/console": "^4.4.20 || ^5.1.3",
"symfony/event-dispatcher": "^4.4.20 || ^5.0",
"symfony/filesystem": "^4.4.20 || ^5.0",
"symfony/finder": "^4.4.20 || ^5.0",
"symfony/options-resolver": "^4.4.20 || ^5.0",
"symfony/console": "^5.1.3",
"symfony/event-dispatcher": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/finder": "^5.0",
"symfony/options-resolver": "^5.0",
"symfony/polyfill-mbstring": "^1.23",
"symfony/polyfill-php72": "^1.23",
"symfony/polyfill-php80": "^1.23",
"symfony/polyfill-php81": "^1.23",
"symfony/process": "^4.4.20 || ^5.0",
"symfony/stopwatch": "^4.4.20 || ^5.0"
"symfony/process": "^5.0",
"symfony/stopwatch": "^5.0"
},
"require-dev": {
"justinrainbow/json-schema": "^5.2",
@ -665,12 +666,11 @@
"phpunitgoodpractices/polyfill": "^1.5",
"phpunitgoodpractices/traits": "^1.9.1",
"symfony/phpunit-bridge": "^5.2.4",
"symfony/yaml": "^4.4.20 || ^5.0"
"symfony/yaml": "^5.0"
},
"suggest": {
"ext-dom": "For handling output formats in XML",
"ext-mbstring": "For handling non-UTF8 characters.",
"symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible."
"ext-mbstring": "For handling non-UTF8 characters."
},
"bin": [
"php-cs-fixer"
@ -698,7 +698,7 @@
"description": "A tool to automatically fix PHP code style",
"support": {
"issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues",
"source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v3.2.1"
"source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v3.3.2"
},
"funding": [
{
@ -706,7 +706,7 @@
"type": "github"
}
],
"time": "2021-10-05T08:12:17+00:00"
"time": "2021-11-15T18:06:47+00:00"
},
{
"name": "php-cs-fixer/diff",
@ -762,20 +762,20 @@
},
{
"name": "psr/cache",
"version": "1.0.1",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
"php": ">=8.0.0"
},
"type": "library",
"extra": {
@ -795,7 +795,7 @@
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
@ -805,26 +805,26 @@
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/master"
"source": "https://github.com/php-fig/cache/tree/3.0.0"
},
"time": "2016-08-06T20:24:11+00:00"
"time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/container",
"version": "1.1.1",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf"
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf",
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf",
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
"shasum": ""
},
"require": {
"php": ">=7.2.0"
"php": ">=7.4.0"
},
"type": "library",
"autoload": {
@ -853,9 +853,9 @@
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/1.1.1"
"source": "https://github.com/php-fig/container/tree/1.1.2"
},
"time": "2021-03-05T17:36:06+00:00"
"time": "2021-11-05T16:50:12+00:00"
},
{
"name": "psr/event-dispatcher",
@ -909,30 +909,30 @@
},
{
"name": "psr/log",
"version": "1.1.4",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11"
"reference": "ef29f6d262798707a9edd554e2b82517ef3a9376"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11",
"url": "https://api.github.com/repos/php-fig/log/zipball/ef29f6d262798707a9edd554e2b82517ef3a9376",
"reference": "ef29f6d262798707a9edd554e2b82517ef3a9376",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
"Psr\\Log\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -953,22 +953,22 @@
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/1.1.4"
"source": "https://github.com/php-fig/log/tree/2.0.0"
},
"time": "2021-05-03T11:20:27+00:00"
"time": "2021-07-14T16:41:46+00:00"
},
{
"name": "symfony/console",
"version": "v5.3.7",
"version": "v5.3.10",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "8b1008344647462ae6ec57559da166c2bfa5e16a"
"reference": "d4e409d9fbcfbf71af0e5a940abb7b0b4bad0bd3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/8b1008344647462ae6ec57559da166c2bfa5e16a",
"reference": "8b1008344647462ae6ec57559da166c2bfa5e16a",
"url": "https://api.github.com/repos/symfony/console/zipball/d4e409d9fbcfbf71af0e5a940abb7b0b4bad0bd3",
"reference": "d4e409d9fbcfbf71af0e5a940abb7b0b4bad0bd3",
"shasum": ""
},
"require": {
@ -1038,7 +1038,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v5.3.7"
"source": "https://github.com/symfony/console/tree/v5.3.10"
},
"funding": [
{
@ -1054,7 +1054,7 @@
"type": "tidelift"
}
],
"time": "2021-08-25T20:02:16+00:00"
"time": "2021-10-26T09:30:15+00:00"
},
{
"name": "symfony/deprecation-contracts",
@ -2168,16 +2168,16 @@
},
{
"name": "symfony/string",
"version": "v5.3.7",
"version": "v5.3.10",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "8d224396e28d30f81969f083a58763b8b9ceb0a5"
"reference": "d70c35bb20bbca71fc4ab7921e3c6bda1a82a60c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/8d224396e28d30f81969f083a58763b8b9ceb0a5",
"reference": "8d224396e28d30f81969f083a58763b8b9ceb0a5",
"url": "https://api.github.com/repos/symfony/string/zipball/d70c35bb20bbca71fc4ab7921e3c6bda1a82a60c",
"reference": "d70c35bb20bbca71fc4ab7921e3c6bda1a82a60c",
"shasum": ""
},
"require": {
@ -2231,7 +2231,7 @@
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v5.3.7"
"source": "https://github.com/symfony/string/tree/v5.3.10"
},
"funding": [
{
@ -2247,7 +2247,7 @@
"type": "tidelift"
}
],
"time": "2021-08-26T08:00:08+00:00"
"time": "2021-10-27T18:21:46+00:00"
}
],
"aliases": [],
@ -2256,7 +2256,7 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=7.4.0",
"php": ">=8.0",
"ext-json": "*",
"ext-mbstring": "*",
"ext-rrd": "*"

View File

@ -1,5 +1,5 @@
body {
margin: 2em 1em 2em 70px;
margin: 2em 1em 0 3em;
color: black;
background: white;
background-position: top left;
@ -9,19 +9,19 @@ body {
text-align: center;
}
th.requirement { background-color: #ff66ff; color: black; }
h1 { text-align: center; }
h2, h3, h4, h5, h6 { text-align: left; }
h1 { color: black; font: 120% sans-serif; font-weight: bold; }
h2 { color: #005A9C; font: 110%; font-weight: medium; }
h3 { color: #001A4C; font: 105% sans-serif; font-weight: medium; }
h4 { color: #007A9C; font: 90% sans-serif; font-weight: medium; }
h5 { color: #005A9C; font: italic 80% sans-serif; }
h6 { font: small-caps 70% sans-serif; }
h1 {text-align: center}
h2, h3, h4, h5, h6 { text-align: left }
h1 { color: black; font: 120% sans-serif; font-weight: bold}
h2 { color: #005A9C; font: 110%; font-weight: medium}
h3 { color: #001A4C; font: 105% sans-serif; font-weight: medium}
h4 { color: #007A9C; font: 90% sans-serif; font-weight: medium}
h5 { color: #005A9C; font: italic 80% sans-serif }
h6 { font: small-caps 70% sans-serif }
img { width: auto; height: auto; max-width: 100%; max-height: 100%; }
main { display: flex; flex-wrap: wrap; }
main div.graph { margin: 5px auto; }
main div.range-select span { color: blue; text-decoration: underline; cursor: pointer; }
pre {
background-color: lightcyan;
text-color: black;
}

View File

@ -1,33 +1,72 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="ja" />
<meta http-equiv="Content-Stype-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="refresh" content="60" />
<link rel="stylesheet" type="text/css" href="css/default.css" />
<meta charset="utf-8">
<title>C407 Server Room Temperature</title>
<meta name="description" content="C407 Server Room Temperature">
<meta name="author" content="Neuroinformatics Unit, RIKEN CBS">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="refresh" content="300">
<link rel="stylesheet" href="css/default.css">
</head>
<body>
<h1>C407 Server Room Temperature</h1>
<table>
<tbody>
<tr>
<td><img src="./images/graph-hour.png" alt="Hourly Graph" /></td>
<td><img src="./images/graph-day.png" alt="Daily Graph" /></td>
</tr>
<tr>
<td><img src="./images/graph-week.png" alt="Weekly Graph" /></td>
<td><img src="./images/graph-month.png" alt="Monthly Graph" /></td>
</tr>
<tr>
<td><img src="./images/graph-year.png" alt="Yearly Graph" /></td>
<td><img src="./images/graph-3year.png" alt="3 Years Graph" /></td>
</tr>
</tbody>
</table>
<main>
<div class="graph">
<div class="range-select">
Hour:
<span onclick="changeGraph('g1', 'hour', 1)">1</span> ...
<span onclick="changeGraph('g1', 'hour', 3)">3</span> ...
<span onclick="changeGraph('g1', 'hour', 6)">6</span> ...
<span onclick="changeGraph('g1', 'hour', 12)">12</span>
</div>
<div><img id="g1" src="./images/graph-hour.png" alt="Hourly Graph" /></div>
</div>
<div class="graph">
<div class="range-select">
Day:
<span onclick="changeGraph('g2', 'day', 1)">1</span> ...
<span onclick="changeGraph('g2', 'day', 3)">3</span>
</div>
<div><img id="g2" src="./images/graph-day.png" alt="Daily Graph" /></div>
</div>
<div class="graph">
<div class="range-select">
Week:
<span onclick="changeGraph('g3', 'week', 1)">1</span> ...
<span onclick="changeGraph('g3', 'week', 2)">2</span>
</div>
<div><img id="g3" src="./images/graph-week.png" alt="Weekly Graph" /></div>
</div>
<div class="graph">
<div class="range-select">
Month:
<span onclick="changeGraph('g4', 'month', 1)">1</span> ...
<span onclick="changeGraph('g4', 'month', 3)">3</span> ...
<span onclick="changeGraph('g4', 'month', 6)">6</span>
</div>
<div><img id="g4" src="./images/graph-month.png" alt="Monthly Graph" /></div>
</div>
<div class="graph">
<div class="range-select">
Year:
<span onclick="changeGraph('g5', 'year', 1)">1</span> ...
<span onclick="changeGraph('g5', 'year', 3)">3</span> ...
<span onclick="changeGraph('g5', 'year', 5)">5</span> ...
<span onclick="changeGraph('g5', 'year', 10)">10</span>
</div>
<div><img id="g5" src="./images/graph-year.png" alt="Yearly Graph" /></div>
</div>
</main>
<script>
function changeGraph(id, type, num) {
const img = document.getElementById(id);
if (img) {
img.src = './images/graph-' + (num === 1 ? '' : num) + type + '.png';
}
}
</script>
</body>
</html>

View File

@ -112,8 +112,8 @@ class Temperature
$options = [
'--step', '60', // 1min step
sprintf('DS:%s:GAUGE:600:0:100', $id), // 10min hartbeat
'RRA:LAST:0.5:1:1440', // last/m - 1day(1440min)
'RRA:LAST:0.5:30:52560', // last/30m - 3years(365day=30min*17520)*3
'RRA:LAST:0.5:1:10080', // last/m - 7day(10080min)
'RRA:LAST:0.5:30:175200', // last/30m - 10years(365day=30min*17520)*10
];
return rrd_create($fpath, $options);
@ -135,21 +135,22 @@ class Temperature
* output graph.
*
* @param string $type output graph type
* @param int $num output period of graph type
* @param string $fpath output image file path
*
* @return bool false if failure
*/
public function outputGraph(string $type, string $fpath): bool
public function outputGraph(string $type, int $num, string $fpath): bool
{
static $colors = [
'#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF',
'#FF9999', '#99FF99', '#9999FF', '#FFFF99', '#99FFFF', '#FF99FF',
];
static $types = ['hour', 'day', 'week', 'month', 'year', '3year'];
static $types = ['hour', 'day', 'week', 'month', 'year'];
if (!in_array($type, $types)) {
return false;
}
$start = '3year' == $type ? '-3year' : '-1'.$type;
$start = sprintf('-%u%s', $num, $type);
$options = [
'--imgformat', 'PNG',
'--lower-limit', '10',
@ -160,7 +161,7 @@ class Temperature
'--height', '200',
'--units-exponent', '0',
'--vertical-label', "Temperature [\xc2\xb0C]",
'--title', 'Server Room Temperature - by '.$type,
'--title', 'Server Room Temperature - by '.$num.$type.'(s)',
];
$idlen = 0;
foreach ($this->sensorIds as $key => $id) {

View File

@ -16,7 +16,16 @@ for ($i = 0; $i < $num; ++$i) {
$now = time();
$rrdtemp->update($id, $now, $value);
}
foreach ($types = ['hour', 'day', 'week', 'month', 'year', '3year'] as $type) {
$fpath = APPDIR.'/'.$config['images_dir'].'/graph-'.$type.'.png';
$rrdtemp->outputGraph($type, $fpath);
$types = [
'hour' => [1, 3, 6, 12],
'day' => [1, 3],
'week' => [1, 2],
'month' => [1, 3, 6],
'year' => [1, 3, 5, 10],
];
foreach ($types as $type => $nums) {
foreach ($nums as $num) {
$fpath = APPDIR.'/'.$config['images_dir'].'/graph-'.(1 === $num ? '' : $num).$type.'.png';
$rrdtemp->outputGraph($type, $num, $fpath);
}
}