This commit is contained in:
Wolfgang Hottgenroth 2022-05-21 15:15:03 +02:00
parent f9b98a6306
commit 23a484eeaf
Signed by: wn
GPG Key ID: 836E9E1192A6B132

View File

@ -1,14 +1,16 @@
library(tidyverse)
library(lubridate, warn.conflicts=FALSE)
library(DBI)
HOME <- Sys.getenv("HOME")
Sys.setenv(PGHOST = "db.mainscnt.eu",
PGDATABASE = "mainscnt",
PGPORT = 5432,
PGUSER = "wn",
PGSSLMODE = "verify-ca",
PGSSLKEY = "/home/wn/keys/psql/wn-postgresql-client-2.pem",
PGSSLCERT = "/home/wn/keys/psql/wn-postgresql-client-2.crt",
PGSSLROOTCERT = "/home/wn/keys/psql/postgres-ca.crt")
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())
@ -16,14 +18,16 @@ res <-dbSendQuery(con,
'select time, freq, location
from mainsfrequency
where time >= \'2022-04-01 00:00:00\' and
time < \'2022-04-05 00:00:00\' and
time < \'2022-05-01 00:00:00\' and
location != \'Nsawam_GH\' and
valid = 1')
freqs <- dbFetch(res)
dbClearResult(res)
dbDisconnect(con)
freqs <- as_tibble(freqs)
freqs <- freqs %>%
freqs <- freqs %>%
filter(freq > 49.6 & freq < 50.4, na.rm=TRUE) %>%
mutate(year = year(time), month = month(time), day = day(time)) %>%
group_by(year, month, day)
@ -31,14 +35,14 @@ freqs <- freqs %>%
# geom_histogram(mapping = aes(x = freq))
# print(p)
#p <- ggplot(data=freqs) +
# geom_boxplot(mapping=aes(group=day,x=time,y=freq), na.rm=TRUE) +
# scale_x_datetime("Date", breaks="1 day") +
# scale_y_continuous("Frequency") +
# theme(axis.text.x=element_text(angle=-90, vjust=0)) +
# labs(title = "Mains Frequency deviation")
p <- ggplot(data=freqs) +
geom_boxplot(mapping=aes(group=day,x=time,y=freq), na.rm=TRUE) +
scale_x_datetime("Date", breaks="1 day") +
scale_y_continuous("Frequency", n.breaks=7) +
theme(axis.text.x=element_text(angle=-90, vjust=0)) +
labs(title = "Mains Frequency deviation")
p <- ggplot(data= freqs) +
geom_freqpoly(mapping = aes(x=freq, color=location))
#p <- ggplot(data= freqs) +
# geom_freqpoly(mapping = aes(x=freq, color=location))
print(p)