simulation
This commit is contained in:
parent
c1957722c2
commit
307b0e307b
BIN
kalender-t1.xlsx
Normal file
BIN
kalender-t1.xlsx
Normal file
Binary file not shown.
BIN
kalender-t2.xlsx
Normal file
BIN
kalender-t2.xlsx
Normal file
Binary file not shown.
BIN
kalender-t3.xlsx
Normal file
BIN
kalender-t3.xlsx
Normal file
Binary file not shown.
13
r-scripts/data/data.Rproj
Normal file
13
r-scripts/data/data.Rproj
Normal file
@ -0,0 +1,13 @@
|
||||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
41
r-scripts/data/distribution.R
Normal file
41
r-scripts/data/distribution.R
Normal file
@ -0,0 +1,41 @@
|
||||
library(tidyverse, warn.conflicts = FALSE)
|
||||
library(DBI, warn.conflicts = FALSE)
|
||||
library(tidyr, warn.conflicts = FALSE)
|
||||
library(dplyr, warn.conflicts = FALSE)
|
||||
|
||||
HOME <- Sys.getenv("HOME")
|
||||
Sys.setenv(PGHOST = "db.mainscnt.eu",
|
||||
PGDATABASE = "power",
|
||||
PGPORT = 5432,
|
||||
PGUSER = "wn",
|
||||
PGSSLMODE = "verify-ca",
|
||||
PGSSLKEY = paste(HOME, "/keys/psql/wn-postgresql-client-2.key", sep=""),
|
||||
PGSSLCERT = paste(HOME, "/keys/psql/wn-postgresql-client-2.crt", sep=""),
|
||||
PGSSLROOTCERT = paste(HOME, "/keys/psql/postgres-ca.crt", sep=""))
|
||||
|
||||
|
||||
con <- dbConnect(RPostgres::Postgres())
|
||||
|
||||
YEAR <- 2022
|
||||
res <- dbSendQuery(con, "
|
||||
select
|
||||
date_trunc('day', time)::date as day,
|
||||
avg(temperature) as temperature
|
||||
from room_climate_measurement_t
|
||||
where
|
||||
category = 'Outdoor' and
|
||||
location = 'Outdoor' and
|
||||
extract('hour' from time) = 12 and
|
||||
extract('year' from time) = $1
|
||||
group by day
|
||||
order by day
|
||||
")
|
||||
dbBind(res, list(YEAR))
|
||||
distribution <- dbFetch(res)
|
||||
dbClearResult(res)
|
||||
|
||||
g <- ggplot(data = distribution, aes(x = temperature)) +
|
||||
geom_histogram(binwidth = 1)
|
||||
|
||||
print(g)
|
||||
|
BIN
r-scripts/data/distribution.pdf
Normal file
BIN
r-scripts/data/distribution.pdf
Normal file
Binary file not shown.
BIN
simulation/gradient.png
Normal file
BIN
simulation/gradient.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
91
simulation/simulate.py
Normal file
91
simulation/simulate.py
Normal file
@ -0,0 +1,91 @@
|
||||
import png
|
||||
import psycopg
|
||||
import json
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
|
||||
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)
|
20
simulation/t.py
Normal file
20
simulation/t.py
Normal file
@ -0,0 +1,20 @@
|
||||
import png
|
||||
|
||||
width = 2400
|
||||
height = 1000
|
||||
img = []
|
||||
|
||||
for y in range(height):
|
||||
row = ()
|
||||
for x in range(int(width/3)):
|
||||
row = row + (255, 0, 0)
|
||||
for x in range(int(width/3)):
|
||||
row = row + (0, 255, 0)
|
||||
for x in range(int(width/3)):
|
||||
row = row + (0, 0, 255)
|
||||
img.append(row)
|
||||
|
||||
with open('gradient.png', 'wb') as f:
|
||||
w = png.Writer(width, height, greyscale=False)
|
||||
w.write(f, img)
|
||||
|
BIN
simulation/temperature.png
Normal file
BIN
simulation/temperature.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
Loading…
x
Reference in New Issue
Block a user