with loop but not fine

This commit is contained in:
2021-08-09 23:24:42 +02:00
parent 6d4eeab42e
commit 5246793f6a

View File

@ -1,16 +1,27 @@
library(DBI)
library(tidyr)
library(dplyr)
library(lubridate)
library(R.utils)
con <- dbConnect(RPostgres::Postgres(),
dbname='mainscnt',
host='172.16.10.27',
host='db.mainscnt.eu',
user='wn')
START <- "2021-08-02T14:00:00.0Z"
END <- "2021-08-02T15:00:00.0Z"
START <- "2021-08-03 00:00:00"
INTERVAL <- 3600
for (offset in 0:23) {
startDate <- ymd_hms(START) + INTERVAL * offset
endDate <- startDate + INTERVAL
startStr <- strftime(startDate, "%Y-%m-%d %H:%M:%S", tz="UTC")
endStr <- strftime(endDate, "%Y-%m-%d %H:%M:%S", tz="UTC")
res <-dbSendQuery(con, "select time, location, freq from mainsfrequency where valid=1 and time >= $1 and time < $2")
dbBind(res, list(START, END))
dbBind(res, list(startStr, endStr))
frequencies <- dbFetch(res)
dbClearResult(res)
@ -19,6 +30,7 @@ freq_wide <- frequencies %>%
values_from = freq,
values_fn = mean)
freq_wide$Linz_AT <- freq_wide$Linz_AT + 0.002
THRESHOLD <- 0.5
@ -40,6 +52,7 @@ freq_wide <- freq_wide %>%
na.rm=TRUE))
# print(summary(freq_wide))
print(sum(freq_wide$mad) / length(freq_wide$mad))
printf("start: %s, end: %s, mad/cnt: %f\n", startStr, endStr, sum(freq_wide$mad) / length(freq_wide$mad))
}
dbDisconnect(con)