From f9b98a6306ee5453925cca14075f97b146550357 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 19 May 2022 19:11:07 +0200 Subject: [PATCH] added --- freqdist.R | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 freqdist.R diff --git a/freqdist.R b/freqdist.R new file mode 100644 index 0000000..8e75ade --- /dev/null +++ b/freqdist.R @@ -0,0 +1,44 @@ +library(tidyverse) +library(DBI) + +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") + + +con <- dbConnect(RPostgres::Postgres()) +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 + valid = 1') +freqs <- dbFetch(res) +dbClearResult(res) +dbDisconnect(con) + +freqs <- as_tibble(freqs) +freqs <- freqs %>% + 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") + +# 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)