s-evohome.mkiv /size: 10 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=s-evohome,
3
%D version=2017.11.12,
4
%D title=\CONTEXT\ Style File,
5
%D subtitle=Evohome Graphics,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\setupbodyfont
[
dejavu
]
15 16
\starttext
17 18
\startluacode
19 20
local
evohome
=
require
(
"
util-evo
"
)
21 22
moduledata
.
evohome
=
{
}
23 24
function
moduledata
.
evohome
.
status
(
specification
)
25 26
local
presets
=
evohome
.
helpers
.
loadpresets
(
specification
.
presets
)
27
local
zones
=
evohome
.
helpers
.
loadtemperatures
(
presets
)
28 29
-- todo : time
30 31
if
not
zones
then
32
context
(
"
no zones
"
)
33
context
.
blank
(
)
34
return
35
end
36 37
local
t
=
zones
.
time
38 39
t
=
t
and
os
.
date
(
"
%Y-%m-%d %H:%M:%S
"
,
t
)
or
"
unknown time
"
40 41
context
.
starttitle
{
title
=
t
}
42 43
context
.
starttabulate
{
"
|l|c|c|c|c|
"
}
44
context
.
BC
(
)
context
(
"
name
"
)
45
context
.
BC
(
)
context
(
"
current
"
)
46
context
.
BC
(
)
context
(
"
min
"
)
47
context
.
BC
(
)
context
(
"
max
"
)
48
context
.
BC
(
)
context
(
"
target
"
)
49
context
.
NC
(
)
context
.
NR
(
)
50
for
i
=
1
,
#
zones
do
51
local
zone
=
zones
[
i
]
52
context
.
NC
(
)
context
.
word
(
zone
.
name
)
53
context
.
NC
(
)
context
(
"
%0.1f
"
,
zone
.
current
)
54
context
.
NC
(
)
context
(
"
%0.1f
"
,
zone
.
min
)
55
context
.
NC
(
)
context
(
"
%0.1f
"
,
zone
.
max
)
56
context
.
NC
(
)
context
(
"
%0.1f
"
,
zone
.
target
)
57
context
.
NC
(
)
context
.
NR
(
)
58
end
59
context
.
stoptabulate
(
)
60 61
for
i
=
1
,
#
zones
do
62
local
zone
=
zones
[
i
]
63
-- evohome.helpers.updatezone(presets,zone.name)
64
local
data
=
evohome
.
helpers
.
getzonestate
(
presets
,
zone
.
name
)
65
local
schedule
=
data
and
data
.
schedule
or
{
}
66
context
.
startsubject
{
title
=
zone
.
name
}
67
context
.
starttabulate
{
"
|l|c|c|
"
}
68
context
.
BC
(
)
context
(
"
day
"
)
69
context
.
BC
(
)
context
(
"
time
"
)
70
context
.
BC
(
)
context
(
"
temperature
"
)
71
context
.
NR
(
)
72
local
daily
=
schedule
.
dailySchedules
73
if
daily
then
74
for
i
=
1
,
#
daily
do
75
local
d
=
daily
[
i
]
76
local
s
=
d
.
switchpoints
77
if
s
then
78
for
i
=
1
,
#
s
do
79
context
.
NC
(
)
80
if
i
=
=
1
then
81
context
.
word
(
d
.
dayOfWeek
)
82
end
83
context
.
NC
(
)
context
(
s
[
i
]
.
timeOfDay
)
84
context
.
NC
(
)
context
(
s
[
i
]
.
temperature
)
85
context
.
NC
(
)
context
.
NR
(
)
86
end
87
end
88
end
89
end
90
context
.
stoptabulate
(
)
91
context
.
stopsubject
(
)
92
end
93 94
context
.
stoptitle
(
)
95 96
end
97 98
function
moduledata
.
evohome
.
history
(
specification
)
99 100
local
presets
=
evohome
.
helpers
.
loadpresets
(
specification
.
presets
)
101
local
zones
=
evohome
.
helpers
.
loadtemperatures
(
presets
)
102 103
if
not
zones
then
104
context
(
"
no zones
"
)
105
context
.
blank
(
)
106
return
107
end
108 109
local
data
=
evohome
.
helpers
.
loadhistory
(
presets
)
110 111
if
not
zones
then
112
context
(
"
no history
"
)
113
return
114
end
115 116
local
years
=
data
.
years
117 118
if
not
years
then
119
context
(
"
no years
"
)
120
return
121
end
122 123
local
minyear
=
specification
.
year
or
2017
124
local
maxyear
=
minyear
125
local
minmonth
=
specification
.
month
or
1
126
local
maxmonth
=
specification
.
month
or
12
127 128
local
scale
=
1
/
8
-- 20
129
local
mark
=
3
130
local
abstemp
=
25
131 132
for
y
=
minyear
,
maxyear
do
133 134
local
year
=
years
[
y
]
135 136
for
m
=
minmonth
,
maxmonth
do
137 138
local
month
=
year
.
months
[
m
]
139 140
if
month
then
141 142
context
.
starttitle
{
title
=
"
\\month{
"
.
.
m
.
.
"
}\\enspace
"
.
.
y
}
-- todo: function context.Month(m) end
143 144
for
i
=
1
,
#
zones
do
145 146
local
zone
=
zones
[
i
]
147
local
where
=
zone
.
name
148
local
mintemp
=
zone
.
min
149
local
maxtemp
=
zone
.
max
150 151
-- context.startMPpage { offset = "10pt" }
152
context
.
startlinecorrection
(
)
153
context
.
startMPcode
(
)
154
context
(
"
linecap := butt; pickup pencircle scaled .5
"
)
155 156
context
(
"
fill (%s,%s) -- (%s,%s) -- (%s,%s) -- (%s,%s) -- cycle withcolor .8white ;
"
,
157
0
,
mintemp
/
scale
,
158
31
*
24
,
mintemp
/
scale
,
159
31
*
24
,
maxtemp
/
scale
,
160
0
,
maxtemp
/
scale
161
)
162 163
for
i
=
0
,
abstemp
do
164
context
(
"
draw (%s,%s) -- (%s,%s) withcolor .6white ;
"
,
165
0
,
i
/
scale
,
166
31
*
24
,
i
/
scale
167
)
168
end
169 170
local
days
=
month
.
days
171
if
days
then
172
local
nd
=
os
.
nofdays
(
y
,
m
)
173
for
d
=
1
,
nd
do
174
local
day
=
days
[
d
]
175
local
xoffset
=
(
d
-1
)
*
24
176
local
wd
=
os
.
weekday
(
d
,
m
,
y
)
177
local
weekend
=
wd
=
=
1
or
wd
=
=
7
178
if
not
weekend
then
179
-- okay
180
elseif
mark
=
=
1
then
181
context
(
"
draw (%s,%s) -- (%s,%s) ;
"
,
xoffset
,
-17
.
5
,
xoffset
,
-32
.
5
)
182
context
(
"
draw (%s,%s) -- (%s,%s) ;
"
,
xoffset
+
24
,
-17
.
5
,
xoffset
+
24
,
-32
.
5
)
183
elseif
mark
=
=
2
then
184
context
(
"
draw (%s,%s) -- (%s,%s) ;
"
,
xoffset
,
-17
.
5
,
xoffset
+
24
,
-17
.
5
)
185
context
(
"
draw (%s,%s) -- (%s,%s) ;
"
,
xoffset
,
-32
.
5
,
xoffset
+
24
,
-32
.
5
)
186
elseif
mark
=
=
3
then
187
context
(
"
draw unitsquare xysized (%s,%s) shifted (%s,%s) ;
"
,
24
,
15
,
xoffset
,
-32
.
5
)
188
end
189
context
(
[
[
draw
textext
(
"
%s
"
)
shifted
(
%
s
,
%
s
)
;
]
]
,
d
,
xoffset
+
12
,
-25
)
190
if
day
then
191
for
h
=
0
,
23
do
192
local
hours
=
day
.
hours
193
if
hours
then
194
local
hour
=
hours
[
h
]
195
if
hour
then
196
local
a
=
0
197
local
n
=
0
198
local
m
=
0
199
for
minute
,
d
in
next
,
hour
do
200
local
v
=
d
[
where
]
201
if
v
then
202
a
=
a
+
v
203
n
=
n
+
1
204
if
v
>
m
then
205
m
=
v
206
end
207
end
208
end
209
if
n
>
0
then
210
a
=
a
/
n
211
else
212
a
=
0
213
end
214
local
dx
=
xoffset
+
h
215
local
dy
=
a
/
scale
216
local
dm
=
m
/
scale
217
context
(
"
draw (%s,%s) -- (%s,%s) withcolor %s ;
"
,
218
dx
,
0
,
dx
,
dy
,
weekend
and
"
darkmagenta
"
or
"
darkblue
"
)
219
context
(
"
draw (%s,%s) -- (%s,%s) withcolor %s ;
"
,
220
dx
,
dy
,
dx
,
dm
,
"
darkred
"
)
221
end
222
end
223
end
224
end
225
end
226
for
d
=
0
,
30
do
227
local
xoffset
=
d
*
24
228
context
(
"
draw (%s,%s) -- (%s,%s) withcolor darkgray ;
"
,
xoffset
+
0
,
0
,
xoffset
+
0
,
-10
)
229
context
(
"
draw (%s,%s) -- (%s,%s) withcolor darkgray ;
"
,
xoffset
+
6
,
0
,
xoffset
+
6
,
-2
.
5
)
230
context
(
"
draw (%s,%s) -- (%s,%s) withcolor darkgray ;
"
,
xoffset
+
12
,
0
,
xoffset
+
12
,
-5
)
231
context
(
"
draw (%s,%s) -- (%s,%s) withcolor darkgray ;
"
,
xoffset
+
18
,
0
,
xoffset
+
18
,
-2
.
5
)
232
end
233
local
xoffset
=
31
*
24
234
context
(
"
draw (%s,%s) -- (%s,%s) withcolor darkgray ;
"
,
xoffset
,
0
,
xoffset
,
-10
)
235
end
236 237
for
i
=
0
,
abstemp
,
5
do
238
context
(
[
[
draw
textext
.
lft
(
"
%s
"
)
shifted
(
%
s
,
%
s
)
;
]
]
,
i
,
-10
,
i
/
scale
)
239
context
(
"
draw (%s,%s) -- (%s,%s) withcolor .2white ;
"
,
0
,
i
/
scale
,
31
*
24
,
i
/
scale
)
240
end
241 242
context
(
[
[
draw
textext
(
"
\strut\month{%s}\enspace%s\enspace:\enspace%s
"
)
shifted
(
%
s
,
%
s
)
;
]
]
,
m
,
y
,
where
,
31
*
24
/
2
,
-50
)
243
context
(
[
[
draw
textext
.
lft
(
"
\textdegree{}C
"
)
shifted
(
%
s
,
%
s
)
;
]
]
,
-10
,
-25
)
244 245
context
(
"
currentpicture := currentpicture xsized TextWidth
"
)
;
246 247
context
.
stopMPcode
(
)
248
context
.
stoplinecorrection
(
)
249
-- context.stopMPpage()
250
end
251 252
context
.
stoptitle
(
)
253 254
end
255 256
end
257 258
end
259 260
end
261 262
\stopluacode
263 264
\continueifinputfile
{
s
-
evohome
.
mkiv
}
265 266
\usemodule
[
art
-
0
1
]
267 268
\setuplayout
269
[
article
]
270
[
footer
=
0
cm
,
271
header
=
1
cm
,
272
topspace
=
5
mm
,
273
bottomspace
=
5
mm
]
274 275
\starttext
276 277
\startluacode
278 279
-- os.execute([[mtxrun --script evohome --collect --presets=c:/data/develop/domotica/code/evohome-presets.lua]])
280 281
-- local specification = {
282
-- year = 2017,
283
-- -- month = 11,
284
-- presets = "c:/data/develop/domotica/evohome/evohome-presets.lua",
285
-- }
286 287
-- moduledata.evohome.status (specification)
288
-- moduledata.evohome.history(specification)
289 290
local
specification
=
{
291
year
=
2018
,
292
-- month = 11,
293
presets
=
"
c:/data/develop/domotica/evohome/evohome-presets.lua
"
,
294
}
295 296
-- moduledata.evohome.status (specification)
297
moduledata
.
evohome
.
history
(
specification
)
298 299
\stopluacode
300 301
\stoptext
302