Skip to content

Commit

Permalink
Update kpi_averaging.R
Browse files Browse the repository at this point in the history
  • Loading branch information
luchengqi7 committed Sep 19, 2023
1 parent 79b6dfc commit 8f6d3a8
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/main/R/drtAnalysis/kpi_averaging.R
Original file line number Diff line number Diff line change
Expand Up @@ -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####

Expand Down Expand Up @@ -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

}

Expand Down Expand Up @@ -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

}

Expand All @@ -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)
}
write.table(folders_drt_averaged_table[[case_name]],paste0(paste(path_to_data,"result_drt_", sep="/"),case_name,".tsv"),quote = FALSE,row.names = FALSE)
}

0 comments on commit 8f6d3a8

Please sign in to comment.