added script to output stats to a file, fixed wrong time zone on light_cuts.csv
parent
0d83a384f7
commit
7c34625b25
|
@ -0,0 +1,9 @@
|
|||
2021/09/23,04.50
|
||||
2021/09/24,05.71
|
||||
2021/09/25,08.86
|
||||
2021/09/26,07.53
|
||||
2021/09/27,08.63
|
||||
2021/09/28,08.31
|
||||
2021/09/29,12.0
|
||||
2021/09/30,11.65
|
||||
2021/10/01,06.41
|
|
|
@ -0,0 +1,63 @@
|
|||
status,date
|
||||
ON,2021/09/23 00:00
|
||||
ON,2021/09/23 06:58
|
||||
OFF,2021/09/23 14:11
|
||||
ON,2021/09/23 14:34
|
||||
OFF,2021/09/23 18:04
|
||||
ON,2021/09/23 21:05
|
||||
OFF,2021/09/23 22:54
|
||||
OFF,2021/09/24 00:00
|
||||
ON,2021/09/24 00:22
|
||||
OFF,2021/09/24 04:13
|
||||
ON,2021/09/24 07:39
|
||||
OFF,2021/09/24 16:18
|
||||
ON,2021/09/24 17:07
|
||||
OFF,2021/09/24 18:02
|
||||
ON,2021/09/24 19:08
|
||||
ON,2021/09/25 00:00
|
||||
OFF,2021/09/25 03:36
|
||||
ON,2021/09/25 06:16
|
||||
OFF,2021/09/25 12:01
|
||||
ON,2021/09/25 14:05
|
||||
OFF,2021/09/25 17:26
|
||||
ON,2021/09/25 18:30
|
||||
OFF,2021/09/25 20:56
|
||||
OFF,2021/09/26 00:00
|
||||
ON,2021/09/26 00:02
|
||||
OFF,2021/09/26 03:32
|
||||
ON,2021/09/26 08:08
|
||||
OFF,2021/09/26 13:44
|
||||
ON,2021/09/26 15:04
|
||||
OFF,2021/09/26 17:21
|
||||
ON,2021/09/26 18:55
|
||||
ON,2021/09/27 00:00
|
||||
OFF,2021/09/27 00:02
|
||||
ON,2021/09/27 06:09
|
||||
OFF,2021/09/27 11:02
|
||||
ON,2021/09/27 12:02
|
||||
OFF,2021/09/27 19:33
|
||||
ON,2021/09/27 21:04
|
||||
ON,2021/09/28 00:00
|
||||
OFF,2021/09/28 05:59
|
||||
ON,2021/09/28 09:48
|
||||
OFF,2021/09/28 15:24
|
||||
ON,2021/09/28 16:21
|
||||
OFF,2021/09/28 16:23
|
||||
ON,2021/09/28 18:56
|
||||
OFF,2021/09/28 23:00
|
||||
OFF,2021/09/29 00:00
|
||||
ON,2021/09/29 06:30
|
||||
OFF,2021/09/29 12:05
|
||||
ON,2021/09/29 14:02
|
||||
OFF,2021/09/29 20:27
|
||||
OFF,2021/09/30 00:00
|
||||
ON,2021/09/30 00:05
|
||||
OFF,2021/09/30 03:44
|
||||
ON,2021/09/30 08:25
|
||||
OFF,2021/09/30 09:21
|
||||
ON,2021/09/30 11:59
|
||||
OFF,2021/09/30 14:05
|
||||
ON,2021/09/30 18:18
|
||||
OFF,2021/09/30 23:58
|
||||
OFF,2021/10/01 00:00
|
||||
|
|
|
@ -10,12 +10,12 @@ then
|
|||
echo "OFF" > state.txt
|
||||
cat off.html | sed "s/date-n-time-placeholder/$date_now/" > /usr/local/apache2/htdocs/index.html
|
||||
./telegram "✅ The generator is OFF!"
|
||||
echo "OFF,$(date +'%Y/%m/%d %H:%M')" >> light_cuts.csv
|
||||
echo "OFF,$(TZ='Asia/Beirut' date +'%Y/%m/%d %H:%M')" >> light_cuts.csv
|
||||
else
|
||||
echo "ON" > state.txt
|
||||
cat on.html | sed "s/date-n-time-placeholder/$date_now/" > /usr/local/apache2/htdocs/index.html
|
||||
./telegram "❌ The generator is on. :("
|
||||
echo "ON,$(date +'%Y/%m/%d %H:%M')" >> light_cuts.csv
|
||||
echo "ON,$(TZ='Asia/Beirut' date +'%Y/%m/%d %H:%M')" >> light_cuts.csv
|
||||
fi
|
||||
|
||||
echo '<html><body>DONE</body></html>'
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
ON, 2021/09/23, 06:58
|
||||
ON, 2021/09/23, 07:13
|
||||
OFF, 2021/09/23, 00:23
|
||||
ON, 2021/09/23, 03:30
|
||||
OFF, 2021/09/23, 03:01
|
||||
ON, 2021/09/23, 01:49
|
||||
OFF, 2021/09/23, 01:06
|
||||
OFF, 2021/09/24, 00:22
|
||||
ON, 2021/09/24, 03:51
|
||||
OFF, 2021/09/24, 03:26
|
||||
ON, 2021/09/24, 08:39
|
||||
OFF, 2021/09/24, 00:49
|
||||
ON, 2021/09/24, 00:55
|
||||
OFF, 2021/09/24, 01:06
|
||||
ON, 2021/09/24, 04:52
|
||||
ON, 2021/09/25, 03:36
|
||||
OFF, 2021/09/25, 02:40
|
||||
ON, 2021/09/25, 05:45
|
||||
OFF, 2021/09/25, 02:04
|
||||
ON, 2021/09/25, 03:21
|
||||
OFF, 2021/09/25, 01:04
|
||||
ON, 2021/09/25, 02:26
|
||||
OFF, 2021/09/25, 03:04
|
||||
OFF, 2021/09/26, 00:02
|
||||
ON, 2021/09/26, 03:30
|
||||
OFF, 2021/09/26, 04:36
|
||||
ON, 2021/09/26, 05:36
|
||||
OFF, 2021/09/26, 01:20
|
||||
ON, 2021/09/26, 02:17
|
||||
OFF, 2021/09/26, 01:34
|
||||
ON, 2021/09/26, 05:05
|
||||
ON, 2021/09/27, 00:02
|
||||
OFF, 2021/09/27, 06:07
|
||||
ON, 2021/09/27, 04:53
|
||||
OFF, 2021/09/27, 01:00
|
||||
ON, 2021/09/27, 07:31
|
||||
OFF, 2021/09/27, 01:31
|
||||
ON, 2021/09/27, 02:56
|
||||
ON, 2021/09/28, 05:59
|
||||
OFF, 2021/09/28, 03:49
|
||||
ON, 2021/09/28, 05:36
|
||||
OFF, 2021/09/28, 00:57
|
||||
ON, 2021/09/28, 00:02
|
||||
OFF, 2021/09/28, 02:33
|
||||
ON, 2021/09/28, 04:04
|
||||
OFF, 2021/09/28, 01:00
|
||||
OFF, 2021/09/29, 06:30
|
||||
ON, 2021/09/29, 05:35
|
||||
OFF, 2021/09/29, 01:57
|
||||
ON, 2021/09/29, 06:25
|
||||
OFF, 2021/09/29, 03:33
|
||||
OFF, 2021/09/30, 00:05
|
||||
ON, 2021/09/30, 03:39
|
||||
OFF, 2021/09/30, 04:41
|
||||
ON, 2021/09/30, 00:56
|
||||
OFF, 2021/09/30, 02:38
|
||||
ON, 2021/09/30, 02:06
|
||||
OFF, 2021/09/30, 04:13
|
||||
ON, 2021/09/30, 05:40
|
||||
OFF, 2021/09/30, 00:02
|
||||
OFF, 2021/10/01, 06:25
|
||||
OFF, 2021/10/01, 00:00
|
|
|
@ -0,0 +1,119 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Generator Status...</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
}
|
||||
p {
|
||||
font-family: "Source Sans Pro", "SF Pro Display", sans-serif;
|
||||
font-weight: 600;
|
||||
font-size: inherit;
|
||||
}
|
||||
b {
|
||||
font-weight: bolder;
|
||||
}
|
||||
.title-bg {
|
||||
background-color: dimgray;
|
||||
height: auto;
|
||||
display: block;
|
||||
text-align: center;
|
||||
align-content: center;
|
||||
padding: 50px 50px 10px 50px;
|
||||
}
|
||||
.title-text {
|
||||
color: white;
|
||||
padding: 10px 5px;
|
||||
font-size: 40px;
|
||||
}
|
||||
.credits {
|
||||
padding: 10px 5px;
|
||||
text-align: center;
|
||||
font-size: 15px;
|
||||
color: gray;
|
||||
}
|
||||
.credits a {
|
||||
color: #555555;
|
||||
font-weight: 700;
|
||||
}
|
||||
.credits a:hover {
|
||||
color: #3c5c68;
|
||||
}
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
.date-time-updated {
|
||||
padding: 5px 5px;
|
||||
color: #dddddd;
|
||||
text-align: center;
|
||||
}
|
||||
.date-time-updated b {
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="title-bg">
|
||||
<div class="title-text">
|
||||
<p>Generator Stats</p>
|
||||
</div>
|
||||
<div class="date-time-updated">
|
||||
<p>last updated at: <b>date-n-time-placeholder</b></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart_last_week_class">
|
||||
<canvas id="chart_last_week"></canvas>
|
||||
</div>
|
||||
<div class="credits">
|
||||
<p>Made with ❤️ | Source Code: <a href="https://git.sandcastle.eu.org/thebiblelover7/generator-status">Gitea</a>
|
||||
<br>
|
||||
Thanks to <a href="https://matrix.to/#/@junyong_chung:tchncs.de">Junyong Chung</a> for the hardware and <a href="https://meu.edu.lb">MEU</a> for providing the domain.</p>
|
||||
</div>
|
||||
</body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
const labels = [
|
||||
'Sunday',
|
||||
'Monday',
|
||||
'Tuesday',
|
||||
'Wednesday',
|
||||
'Thursday',
|
||||
'Friday',
|
||||
'Saturday',
|
||||
];
|
||||
const data = {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: 'Hours we had electricity from government',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: [offtime_1, offtime_2, offtime_3, offtime_4, offtime_5, offtime_6, offtime_7],
|
||||
fill: {
|
||||
target: 'origin',
|
||||
above: 'rgb(255, 0, 0)', // Area will be red above the origin
|
||||
below: 'rgb(0, 0, 255)' // And blue below the origin
|
||||
|
||||
},
|
||||
}]
|
||||
};
|
||||
const config = {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 24,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var chart_last_week = new Chart(
|
||||
document.getElementById('chart_last_week'),
|
||||
config
|
||||
);
|
||||
</script>
|
||||
</html>
|
|
@ -0,0 +1,99 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm stats.csv days.csv &> /dev/null
|
||||
first_line=true
|
||||
|
||||
lines=$(cat light_cuts.csv | grep -c ,)
|
||||
line=0
|
||||
while read in
|
||||
do
|
||||
line=$(( $line + 1 ))
|
||||
if [[ $in != 'status,date' ]]
|
||||
then
|
||||
state=$(echo $in | cut -d, -f1)
|
||||
date_var=$(echo $in | cut -d, -f2)
|
||||
|
||||
if [[ $first_line = true ]]
|
||||
then
|
||||
prev_state=$state
|
||||
prev_date_var=$date_var
|
||||
first_line=false
|
||||
else
|
||||
D1=$(date -d "$prev_date_var" '+%s'); D2=$(date -d "$date_var" '+%s')
|
||||
stats_hours=$(echo "$(date -u -d@$((D2-D1)) +%H:%M)")
|
||||
echo "the generator was $prev_state for $stats_hours"
|
||||
day_date=$(echo $prev_date_var | cut --delimiter=' ' -f1 | cut -d, -f2)
|
||||
echo "$prev_state, $day_date, $stats_hours" >> stats.csv
|
||||
prev_state=$state
|
||||
prev_date_var=$date_var
|
||||
fi
|
||||
fi
|
||||
if [[ $line = $lines ]]
|
||||
then
|
||||
D1=$(date -d "$prev_date_var" '+%s'); D2=$(date '+%s')
|
||||
stats_hours=$(echo "$(date -u -d@$((D2-D1)) +%H:%M)")
|
||||
day_date=$(echo $prev_date_var | cut --delimiter=' ' -f1 | cut -d, -f2)
|
||||
echo "$prev_state, $day_date, $stats_hours" >> stats.csv
|
||||
fi
|
||||
done < light_cuts.csv
|
||||
|
||||
first_line=true
|
||||
|
||||
lines=$(cat stats.csv | grep -c OFF)
|
||||
line=0
|
||||
while read in
|
||||
do
|
||||
state=$(echo $in | cut -d, -f1)
|
||||
if [[ $state = 'OFF' ]]
|
||||
then
|
||||
line=$(( $line + 1 ))
|
||||
date_var=$(echo $in | cut -d, -f2)
|
||||
time=$(echo $in | cut -d, -f3)
|
||||
|
||||
if [[ $first_line = true ]]
|
||||
then
|
||||
current_date=$date_var
|
||||
total_time=$time
|
||||
first_line=false
|
||||
else
|
||||
if [[ $current_date = $date_var ]]
|
||||
then
|
||||
total_time=$(date -d "$total_time $(date -d "$time" +'%H hours %M minutes')" +'%H:%M')
|
||||
else
|
||||
time_decimal=$(echo $(date -d "$total_time" +'%H').$(($(date -d "$total_time" +'%M') * 100 / 60)))
|
||||
echo "$current_date,$time_decimal" >> days.csv
|
||||
current_date=$date_var
|
||||
total_time=$time
|
||||
fi
|
||||
fi
|
||||
if [[ $line = $lines ]]
|
||||
then
|
||||
time_decimal=$(echo $(date -d "$total_time" +'%H').$(($(date -d "$total_time" +'%M') * 100 / 60)))
|
||||
echo "$current_date,$time_decimal" >> days.csv
|
||||
fi
|
||||
fi
|
||||
done < stats.csv
|
||||
|
||||
lines=$(cat days.csv | grep -c ,)
|
||||
line=0
|
||||
line_start=$(( $lines - 7 ))
|
||||
day_num=0
|
||||
|
||||
while read in
|
||||
do
|
||||
hours=$(echo $in | cut -d, -f2)
|
||||
line=$(( $line + 1 ))
|
||||
if [[ $line > $line_start ]]
|
||||
then
|
||||
day_num=$(( $day_num + 1 ))
|
||||
if [[ $day_num = 1 ]]; then day_1=$(echo $hours | sed "s/0//"); fi
|
||||
if [[ $day_num = 2 ]]; then day_2=$(echo $hours | sed "s/0//"); fi
|
||||
if [[ $day_num = 3 ]]; then day_3=$(echo $hours | sed "s/0//"); fi
|
||||
if [[ $day_num = 4 ]]; then day_4=$(echo $hours | sed "s/0//"); fi
|
||||
if [[ $day_num = 5 ]]; then day_5=$(echo $hours | sed "s/0//"); fi
|
||||
if [[ $day_num = 6 ]]; then day_6=$(echo $hours | sed "s/0//"); fi
|
||||
if [[ $day_num = 7 ]]; then day_7=$(echo $hours | sed "s/0//"); fi
|
||||
fi
|
||||
done < days.csv
|
||||
|
||||
cat stats.html | sed "s/offtime_1/$day_1/" | sed "s/offtime_2/$day_2/"| sed "s/offtime_3/$day_3/" | sed "s/offtime_4/$day_4/" | sed "s/offtime_5/$day_5/" | sed "s/offtime_6/$day_6/" | sed "s/offtime_7/$day_7/" > stats/index.html
|
|
@ -0,0 +1,119 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Generator Status...</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
}
|
||||
p {
|
||||
font-family: "Source Sans Pro", "SF Pro Display", sans-serif;
|
||||
font-weight: 600;
|
||||
font-size: inherit;
|
||||
}
|
||||
b {
|
||||
font-weight: bolder;
|
||||
}
|
||||
.title-bg {
|
||||
background-color: dimgray;
|
||||
height: auto;
|
||||
display: block;
|
||||
text-align: center;
|
||||
align-content: center;
|
||||
padding: 50px 50px 10px 50px;
|
||||
}
|
||||
.title-text {
|
||||
color: white;
|
||||
padding: 10px 5px;
|
||||
font-size: 40px;
|
||||
}
|
||||
.credits {
|
||||
padding: 10px 5px;
|
||||
text-align: center;
|
||||
font-size: 15px;
|
||||
color: gray;
|
||||
}
|
||||
.credits a {
|
||||
color: #555555;
|
||||
font-weight: 700;
|
||||
}
|
||||
.credits a:hover {
|
||||
color: #3c5c68;
|
||||
}
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
.date-time-updated {
|
||||
padding: 5px 5px;
|
||||
color: #dddddd;
|
||||
text-align: center;
|
||||
}
|
||||
.date-time-updated b {
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="title-bg">
|
||||
<div class="title-text">
|
||||
<p>Generator Stats</p>
|
||||
</div>
|
||||
<div class="date-time-updated">
|
||||
<p>last updated at: <b>date-n-time-placeholder</b></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart_last_week_class">
|
||||
<canvas id="chart_last_week"></canvas>
|
||||
</div>
|
||||
<div class="credits">
|
||||
<p>Made with ❤️ | Source Code: <a href="https://git.sandcastle.eu.org/thebiblelover7/generator-status">Gitea</a>
|
||||
<br>
|
||||
Thanks to <a href="https://matrix.to/#/@junyong_chung:tchncs.de">Junyong Chung</a> for the hardware and <a href="https://meu.edu.lb">MEU</a> for providing the domain.</p>
|
||||
</div>
|
||||
</body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
const labels = [
|
||||
'Sunday',
|
||||
'Monday',
|
||||
'Tuesday',
|
||||
'Wednesday',
|
||||
'Thursday',
|
||||
'Friday',
|
||||
'Saturday',
|
||||
];
|
||||
const data = {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: 'Hours we had electricity from government',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: [8.86, 7.53, 8.63, 8.31, 12., 11.65, 6.41],
|
||||
fill: {
|
||||
target: 'origin',
|
||||
above: 'rgb(255, 0, 0)', // Area will be red above the origin
|
||||
below: 'rgb(0, 0, 255)' // And blue below the origin
|
||||
|
||||
},
|
||||
}]
|
||||
};
|
||||
const config = {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 24,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var chart_last_week = new Chart(
|
||||
document.getElementById('chart_last_week'),
|
||||
config
|
||||
);
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue