49 lines
1.6 KiB
R
49 lines
1.6 KiB
R
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 = 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())
|
|
res <-dbSendQuery(con,
|
|
'select time, freq, location
|
|
from mainsfrequency
|
|
where time >= \'2022-04-01 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 %>%
|
|
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)
|
|
|
|
# p = ggplot(data = 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", 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))
|
|
|
|
print(p)
|