Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 1 | # 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 Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 22 | |
| 23 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 24 | # STEP 1: Data management. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 25 | # ********************************************************** |
| 26 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 27 | print( "**********************************************************" ) |
| 28 | print( "STEP 1: Data management." ) |
| 29 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 30 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 31 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 32 | print( "Reading commmand-line args." ) |
| 33 | args <- commandArgs( trailingOnly=TRUE ) |
| 34 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 35 | # ---------------- |
| 36 | # Import Libraries |
| 37 | # ---------------- |
| 38 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | print( "Importing libraries." ) |
| 40 | library( ggplot2 ) |
| 41 | library( reshape2 ) |
| 42 | library( RPostgreSQL ) # For databases |
| 43 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 44 | # ------------------- |
| 45 | # Check CLI Arguments |
| 46 | # ------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 47 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 48 | print( "Verifying CLI args." ) |
| 49 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 50 | if ( is.na( args[ 7 ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 51 | |
| 52 | print( paste( "Usage: Rscript SCPFhostLat", |
| 53 | "<database-host>", |
| 54 | "<database-port>", |
| 55 | "<database-user-id>", |
| 56 | "<database-password>", |
| 57 | "<test-name>", |
| 58 | "<branch-name>", |
| 59 | "<directory-to-save-graphs>", |
| 60 | sep=" " ) ) |
| 61 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 62 | q() # basically exit(), but in R |
| 63 | } |
| 64 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 65 | # ----------------- |
| 66 | # Create File Names |
| 67 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 68 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 69 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 70 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 71 | errBarOutputFile <- paste( args[ 7 ], |
| 72 | args[ 5 ], |
| 73 | "_", |
| 74 | args[ 6 ], |
| 75 | "_errGraph.jpg", |
| 76 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 77 | |
| 78 | chartTitle <- "Host Latency" |
| 79 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 80 | # ------------------ |
| 81 | # SQL Initialization |
| 82 | # ------------------ |
| 83 | |
| 84 | print( "Initializing SQL" ) |
| 85 | |
| 86 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 87 | dbname = "onostest", |
| 88 | host = args[ 1 ], |
| 89 | port = strtoi( args[ 2 ] ), |
| 90 | user = args[ 3 ], |
| 91 | password = args[ 4 ] ) |
| 92 | |
| 93 | # ------------------------ |
| 94 | # Host Latency SQL Command |
| 95 | # ------------------------ |
| 96 | |
| 97 | print( "Generating Host Latency SQL Command" ) |
| 98 | |
| 99 | command <- paste( "SELECT * FROM host_latency_tests WHERE branch = '", |
| 100 | args[ 6 ], |
| 101 | "' AND date IN ( SELECT MAX( date ) FROM host_latency_tests WHERE branch = '", |
| 102 | args[ 6 ], |
| 103 | "' ) ", |
| 104 | sep = "" ) |
| 105 | |
| 106 | print( "Sending SQL command:" ) |
| 107 | print( command ) |
| 108 | |
| 109 | fileData <- dbGetQuery( con, command ) |
| 110 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 111 | |
| 112 | # ********************************************************** |
| 113 | # STEP 2: Organize data. |
| 114 | # ********************************************************** |
| 115 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 116 | print( "**********************************************************" ) |
| 117 | print( "STEP 2: Organize Data." ) |
| 118 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 119 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 120 | # ------------ |
| 121 | # Data Sorting |
| 122 | # ------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 123 | |
| 124 | print( "Sorting data." ) |
| 125 | avgs <- c( fileData[ 'avg' ] ) |
| 126 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 127 | # -------------------- |
| 128 | # Construct Data Frame |
| 129 | # -------------------- |
| 130 | |
| 131 | print( "Constructing Data Frame" ) |
| 132 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 133 | dataFrame <- melt( avgs ) |
| 134 | dataFrame$scale <- fileData$scale |
| 135 | dataFrame$std <- fileData$std |
| 136 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 137 | colnames( dataFrame ) <- c( "ms", |
| 138 | "type", |
| 139 | "scale", |
| 140 | "std" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 141 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 142 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 143 | |
| 144 | print( "Data Frame Results:" ) |
| 145 | print( dataFrame ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 146 | |
| 147 | # ********************************************************** |
| 148 | # STEP 3: Generate graphs. |
| 149 | # ********************************************************** |
| 150 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 151 | print( "**********************************************************" ) |
| 152 | print( "STEP 3: Generate Graph." ) |
| 153 | print( "**********************************************************" ) |
| 154 | |
| 155 | # ------------------ |
| 156 | # Generate Main Plot |
| 157 | # ------------------ |
| 158 | |
| 159 | print( "Creating main plot." ) |
| 160 | |
| 161 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 162 | y = ms, |
| 163 | ymin = ms, |
| 164 | ymax = ms + std ) ) |
| 165 | |
| 166 | # ------------------------------ |
| 167 | # Fundamental Variables Assigned |
| 168 | # ------------------------------ |
| 169 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 170 | print( "Generating fundamental graph data." ) |
| 171 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 172 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 173 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 174 | xLabel <- xlab( "Scale" ) |
| 175 | yLabel <- ylab( "Latency (ms)" ) |
| 176 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 177 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face ='bold' ) ) |
| 178 | title <- ggtitle( chartTitle ) |
| 179 | errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 ) |
| 180 | imageWidth <- 15 |
| 181 | imageHeight <- 10 |
| 182 | imageDPI <- 200 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 183 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 184 | fundamentalGraphData <- mainPlot + |
| 185 | xScaleConfig + |
| 186 | xLabel + |
| 187 | yLabel + |
| 188 | fillLabel + |
| 189 | theme + |
| 190 | title |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 191 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 192 | # --------------------------- |
| 193 | # Generating Bar Graph Format |
| 194 | # --------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 195 | |
| 196 | print( "Generating bar graph with error bars." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 197 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 198 | barWidth <- 0.9 |
| 199 | barGraphFormat <- geom_bar( stat = "identity", |
| 200 | position = position_dodge(), |
| 201 | width = barWidth, |
| 202 | fill = "#A700EF" ) |
| 203 | |
| 204 | errorBarFormat <- geom_errorbar( position = position_dodge(), |
| 205 | width = barWidth, |
| 206 | color = errorBarColor ) |
| 207 | |
| 208 | values <- geom_text( aes( x=dataFrame$scale, |
| 209 | y=dataFrame$ms + 0.06 * max( dataFrame$ms ), |
| 210 | label = format( dataFrame$ms, |
| 211 | digits=3, |
| 212 | big.mark = ",", |
| 213 | scientific = FALSE ) ), |
| 214 | size = 7.0, |
| 215 | fontface = "bold" ) |
| 216 | |
| 217 | result <- fundamentalGraphData + |
| 218 | barGraphFormat + |
| 219 | errorBarFormat + |
| 220 | values |
| 221 | |
| 222 | # ----------------------- |
| 223 | # Exporting Graph to File |
| 224 | # ----------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 225 | |
| 226 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 227 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame^] | 228 | ggsave( errBarOutputFile, |
| 229 | width = imageWidth, |
| 230 | height = imageHeight, |
| 231 | dpi = imageDPI ) |
| 232 | |
| 233 | print( paste( "[SUCCESS] Successfully wrote bar chart out to", errBarOutputFile ) ) |