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( "**********************************************************" ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 30 | database_host = 1 |
| 31 | database_port = 2 |
| 32 | database_u_id = 3 |
| 33 | database_pw = 4 |
| 34 | test_name = 5 |
| 35 | branch_name = 6 |
| 36 | save_directory = 7 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 37 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 38 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | print( "Reading commmand-line args." ) |
| 40 | args <- commandArgs( trailingOnly=TRUE ) |
| 41 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 42 | # ---------------- |
| 43 | # Import Libraries |
| 44 | # ---------------- |
| 45 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 46 | print( "Importing libraries." ) |
| 47 | library( ggplot2 ) |
| 48 | library( reshape2 ) |
| 49 | library( RPostgreSQL ) # For databases |
| 50 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 51 | # ------------------- |
| 52 | # Check CLI Arguments |
| 53 | # ------------------- |
| 54 | |
| 55 | print( "Verifying CLI args." ) |
| 56 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 57 | if ( is.na( args[ save_directory ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 58 | |
| 59 | print( paste( "Usage: Rscript SCPFswitchLat", |
| 60 | "<database-host>", |
| 61 | "<database-port>", |
| 62 | "<database-user-id>", |
| 63 | "<database-password>", |
| 64 | "<test-name>", |
| 65 | "<branch-name>", |
| 66 | "<directory-to-save-graphs>", |
| 67 | sep=" ") ) |
| 68 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 69 | quit( status = 1 ) # basically exit(), but in R |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 72 | # ----------------- |
| 73 | # Create File Names |
| 74 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 75 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 76 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 77 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 78 | errBarOutputFileUp <- paste( args[ save_directory ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 79 | "SCPFswitchLat_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 80 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 81 | "_UpErrBarWithStack.jpg", |
| 82 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 83 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 84 | errBarOutputFileDown <- paste( args[ save_directory ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 85 | "SCPFswitchLat_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 86 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 87 | "_DownErrBarWithStack.jpg", |
| 88 | sep="" ) |
| 89 | # ------------------ |
| 90 | # SQL Initialization |
| 91 | # ------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 92 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 93 | print( "Initializing SQL" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 94 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 95 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 96 | dbname = "onostest", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 97 | host = args[ database_host ], |
| 98 | port = strtoi( args[ database_port ] ), |
| 99 | user = args[ database_u_id ], |
| 100 | password = args[ database_pw ] ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 101 | |
| 102 | # -------------------------- |
| 103 | # Switch Latency SQL Command |
| 104 | # -------------------------- |
| 105 | |
| 106 | print( "Generating Switch Latency SQL Command" ) |
| 107 | |
| 108 | command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 109 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 110 | "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 111 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 112 | "' )", |
| 113 | sep="" ) |
| 114 | |
| 115 | print( "Sending SQL command:" ) |
| 116 | print( command ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 117 | |
| 118 | fileData <- dbGetQuery( con, command ) |
| 119 | |
| 120 | # ********************************************************** |
| 121 | # STEP 2: Organize data. |
| 122 | # ********************************************************** |
| 123 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 124 | print( "**********************************************************" ) |
| 125 | print( "STEP 2: Organize Data." ) |
| 126 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 127 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 128 | # ------------------------------- |
| 129 | # Switch Up Averages Data Sorting |
| 130 | # ------------------------------- |
| 131 | |
| 132 | print( "Sorting data for Switch Up Averages." ) |
| 133 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 134 | requiredColumns <- c( "up_device_to_graph_avg", |
| 135 | "role_reply_to_device_avg", |
| 136 | "role_request_to_role_reply_avg", |
| 137 | "feature_reply_to_role_request_avg", |
| 138 | "tcp_to_feature_reply_avg" ) |
| 139 | |
| 140 | tryCatch( upAvgs <- c( fileData[ requiredColumns] ), |
| 141 | error = function( e ) { |
| 142 | print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." ) |
| 143 | print( "Required columns: " ) |
| 144 | print( requiredColumns ) |
| 145 | print( "Actual columns: " ) |
| 146 | print( names( fileData ) ) |
| 147 | print( "Error dump:" ) |
| 148 | print( e ) |
| 149 | quit( status = 1 ) |
| 150 | } |
| 151 | ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 152 | |
| 153 | # ------------------------------ |
| 154 | # Switch Up Construct Data Frame |
| 155 | # ------------------------------ |
| 156 | |
| 157 | print( "Constructing Switch Up data frame." ) |
| 158 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 159 | upAvgsData <- melt( upAvgs ) |
| 160 | upAvgsData$scale <- fileData$scale |
| 161 | upAvgsData$up_std <- fileData$up_std |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 162 | upAvgsData <- na.omit( upAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 163 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 164 | colnames( upAvgsData ) <- c( "ms", |
| 165 | "type", |
| 166 | "scale", |
| 167 | "stds" ) |
| 168 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 169 | upAvgsData$type <- as.character( upAvgsData$type ) |
| 170 | upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) ) |
| 171 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 172 | sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] + |
| 173 | fileData[ 'role_reply_to_device_avg' ] + |
| 174 | fileData[ 'role_request_to_role_reply_avg' ] + |
| 175 | fileData[ 'feature_reply_to_role_request_avg' ] + |
| 176 | fileData[ 'tcp_to_feature_reply_avg' ] |
| 177 | |
| 178 | print( "Up Averages Results:" ) |
| 179 | print( upAvgsData ) |
| 180 | |
| 181 | # --------------------------------- |
| 182 | # Switch Down Averages Data Sorting |
| 183 | # --------------------------------- |
| 184 | |
| 185 | print( "Sorting data for Switch Down Averages." ) |
| 186 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 187 | requiredColumns <- c( "down_device_to_graph_avg", |
| 188 | "ack_to_device_avg", |
| 189 | "fin_ack_to_ack_avg" ) |
| 190 | |
| 191 | tryCatch( downAvgs <- c( fileData[ requiredColumns] ), |
| 192 | error = function( e ) { |
| 193 | print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." ) |
| 194 | print( "Required columns: " ) |
| 195 | print( requiredColumns ) |
| 196 | print( "Actual columns: " ) |
| 197 | print( names( fileData ) ) |
| 198 | print( "Error dump:" ) |
| 199 | print( e ) |
| 200 | quit( status = 1 ) |
| 201 | } |
| 202 | ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 203 | |
| 204 | # -------------------------------- |
| 205 | # Switch Down Construct Data Frame |
| 206 | # -------------------------------- |
| 207 | |
| 208 | print( "Constructing Switch Down data frame." ) |
| 209 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 210 | downAvgsData <- melt( downAvgs ) |
| 211 | downAvgsData$scale <- fileData$scale |
| 212 | downAvgsData$down_std <- fileData$down_std |
| 213 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 214 | colnames( downAvgsData ) <- c( "ms", |
| 215 | "type", |
| 216 | "scale", |
| 217 | "stds" ) |
| 218 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 219 | downAvgsData$type <- as.character( downAvgsData$type ) |
| 220 | downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) ) |
| 221 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 222 | downAvgsData <- na.omit( downAvgsData ) |
| 223 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 224 | sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] + |
| 225 | fileData[ 'ack_to_device_avg' ] + |
| 226 | fileData[ 'fin_ack_to_ack_avg' ] |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 227 | |
| 228 | print( "Down Averages Results:" ) |
| 229 | print( downAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 230 | |
| 231 | # ********************************************************** |
| 232 | # STEP 3: Generate graphs. |
| 233 | # ********************************************************** |
| 234 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 235 | print( "**********************************************************" ) |
| 236 | print( "STEP 3: Generate Graph." ) |
| 237 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 238 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 239 | # ------------------------------------ |
| 240 | # Initialize Variables For Both Graphs |
| 241 | # ------------------------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 242 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 243 | print( "Initializing variables used in both graphs." ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 244 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 245 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graphs |
| 246 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 247 | xLabel <- xlab( "Scale" ) |
| 248 | yLabel <- ylab( "Latency (ms)" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 249 | imageWidth <- 15 |
| 250 | imageHeight <- 10 |
| 251 | imageDPI <- 200 |
| 252 | errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 ) |
| 253 | barWidth <- 1 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 254 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 255 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 256 | legend.position = "bottom", |
| 257 | legend.text = element_text( size = 22 ), |
| 258 | legend.title = element_blank(), |
| 259 | legend.key.size = unit( 1.5, 'lines' ) ) |
| 260 | |
| 261 | # ---------------------------- |
| 262 | # Switch Up Generate Main Plot |
| 263 | # ---------------------------- |
| 264 | |
| 265 | print( "Creating main plot (Switch Up Latency)." ) |
| 266 | |
| 267 | mainPlot <- ggplot( data = upAvgsData, aes( x = scale, |
| 268 | y = ms, |
| 269 | fill = type, |
| 270 | ymin = fileData[ 'up_end_to_end_avg' ], |
| 271 | ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
| 272 | |
| 273 | # ---------------------------------------- |
| 274 | # Switch Up Fundamental Variables Assigned |
| 275 | # ---------------------------------------- |
| 276 | |
| 277 | print( "Generating fundamental graph data (Switch Up Latency)." ) |
| 278 | |
| 279 | title <- ggtitle( "Switch Up Latency" ) |
| 280 | |
| 281 | fundamentalGraphData <- mainPlot + |
| 282 | xScaleConfig + |
| 283 | xLabel + |
| 284 | yLabel + |
| 285 | theme + |
| 286 | title |
| 287 | |
| 288 | # ------------------------------------- |
| 289 | # Switch Up Generating Bar Graph Format |
| 290 | # ------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 291 | |
| 292 | print( "Generating bar graph with error bars (Switch Up Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 293 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 294 | barGraphFormat <- geom_bar( stat = "identity", width = barWidth ) |
| 295 | errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor ) |
| 296 | |
| 297 | barGraphValues <- geom_text( aes( x = upAvgsData$scale, |
| 298 | y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ), |
| 299 | label = format( sumOfUpAvgs, |
| 300 | digits = 3, |
| 301 | big.mark = ",", |
| 302 | scientific = FALSE ) ), |
| 303 | size = 7.0, |
| 304 | fontface = "bold" ) |
| 305 | |
| 306 | wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) ) |
| 307 | |
| 308 | result <- fundamentalGraphData + |
| 309 | barGraphFormat + |
| 310 | errorBarFormat + |
| 311 | barGraphValues + |
| 312 | wrapLegend |
| 313 | |
| 314 | # --------------------------------- |
| 315 | # Switch Up Exporting Graph to File |
| 316 | # --------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 317 | |
| 318 | print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 319 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 320 | tryCatch( ggsave( errBarOutputFileUp, |
| 321 | width = imageWidth, |
| 322 | height = imageHeight, |
| 323 | dpi = imageDPI ), |
| 324 | error = function( e ){ |
| 325 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 326 | print( e ) |
| 327 | quit( status = 1 ) |
| 328 | } |
| 329 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 330 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 331 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) ) |
| 332 | |
| 333 | # ------------------------------ |
| 334 | # Switch Down Generate Main Plot |
| 335 | # ------------------------------ |
| 336 | |
| 337 | print( "Creating main plot (Switch Down Latency)." ) |
| 338 | |
| 339 | mainPlot <- ggplot( data = downAvgsData, aes( x = scale, |
| 340 | y = ms, |
| 341 | fill = type, |
| 342 | ymin = fileData[ 'down_end_to_end_avg' ], |
| 343 | ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 344 | |
| 345 | # ------------------------------------------ |
| 346 | # Switch Down Fundamental Variables Assigned |
| 347 | # ------------------------------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 348 | |
| 349 | print( "Generating fundamental graph data (Switch Down Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 350 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 351 | colors <- scale_fill_manual( values=c( "#F77670", # Red |
| 352 | "#619DFA", # Blue |
| 353 | "#18BA48" ) ) # Green |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 354 | |
| 355 | title <- ggtitle( "Switch Down Latency" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 356 | |
| 357 | fundamentalGraphData <- mainPlot + |
| 358 | xScaleConfig + |
| 359 | xLabel + |
| 360 | yLabel + |
| 361 | theme + |
| 362 | title |
| 363 | |
| 364 | # --------------------------------------- |
| 365 | # Switch Down Generating Bar Graph Format |
| 366 | # --------------------------------------- |
| 367 | |
| 368 | print( "Generating bar graph with error bars (Switch Down Latency)." ) |
| 369 | barGraphFormat <- geom_bar( stat = "identity", width = barWidth ) |
| 370 | errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor ) |
| 371 | |
| 372 | barGraphValues <- geom_text( aes( x = downAvgsData$scale, |
| 373 | y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ), |
| 374 | label = format( sumOfDownAvgs, |
| 375 | digits = 3, |
| 376 | big.mark = ",", |
| 377 | scientific = FALSE ) ), |
| 378 | size = 7.0, |
| 379 | fontface = "bold" ) |
| 380 | |
| 381 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
| 382 | |
| 383 | result <- fundamentalGraphData + |
| 384 | barGraphFormat + |
| 385 | colors + |
| 386 | errorBarFormat + |
| 387 | barGraphValues + |
| 388 | wrapLegend |
| 389 | |
| 390 | # ----------------------------------- |
| 391 | # Switch Down Exporting Graph to File |
| 392 | # ----------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 393 | |
| 394 | print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 395 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 396 | tryCatch( ggsave( errBarOutputFileDown, |
| 397 | width = imageWidth, |
| 398 | height = imageHeight, |
| 399 | dpi = imageDPI ), |
| 400 | error = function( e ){ |
| 401 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 402 | print( e ) |
| 403 | quit( status = 1 ) |
| 404 | } |
| 405 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 406 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 407 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) ) |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 408 | quit( status = 0 ) |