This commit is contained in:
2021-08-10 18:10:11 +02:00
parent 5246793f6a
commit 0f2dbec5f2

View File

@ -4,19 +4,8 @@ library(dplyr)
library(lubridate)
library(R.utils)
con <- dbConnect(RPostgres::Postgres(),
dbname='mainscnt',
host='db.mainscnt.eu',
user='wn')
START <- "2021-08-03 00:00:00"
INTERVAL <- 3600
for (offset in 0:23) {
startDate <- ymd_hms(START) + INTERVAL * offset
endDate <- startDate + INTERVAL
get_freq_df <- function(con, startDate, endDate) {
startStr <- strftime(startDate, "%Y-%m-%d %H:%M:%S", tz="UTC")
endStr <- strftime(endDate, "%Y-%m-%d %H:%M:%S", tz="UTC")
@ -30,8 +19,6 @@ for (offset in 0:23) {
values_from = freq,
values_fn = mean)
freq_wide$Linz_AT <- freq_wide$Linz_AT + 0.002
THRESHOLD <- 0.5
for (colIdx in 2:length(freq_wide)) {
@ -44,15 +31,38 @@ for (offset in 0:23) {
last <- current
}
}
return (freq_wide)
}
con <- dbConnect(RPostgres::Postgres(),
dbname='mainscnt',
host='172.16.10.27',
user='wn')
START <- "2021-08-03 00:00:00"
INTERVAL <- 3600
for (offset in 0:0) {
startDate <- ymd_hms(START) + INTERVAL * offset
endDate <- startDate + INTERVAL
freq_wide <- get_freq_df(con, startDate, endDate)
freq_wide <- freq_wide %>%
rowwise() %>%
mutate(mad = mad(c_across(names(freq_wide)[-1]),
na.rm=TRUE))
# print(summary(freq_wide))
printf("start: %s, end: %s, mad/cnt: %f\n", startStr, endStr, sum(freq_wide$mad) / length(freq_wide$mad))
for (colIdx in 2:length(freq_wide)) {
colName.mean <- paste("mean.w.o.", names(freq_wide)[colIdx], sep="")
colName.diff <- paste(names(freq_wide)[colIdx], ".to.mean", sep="")
freq_wide <- freq_wide %>%
rowwise() %>%
mutate(!!colName.mean := mean(c_across(names(freq_wide)[c(-1, - colIdx)]), na.rm=TRUE)) %>%
mutate(!!colName.diff := abs())
}
# print(summary(freq_wide))
}
dbDisconnect(con)