-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21-jmeter-create-objects-plots.r
64 lines (52 loc) · 2.23 KB
/
21-jmeter-create-objects-plots.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('ggplot2')
require('svglite')
options <- commandArgs(TRUE)
# If not given a file name, assume the input is stdin so the data can be piped in.
if(length(options)==0) {
input_filename <- 'stdin'
}else{
input_filename <- options[1]
}
### Read file passed as command line arg or piped in
# Expected Headers ('label','elapsed',target_columns)
input_file <- file(input_filename)
open(input_file, blocking=TRUE)
df <- read.csv(input_file)
close(input_file)
### Get names of target columns
target_column_names <- setdiff(colnames(df), c('elapsed','label'))
### Plot each
# Given the data, what is our model of elapsed time as predicted by the variable of interest?
make_linear_model <- function(column_label, input_data){
lm_formula <- as.formula(paste('elapsed ~', column_label))
lmodel <- glm(lm_formula, data=input_data, na.action=na.omit)
}
glmodels <- lapply(target_column_names, FUN=make_linear_model, df)
# Create a dot plot with the linear model plotted as a line
make_dot_plot <- function(column_label, input_data){
p <- ggplot(input_data, aes_string(x=column_label, y='elapsed')) +
geom_point(shape=1) +
stat_smooth(method="glm", color="red")
}
dot_plots <- lapply(target_column_names, FUN=make_dot_plot, df)
# Create binned 2d plot to reduce number of points plotted
make_bin_plot <- function(column_label, input_data){
p <- ggplot(input_data, aes_string(x=column_label, y='elapsed')) +
geom_bin2d()
}
bin_plots <- lapply(target_column_names, FUN=make_bin_plot, df)
# render plots to file
for(i in 1:length(dot_plots)){
png_filename <- paste("reports/21-","dot-",bin_plots[[1]]$label$x,".png", sep="")
svg_filename <- paste("reports/21-","dot-",bin_plots[[1]]$label$x,".svg", sep="")
ggsave(png_filename,plot=dot_plots[[i]],device="png")
ggsave(svg_filename,plot=dot_plots[[i]],device="svg")
}
for(i in 1:length(bin_plots)){
png_filename <- paste("reports/21-","bin-",bin_plots[[1]]$label$x,".png", sep="")
svg_filename <- paste("reports/21-","bin-",bin_plots[[1]]$label$x,".svg", sep="")
ggsave(png_filename,plot=bin_plots[[i]],device="png")
ggsave(svg_filename,plot=bin_plots[[i]],device="svg")
}
# write plot objects to build artifacts
save(list=c("dot_plots", "bin_plots"), file="build/object-plots.dat")