blob: f080a4dbd4cfb9614ec07423a7b90182593ac074 [file] [log] [blame]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +00001# Copyright 2017 Open Networking Foundation (ONF)
2#
3# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
4# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
5# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
6#
7# TestON is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 2 of the License, or
10# (at your option) any later version.
11#
12# TestON is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with TestON. If not, see <http://www.gnu.org/licenses/>.
19#
20# If you have any questions, or if you don't understand R,
Jeremy Ronquillob6268842017-10-03 13:02:58 -070021# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000022
23# This is the R script that generates the SCPF front page graphs.
24
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070025
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000026# **********************************************************
27# STEP 1: Data management.
28# **********************************************************
29
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070030print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000031print( "STEP 1: Data management." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070032print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000033
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070034# ----------------
35# Import Libraries
36# ----------------
37
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000038print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL )
42
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070043# -------------------
44# Check CLI Arguments
45# -------------------
46
47print( "Verifying CLI args." )
48
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000049# Command line arguments are read. Args include the database credentials, test name, branch name, and the directory to output files.
50print( "Reading commmand-line args." )
51args <- commandArgs( trailingOnly=TRUE )
52
53# Check if sufficient args are provided.
54if ( is.na( args[ 10 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070055
56 print( paste( "Usage: Rscript testresultgraph.R",
57 "<database-host>",
58 "<database-port>",
59 "<database-user-id>",
60 "<database-password>",
61 "<graph-title>", # part of the output filename as well
62 "<branch-name>", # part of the output filename
63 "<#-dates>", # part of the output filename
64 "<SQL-command>",
65 "<y-axis-title>", # y-axis may be different among other SCPF graphs (ie: batch size, latency, etc. )
66 "<directory-to-save-graph>",
67 sep = " " ) )
68
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000069 q() # basically exit(), but in R
70}
71
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070072# -------------------------------
73# Create Title and Graph Filename
74# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076print( "Creating title of graph" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
78# Title of graph based on command line args.
79title <- args[ 5 ]
80
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070081print( "Creating graph filename." )
82
83# Filenames for the output graph include the testname, branch, and the graph type.
84outputFile <- paste( args[ 10 ],
85 "SCPF_Front_Page_",
86 gsub( " ", "_", args[ 5 ] ),
87 "_",
88 args[ 6 ],
89 "_",
90 args[ 7 ],
91 "-dates_graph.jpg",
92 sep="" )
93
94# ------------------
95# SQL Initialization
96# ------------------
97
98print( "Initializing SQL" )
99con <- dbConnect( dbDriver( "PostgreSQL" ),
100 dbname = "onostest",
101 host = args[ 1 ],
102 port = strtoi( args[ 2 ] ),
103 user = args[ 3 ],
104 password = args[ 4 ] )
105
106print( "Sending SQL command:" )
107print( args[ 8 ] )
108fileData <- dbGetQuery( con, args[ 8 ] )
109
110
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000111# **********************************************************
112# STEP 2: Organize data.
113# **********************************************************
114
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700115print( "**********************************************************" )
116print( "STEP 2: Organize Data." )
117print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000118
119# Create lists c() and organize data into their corresponding list.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700120print( "Combine data retrieved from databases into a list." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000121
122if ( ncol( fileData ) > 1 ){
123 for ( i in 2:ncol( fileData ) ){
124 fileData[ i ] <- fileData[ i - 1 ] + fileData[ i ]
125 }
126}
127
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700128# --------------------
129# Construct Data Frame
130# --------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000131
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700132print( "Constructing data frame from combined data." )
133
134dataFrame <- melt( fileData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000135dataFrame$date <- fileData$date
136
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700137colnames( dataFrame ) <- c( "Legend",
138 "Values" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000139
140# Format data frame so that the data is in the same order as it appeared in the file.
141dataFrame$Legend <- as.character( dataFrame$Legend )
142dataFrame$Legend <- factor( dataFrame$Legend, levels=unique( dataFrame$Legend ) )
143
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700144# Adding a temporary iterative list to the dataFrame so that there are no gaps in-between date numbers.
145dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
146
147dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000148
149print( "Data Frame Results:" )
150print( dataFrame )
151
152# **********************************************************
153# STEP 3: Generate graphs.
154# **********************************************************
155
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700156print( "**********************************************************" )
157print( "STEP 3: Generate Graph." )
158print( "**********************************************************" )
159
160# -------------------
161# Main Plot Generated
162# -------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000163
164print( "Creating main plot." )
165# Create the primary plot here.
166# ggplot contains the following arguments:
167# - data: the data frame that the graph will be based off of
168# - aes: the asthetics of the graph which require:
169# - x: x-axis values (usually iterative, but it will become date # later)
170# - y: y-axis values (usually tests)
171# - color: the category of the colored lines (usually legend of test)
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700172
173mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
174 y = Values,
175 color = Legend ) )
176
177# -------------------
178# Main Plot Formatted
179# -------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000180
181print( "Formatting main plot." )
182
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700183limitExpansion <- expand_limits( y = 0 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000184
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700185maxYDisplay <- max( dataFrame$Values ) * 1.05
186yBreaks <- ceiling( max( dataFrame$Values ) / 10 )
187yScaleConfig <- scale_y_continuous( breaks = seq( 0, maxYDisplay, by = yBreaks ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000188
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700189# ------------------------------
190# Fundamental Variables Assigned
191# ------------------------------
192
193print( "Generating fundamental graph data." )
194
195theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
196xLabel <- xlab( "Build" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000197yLabel <- ylab( args[ 9 ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000198
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700199imageWidth <- 15
200imageHeight <- 10
201imageDPI <- 200
202
203# Set other graph configurations here.
204theme <- theme( axis.text.x = element_blank(),
205 axis.ticks.x = element_blank(),
206 plot.title = element_text( size = 32, face='bold', hjust = 0.5 ),
207 legend.position = "bottom",
208 legend.text = element_text( size=22 ),
209 legend.title = element_blank(),
210 legend.key.size = unit( 1.5, 'lines' ),
211 legend.direction = 'horizontal' )
212
213# Colors used for the lines.
214# Note: graphs that have X lines will use the first X colors in this list.
215colors <- scale_color_manual( values=c( "#111111", # black
216 "#008CFF", # blue
217 "#FF3700", # red
218 "#00E043", # green
219 "#EEB600", # yellow
220 "#E500FF") ) # purple (not used)
221
222wrapLegend <- guides( color = guide_legend( nrow = 2, byrow = TRUE ) )
223title <- ggtitle( title )
224
225fundamentalGraphData <- mainPlot +
226 limitExpansion +
227 yScaleConfig +
228 xLabel +
229 yLabel +
230 theme +
231 colors +
232 wrapLegend +
233 title
234
235# ----------------------------
236# Generating Line Graph Format
237# ----------------------------
238
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000239print( "Generating line graph." )
240
Jeremy Ronquilloe9063762017-10-17 15:36:09 -0700241lineGraphFormat <- geom_line( size = 0.75 )
242pointFormat <- geom_point( size = 1.75 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000243
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700244result <- fundamentalGraphData +
245 lineGraphFormat +
246 pointFormat
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700247
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700248# -----------------------
249# Exporting Graph to File
250# -----------------------
251
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000252print( paste( "Saving result graph to", outputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700253
254ggsave( outputFile,
255 width = imageWidth,
256 height = imageHeight,
257 dpi = imageDPI )
258
259print( paste( "[SUCCESS] Successfully wrote result graph out to", outputFile ) )