From 8f6d3a859f55583e73c127d138a6b461b242556b Mon Sep 17 00:00:00 2001 From: Chengqi Lu <43133404+luchengqi7@users.noreply.github.com> Date: Tue, 19 Sep 2023 17:34:58 +0200 Subject: [PATCH 1/3] Update kpi_averaging.R --- src/main/R/drtAnalysis/kpi_averaging.R | 44 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/R/drtAnalysis/kpi_averaging.R b/src/main/R/drtAnalysis/kpi_averaging.R index e807bae4..232a4999 100644 --- a/src/main/R/drtAnalysis/kpi_averaging.R +++ b/src/main/R/drtAnalysis/kpi_averaging.R @@ -2,8 +2,8 @@ library(stringr) #####global variables#### -path_to_data <- "runs" - +path_to_data <- "output-folder (specific case with different seeds)" +stats = c("mean","median","sd" ,"max", "min") ##### Collect all folder names#### @@ -40,13 +40,27 @@ for(case_name in names(folders_seeded)){ if(!case_name %in% names(folders_av_averaged_table)){ folders_av_averaged_table[[case_name]] = av_KPI_table }else{ - folders_av_averaged_table[[case_name]] = folders_av_averaged_table[[case_name]]+av_KPI_table + folders_av_averaged_table[[case_name]] = rbind(folders_av_averaged_table[[case_name]],av_KPI_table) } } - folders_av_averaged_table[[case_name]] = folders_av_averaged_table[[case_name]]/length(folders_seeded[[case_name]]) + + + tbl_colnames = c("stat",colnames(folders_av_averaged_table[[case_name]])) + result_tibble = tbl_colnames %>% purrr::map_dfc(setNames, object = list(numeric())) + for(stat in stats){ + func = get(stat) + new_row = c(stat) + for(column in colnames(folders_av_averaged_table[[case_name]])){ + new_row = append(new_row,func(folders_av_averaged_table[[case_name]][[column]])) + } + + result_tibble = rbind(result_tibble,new_row) + } + colnames(result_tibble) = tbl_colnames + folders_av_averaged_table[[case_name]] = result_tibble } @@ -82,13 +96,25 @@ for(case_name in names(folders_seeded)){ if(!case_name %in% names(folders_drt_averaged_table)){ folders_drt_averaged_table[[case_name]] = drt_KPI_table }else{ - folders_drt_averaged_table[[case_name]] = folders_drt_averaged_table[[case_name]]+drt_KPI_table + folders_drt_averaged_table[[case_name]] = rbind(folders_drt_averaged_table[[case_name]],drt_KPI_table) } } + + tbl_colnames = c("stat",colnames(folders_drt_averaged_table[[case_name]])) + result_tibble = tbl_colnames %>% purrr::map_dfc(setNames, object = list(numeric())) + for(stat in stats){ + func = get(stat) + new_row = c(stat) + for(column in colnames(folders_drt_averaged_table[[case_name]])){ + new_row = append(new_row,func(folders_drt_averaged_table[[case_name]][[column]])) + } + + result_tibble = rbind(result_tibble,new_row) + } + colnames(result_tibble) = tbl_colnames - folders_drt_averaged_table[[case_name]] = folders_drt_averaged_table[[case_name]]/length(folders_seeded[[case_name]]) - + folders_drt_averaged_table[[case_name]] = result_tibble } @@ -100,5 +126,5 @@ output_dir_name <- "results_kpi_drt" dir.create(output_dir_name) for(case_name in names(folders_drt_averaged_table)){ - write.table(folders_drt_averaged_table[[case_name]],paste0("results_kpi_drt/result_drt_",case_name,".tsv"),quote = FALSE,row.names = FALSE) -} \ No newline at end of file + write.table(folders_drt_averaged_table[[case_name]],paste0(paste(path_to_data,"result_drt_", sep="/"),case_name,".tsv"),quote = FALSE,row.names = FALSE) +} From 73558fb1024dc65995e3e1f80817a742a496deff Mon Sep 17 00:00:00 2001 From: Chengqi Lu <43133404+luchengqi7@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:36:38 +0200 Subject: [PATCH 2/3] Update kpi_averaging.R Some reformating and minor update --- src/main/R/drtAnalysis/kpi_averaging.R | 106 +++++++++++-------------- 1 file changed, 45 insertions(+), 61 deletions(-) diff --git a/src/main/R/drtAnalysis/kpi_averaging.R b/src/main/R/drtAnalysis/kpi_averaging.R index 232a4999..e6a89ad8 100644 --- a/src/main/R/drtAnalysis/kpi_averaging.R +++ b/src/main/R/drtAnalysis/kpi_averaging.R @@ -1,17 +1,19 @@ #####libraries#### library(stringr) +library(tidyverse) #####global variables#### -path_to_data <- "output-folder (specific case with different seeds)" +path_to_data <- "path/to/data (folder of a specific case, with different seeds)" stats = c("mean","median","sd" ,"max", "min") ##### Collect all folder names#### - folders_list<-list.files(path_to_data,full.names = TRUE) - folders_seeded = list() for(i in 1:length(folders_list)){ + if (endsWith(folders_list[i],".tsv")){ + next + } case_name = tail(str_split(folders_list[i],"-")[[1]],n = 1) @@ -22,109 +24,91 @@ for(i in 1:length(folders_list)){ } } -#####Reading and averaging av tables##### - - -folders_av_averaged_table = list() +######################################### +#####Reading and averaging drt tables#### +folders_drt_averaged_table = list() for(case_name in names(folders_seeded)){ - - - for(folder in folders_seeded[[case_name]]){ files_list<- list.files(paste0(folder,"/analysis-drt-service-quality"),full.names = TRUE) - av_KPI_file <- files_list[grepl(pattern = "av_KPI.tsv",files_list)] - cat("processing ",av_KPI_file," \r\n") - av_KPI_table <- read.delim(av_KPI_file) + drt_KPI_file <- files_list[grepl(pattern = "drt_KPI.tsv",files_list)] + cat("processing ",drt_KPI_file," \r\n") + drt_KPI_table <- read.delim(drt_KPI_file) - if(!case_name %in% names(folders_av_averaged_table)){ - folders_av_averaged_table[[case_name]] = av_KPI_table + if(!case_name %in% names(folders_drt_averaged_table)){ + folders_drt_averaged_table[[case_name]] = drt_KPI_table }else{ - folders_av_averaged_table[[case_name]] = rbind(folders_av_averaged_table[[case_name]],av_KPI_table) + folders_drt_averaged_table[[case_name]] = rbind(folders_drt_averaged_table[[case_name]],drt_KPI_table) } } - - - tbl_colnames = c("stat",colnames(folders_av_averaged_table[[case_name]])) + tbl_colnames = c("stat",colnames(folders_drt_averaged_table[[case_name]])) result_tibble = tbl_colnames %>% purrr::map_dfc(setNames, object = list(numeric())) for(stat in stats){ func = get(stat) new_row = c(stat) - for(column in colnames(folders_av_averaged_table[[case_name]])){ - new_row = append(new_row,func(folders_av_averaged_table[[case_name]][[column]])) + for(column in colnames(folders_drt_averaged_table[[case_name]])){ + new_row = append(new_row,func(folders_drt_averaged_table[[case_name]][[column]])) } result_tibble = rbind(result_tibble,new_row) } colnames(result_tibble) = tbl_colnames - folders_av_averaged_table[[case_name]] = result_tibble + folders_drt_averaged_table[[case_name]] = result_tibble } -print(folders_av_averaged_table) - -#####Write averaged av tables#### - -dir_output_name <- "results_kpi_av" -dir.create(dir_output_name) +print(folders_drt_averaged_table) -for(case_name in names(folders_av_averaged_table)){ - write.table(folders_av_averaged_table[[case_name]],paste0("results_kpi_av/result_av_",case_name,".tsv"),quote = FALSE,row.names = FALSE) +#Write averaged drt tables#### +for(case_name in names(folders_drt_averaged_table)){ + write.table(folders_drt_averaged_table[[case_name]],paste0(path_to_data, "/kpi_summary_drt_", case_name, ".tsv"),quote = FALSE,row.names = FALSE) } -#####Reading and averaging drt tables#### - - - -folders_drt_averaged_table = list() - +######################################### +#####Reading and averaging av tables##### +folders_av_averaged_table = list() for(case_name in names(folders_seeded)){ - - - for(folder in folders_seeded[[case_name]]){ files_list<- list.files(paste0(folder,"/analysis-drt-service-quality"),full.names = TRUE) - drt_KPI_file <- files_list[grepl(pattern = "drt_KPI.tsv",files_list)] - cat("processing ",drt_KPI_file," \r\n") - drt_KPI_table <- read.delim(drt_KPI_file) + av_KPI_file <- files_list[grepl(pattern = "av_KPI.tsv",files_list)] + cat("processing ",av_KPI_file," \r\n") + av_KPI_table <- read.delim(av_KPI_file) - if(!case_name %in% names(folders_drt_averaged_table)){ - folders_drt_averaged_table[[case_name]] = drt_KPI_table + if(!case_name %in% names(folders_av_averaged_table)){ + folders_av_averaged_table[[case_name]] = av_KPI_table }else{ - folders_drt_averaged_table[[case_name]] = rbind(folders_drt_averaged_table[[case_name]],drt_KPI_table) + folders_av_averaged_table[[case_name]] = rbind(folders_av_averaged_table[[case_name]],av_KPI_table) } - } - - tbl_colnames = c("stat",colnames(folders_drt_averaged_table[[case_name]])) + + tbl_colnames = c("stat",colnames(folders_av_averaged_table[[case_name]])) result_tibble = tbl_colnames %>% purrr::map_dfc(setNames, object = list(numeric())) for(stat in stats){ func = get(stat) new_row = c(stat) - for(column in colnames(folders_drt_averaged_table[[case_name]])){ - new_row = append(new_row,func(folders_drt_averaged_table[[case_name]][[column]])) + for(column in colnames(folders_av_averaged_table[[case_name]])){ + new_row = append(new_row,func(folders_av_averaged_table[[case_name]][[column]])) } - result_tibble = rbind(result_tibble,new_row) } colnames(result_tibble) = tbl_colnames - - folders_drt_averaged_table[[case_name]] = result_tibble - + folders_av_averaged_table[[case_name]] = result_tibble } -print(folders_drt_averaged_table) - -#####Write averaged drt tables#### +print(folders_av_averaged_table) -output_dir_name <- "results_kpi_drt" -dir.create(output_dir_name) +#####Write averaged av tables#### +dir_output_name <- "results_kpi_av" +dir.create(dir_output_name) -for(case_name in names(folders_drt_averaged_table)){ - write.table(folders_drt_averaged_table[[case_name]],paste0(paste(path_to_data,"result_drt_", sep="/"),case_name,".tsv"),quote = FALSE,row.names = FALSE) +for(case_name in names(folders_av_averaged_table)){ + write.table(folders_av_averaged_table[[case_name]],paste0(path_to_data, "/kpi_summary_av_",case_name,".tsv"),quote = FALSE,row.names = FALSE) } + + + From e49899820103f9447bc6c073dfa0892ec11e0424 Mon Sep 17 00:00:00 2001 From: Chengqi Lu <43133404+luchengqi7@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:37:35 +0200 Subject: [PATCH 3/3] Update kpi_averaging.R --- src/main/R/drtAnalysis/kpi_averaging.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/R/drtAnalysis/kpi_averaging.R b/src/main/R/drtAnalysis/kpi_averaging.R index e6a89ad8..f4997782 100644 --- a/src/main/R/drtAnalysis/kpi_averaging.R +++ b/src/main/R/drtAnalysis/kpi_averaging.R @@ -102,10 +102,7 @@ for(case_name in names(folders_seeded)){ print(folders_av_averaged_table) -#####Write averaged av tables#### -dir_output_name <- "results_kpi_av" -dir.create(dir_output_name) - +#Write averaged av tables#### for(case_name in names(folders_av_averaged_table)){ write.table(folders_av_averaged_table[[case_name]],paste0(path_to_data, "/kpi_summary_av_",case_name,".tsv"),quote = FALSE,row.names = FALSE) }