-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pct_colours.py
49 lines (44 loc) · 1.7 KB
/
test_pct_colours.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Script to spit out a table of colours to show the "tilt" light."""
from power import SolarLights
if __name__ == '__main__':
sl = SolarLights()
data = {
'production': 0.00,
'consumption': 0.00,
'import': 0.00,
'export': None,
'direction': 'import',
'grid': 0.00
}
with open('pct_test.html', 'w') as fp:
fp.write('<html><head></head><body>\n')
fp.write('<table>\n')
for i in range(1, 300, 10):
fp.write('<tr>')
data['production'] = i / 100.
for j in range(1, 300, 10):
data['consumption'] = j / 100.
if data['production'] > data['consumption']:
data['export'] = data['production'] - data['consumption']
data['import'] = 0
data['grid'] = data['export']
data['direction'] = 'export'
pct = data['grid'] / data['production']
else:
data['import'] = data['consumption'] - data['production']
data['export'] = 0
data['grid'] = data['import']
data['direction'] = 'import'
pct = data['grid'] / data['consumption']
sl._data = data
pixel = sl.get_tilt_pixels()[0]
fp.write(
f'<td style="background-color: '
f'rgb({pixel[0]}, {pixel[1]}, {pixel[2]});"'
f' title="{data}">\n'
)
fp.write(f' {round(pct, 2)}%\n')
fp.write('</td>\n')
fp.write('</tr>\n')
fp.write('</table>')
fp.write('</body></html>')