From 0f2dbec5f298daeae83ce3be36cf0136cf977105 Mon Sep 17 00:00:00 2001 From: Wolfgang Ludger Hottgenroth Date: Tue, 10 Aug 2021 18:10:11 +0200 Subject: [PATCH] changes --- secondDbSteps.r | 54 +++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/secondDbSteps.r b/secondDbSteps.r index 1a8eb67..6b64863 100644 --- a/secondDbSteps.r +++ b/secondDbSteps.r @@ -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) + +