Skip to content

Commit

Permalink
Web statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
slacky1965 committed Jun 27, 2017
1 parent 8dddd45 commit cca1055
Show file tree
Hide file tree
Showing 3 changed files with 446 additions and 0 deletions.
181 changes: 181 additions & 0 deletions utils/web/column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php

include ('lib/module.php');

$hotWaterTable = $_POST['hot_water_table'];
$coldWaterTable = $_POST['cold_water_table'];

$date = explode("-", $_POST['date']);
$year = $date[0];
$month = $date[1];
$day = $date[2];
$period = $_POST['period'];

$db = openBase();

$hotArray = array();
$coldArray = array();

$globCounter = 0;




if ($period == "day") {

$dateIn = mktime(0, 0, 0, $month, $day, $year);
$dateEnd = mktime(23, 59, 59, $month, $day, $year);

$xAxis = "0";
for($i=1; $i < 24; $i++) {
$xAxis = $xAxis.", $i";
}

$titleText = "00:00:00 $day-$month-$year - 23:59:59 $day-$month-$year";

$retHot = getPeriod($hotWaterTable);
$retCold = getPeriod($coldWaterTable);

for($i = 0; $i < 24; $i++) {
$hotArray[$i] = 0;
$coldArray[$i] = 0;
}

} elseif ($period == "month") {

$d = date("t", strtotime("$year-$month"));

$dateIn = mktime(0, 0, 0, $month, 1, $year);
$dateEnd = mktime(23, 59, 59, $month, $d, $year);

$xAxis = "1";
for ($i=2; $i <= $d; $i++) {
$xAxis = $xAxis.", $i";
}

$titleText = "00:00:00 01-$month-$year - 23:59:59 $d-$month-$year";

$retHot = getPeriod($hotWaterTable);
$retCold = getPeriod($coldWaterTable);

for($i = 1; $i <= $d; $i++) {
$hotArray[$i] = 0;
$coldArray[$i] = 0;
}


} else {

$dateIn = mktime(0, 0, 0, 1, 1, $year);
$dateEnd = mktime(23, 59, 59, 12, 31, $year);

$xAxis = "1";
for($i=2; $i <= 12; $i++) {
$xAxis = $xAxis.", $i";
}

$titleText = "00:00:00 01-01-$year - 23:59:59 31-12-$year";

$retHot = getPeriod($hotWaterTable);
$retCold = getPeriod($coldWaterTable);

for($i = 1; $i <= 12; $i++) {
$hotArray[$i] = 0;
$coldArray[$i] = 0;
}

}

makeColumns($hotWaterTable, $retHot, $hotArray);
$titleText = $titleText."<br>Total $globCounter liters of hot water ";

makeColumns($coldWaterTable, $retCold, $coldArray);
$titleText = $titleText." and $globCounter liters of cold water";


?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts WaterMeter</title>

<style type="text/css">

</style>
</head>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>



<script type="text/javascript">

Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'WaterMeter'
},
subtitle: {
text: '<?php echo $titleText ?>'
},
xAxis: {
categories: [
<?php
echo $xAxis;
?>
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Liters'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} liters</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Hot Water',
color: '#FF0000',
data: [<?php
foreach ($hotArray as $value) {
echo "$value, ";
}
?>]

}, {
name: 'Cold Water',
color: '#00008B',
data: [<?php
foreach ($coldArray as $value) {
echo "$value, ";
}
?>]

}]
});
</script>
</body>
</html>

<?php
closeBase();
?>
112 changes: 112 additions & 0 deletions utils/web/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

include ('lib/module.php');

$db = openBase();
$arrayTables = getTables();

?>

<!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">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"; charset=utf-8>
<title>WaterMeter statistics</title>
<style>
form {
width: 35em;
margin: 0 auto;
text-align: center;
font: 12pt/10pt sans-serif;
}

form {
max-width: 1000px;
height: auto;
}

a.hot {
color: #FF0000;
}

a.cold {
color: #00008B;
}

@media (max-width: 1024px) {
form {
width: 800px;
height: auto;
}
}

@media (max-width: 768px) {
form {
width: 600px;
height: auto;
}
}

@media (max-width: 480px) {
form {
width: 100%;
height: auto;
}
}

@media (max-width: 320px) {
form {
width: 100%;
height: auto;
}
}
</style>
</head>
<body>

<form action="column.php" method="POST">
<p><a class="hot"><b>Hot Water Table </b></a><select size="1" name="hot_water_table">
<?php
$i = 0;
foreach($arrayTables as $value) {
if ($i == 0) {
echo "<option value=\"$value\" selected>$value</option>\n";
$i++;
}
echo "<option value=\"$value\">$value</option>\n";
}
?>
</select></p>
<p><a class="cold"><b>Cold Water Table </b></a><select size="1" name="cold_water_table">
<?php
$i = 0;
foreach($arrayTables as $value) {
if ($i == 0) {
echo "<option value=\"$value\" selected>$value</option>\n";
$i++;
}
echo "<option value=\"$value\">$value</option>\n";
}
?>
</select></p>


<p>Select a date: <input required type="date" name="date"></p>

<p><input type="radio" name="period" id="day" value="day" checked>
<label for="day">Day</label>
<input type="radio" name="period" id="month" value="month">
<label for="month">Month</label>
<input type="radio" name="period" id="year" value="year">
<label for="year">Year</label></p>

<p><input type="submit" value="Submit"></p>

</form>

</body>
</html>

<?php
closeBase();
?>
Loading

0 comments on commit cca1055

Please sign in to comment.