121 lines
2.6 KiB
Python
121 lines
2.6 KiB
Python
import png
|
|
import psycopg
|
|
import json
|
|
|
|
# rainbow
|
|
#COLORS = (
|
|
# (128, 0, 0),
|
|
# (130, 40, 40),
|
|
# (141, 83, 59),
|
|
# (153, 102, 117),
|
|
# (153, 102, 169),
|
|
# (128, 0, 128),
|
|
# (101, 0, 155),
|
|
# (72, 0, 225),
|
|
# (4, 0, 208),
|
|
# (0, 68, 220),
|
|
# (1, 114, 226),
|
|
# (1, 159, 232),
|
|
# (11, 175, 162),
|
|
# (23, 179, 77),
|
|
# (0, 212, 28),
|
|
# (0, 255, 0),
|
|
# (128, 255, 0),
|
|
# (200, 255, 0),
|
|
# (255, 255, 0),
|
|
# (255, 219, 0),
|
|
# (255, 182, 0),
|
|
# (255, 146, 0),
|
|
# (255, 109, 0),
|
|
# (255, 73, 0),
|
|
# (255, 0, 0),
|
|
# (255, 0, 128),
|
|
# (255, 105, 180),
|
|
# (255, 0, 255),
|
|
# (168, 0, 185)
|
|
#)
|
|
|
|
COLORS = (
|
|
# (236, 212, 219),
|
|
(155, 132, 159),
|
|
(91, 66, 112),
|
|
(59, 68, 97),
|
|
(36, 46, 72),
|
|
(38, 45, 83),
|
|
(31, 64, 131),
|
|
(29, 86, 103),
|
|
(71, 118, 139),
|
|
(189, 204, 199),
|
|
(139, 170, 163),
|
|
(71, 70, 46),
|
|
(104, 101, 68),
|
|
(112, 126, 94),
|
|
(248, 226, 152),
|
|
(227, 165, 82),
|
|
(212, 116, 75),
|
|
# (228, 162, 178),
|
|
(186, 103, 104),
|
|
(157, 74, 77),
|
|
(195, 41, 54),
|
|
(152, 35, 48),
|
|
(129, 49, 80),
|
|
(49, 22, 26),
|
|
(66, 23, 20)
|
|
)
|
|
|
|
|
|
conn = psycopg.connect("dbname=power")
|
|
with conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute("""
|
|
select
|
|
date_trunc('day', time)::date::varchar as day,
|
|
avg(temperature)::int as temperature
|
|
from room_climate_measurement_t
|
|
where
|
|
category = 'Outdoor' and
|
|
location = 'Outdoor' and
|
|
extract('hour' from time) = 12 and
|
|
extract('year' from time) = 2022
|
|
group by day
|
|
order by day
|
|
""")
|
|
res = cur.fetchall()
|
|
temperatures = [ x[1] for x in res ]
|
|
# print(json.dumps(temperatures))
|
|
conn.close()
|
|
|
|
min_t = min(temperatures)
|
|
max_t = max(temperatures)
|
|
span_t = max_t - min_t
|
|
print(f"{min_t=}, {max_t=}, {span_t=}")
|
|
|
|
temperatures = [ int(x/2) for x in temperatures ]
|
|
min_t = min(temperatures)
|
|
max_t = max(temperatures)
|
|
span_t = max_t - min_t
|
|
print(f"{min_t=}, {max_t=}, {span_t=}")
|
|
|
|
temperatures = [ x - min_t for x in temperatures ]
|
|
min_t = min(temperatures)
|
|
max_t = max(temperatures)
|
|
span_t = max_t - min_t
|
|
print(f"{min_t=}, {max_t=}, {span_t=}")
|
|
|
|
|
|
height = 350
|
|
|
|
img = []
|
|
for i in range(height):
|
|
row = ()
|
|
for t in temperatures:
|
|
for j in range(3):
|
|
row += COLORS[t]
|
|
img.append(row)
|
|
|
|
width = len(temperatures) * 3
|
|
|
|
with open('temperature.png', 'wb') as f:
|
|
w = png.Writer(width, height, greyscale=False)
|
|
w.write(f, img)
|