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", |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 135 | "feature_reply_to_device_avg", |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 136 | "tcp_to_feature_reply_avg" ) |
| 137 | |
| 138 | tryCatch( upAvgs <- c( fileData[ requiredColumns] ), |
| 139 | error = function( e ) { |
| 140 | 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." ) |
| 141 | print( "Required columns: " ) |
| 142 | print( requiredColumns ) |
| 143 | print( "Actual columns: " ) |
| 144 | print( names( fileData ) ) |
| 145 | print( "Error dump:" ) |
| 146 | print( e ) |
| 147 | quit( status = 1 ) |
| 148 | } |
| 149 | ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 150 | |
| 151 | # ------------------------------ |
| 152 | # Switch Up Construct Data Frame |
| 153 | # ------------------------------ |
| 154 | |
| 155 | print( "Constructing Switch Up data frame." ) |
| 156 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 157 | upAvgsData <- melt( upAvgs ) |
| 158 | upAvgsData$scale <- fileData$scale |
| 159 | upAvgsData$up_std <- fileData$up_std |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 160 | upAvgsData <- na.omit( upAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 161 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 162 | colnames( upAvgsData ) <- c( "ms", |
| 163 | "type", |
| 164 | "scale", |
| 165 | "stds" ) |
| 166 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 167 | upAvgsData$type <- as.character( upAvgsData$type ) |
| 168 | upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) ) |
| 169 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 170 | sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] + |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 171 | fileData[ 'feature_reply_to_device_avg' ] + |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 172 | fileData[ 'tcp_to_feature_reply_avg' ] |
| 173 | |
| 174 | print( "Up Averages Results:" ) |
| 175 | print( upAvgsData ) |
| 176 | |
| 177 | # --------------------------------- |
| 178 | # Switch Down Averages Data Sorting |
| 179 | # --------------------------------- |
| 180 | |
| 181 | print( "Sorting data for Switch Down Averages." ) |
| 182 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 183 | requiredColumns <- c( "down_device_to_graph_avg", |
| 184 | "ack_to_device_avg", |
| 185 | "fin_ack_to_ack_avg" ) |
| 186 | |
| 187 | tryCatch( downAvgs <- c( fileData[ requiredColumns] ), |
| 188 | error = function( e ) { |
| 189 | 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." ) |
| 190 | print( "Required columns: " ) |
| 191 | print( requiredColumns ) |
| 192 | print( "Actual columns: " ) |
| 193 | print( names( fileData ) ) |
| 194 | print( "Error dump:" ) |
| 195 | print( e ) |
| 196 | quit( status = 1 ) |
| 197 | } |
| 198 | ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 199 | |
| 200 | # -------------------------------- |
| 201 | # Switch Down Construct Data Frame |
| 202 | # -------------------------------- |
| 203 | |
| 204 | print( "Constructing Switch Down data frame." ) |
| 205 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 206 | downAvgsData <- melt( downAvgs ) |
| 207 | downAvgsData$scale <- fileData$scale |
| 208 | downAvgsData$down_std <- fileData$down_std |
| 209 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 210 | colnames( downAvgsData ) <- c( "ms", |
| 211 | "type", |
| 212 | "scale", |
| 213 | "stds" ) |
| 214 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 215 | downAvgsData$type <- as.character( downAvgsData$type ) |
| 216 | downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) ) |
| 217 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 218 | downAvgsData <- na.omit( downAvgsData ) |
| 219 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 220 | sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] + |
| 221 | fileData[ 'ack_to_device_avg' ] + |
| 222 | fileData[ 'fin_ack_to_ack_avg' ] |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 223 | |
| 224 | print( "Down Averages Results:" ) |
| 225 | print( downAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 226 | |
| 227 | # ********************************************************** |
| 228 | # STEP 3: Generate graphs. |
| 229 | # ********************************************************** |
| 230 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 231 | print( "**********************************************************" ) |
| 232 | print( "STEP 3: Generate Graph." ) |
| 233 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 234 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 235 | # ------------------------------------ |
| 236 | # Initialize Variables For Both Graphs |
| 237 | # ------------------------------------ |
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 | print( "Initializing variables used in both graphs." ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 240 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 241 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graphs |
| 242 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 243 | xLabel <- xlab( "Scale" ) |
| 244 | yLabel <- ylab( "Latency (ms)" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 245 | imageWidth <- 15 |
| 246 | imageHeight <- 10 |
| 247 | imageDPI <- 200 |
| 248 | errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 ) |
| 249 | barWidth <- 1 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 250 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 251 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 252 | legend.position = "bottom", |
| 253 | legend.text = element_text( size = 22 ), |
| 254 | legend.title = element_blank(), |
Jeremy Ronquillo | 94f99dd | 2018-01-05 11:11:27 -0800 | [diff] [blame] | 255 | legend.key.size = unit( 1.5, 'lines' ), |
| 256 | plot.subtitle = element_text( size=16, hjust=1.0 ) ) |
| 257 | |
| 258 | subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 259 | |
| 260 | # ---------------------------- |
| 261 | # Switch Up Generate Main Plot |
| 262 | # ---------------------------- |
| 263 | |
| 264 | print( "Creating main plot (Switch Up Latency)." ) |
| 265 | |
| 266 | mainPlot <- ggplot( data = upAvgsData, aes( x = scale, |
| 267 | y = ms, |
| 268 | fill = type, |
| 269 | ymin = fileData[ 'up_end_to_end_avg' ], |
| 270 | ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
| 271 | |
| 272 | # ---------------------------------------- |
| 273 | # Switch Up Fundamental Variables Assigned |
| 274 | # ---------------------------------------- |
| 275 | |
| 276 | print( "Generating fundamental graph data (Switch Up Latency)." ) |
| 277 | |
Jeremy Ronquillo | 94f99dd | 2018-01-05 11:11:27 -0800 | [diff] [blame] | 278 | title <- labs( title = "Switch Up Latency", subtitle = subtitle ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 279 | |
| 280 | fundamentalGraphData <- mainPlot + |
| 281 | xScaleConfig + |
| 282 | xLabel + |
| 283 | yLabel + |
| 284 | theme + |
| 285 | title |
| 286 | |
| 287 | # ------------------------------------- |
| 288 | # Switch Up Generating Bar Graph Format |
| 289 | # ------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 290 | |
| 291 | print( "Generating bar graph with error bars (Switch Up Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 292 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 293 | barGraphFormat <- geom_bar( stat = "identity", width = barWidth ) |
| 294 | errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor ) |
| 295 | |
| 296 | barGraphValues <- geom_text( aes( x = upAvgsData$scale, |
| 297 | y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ), |
| 298 | label = format( sumOfUpAvgs, |
| 299 | digits = 3, |
| 300 | big.mark = ",", |
| 301 | scientific = FALSE ) ), |
| 302 | size = 7.0, |
| 303 | fontface = "bold" ) |
| 304 | |
| 305 | wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) ) |
| 306 | |
| 307 | result <- fundamentalGraphData + |
| 308 | barGraphFormat + |
| 309 | errorBarFormat + |
| 310 | barGraphValues + |
| 311 | wrapLegend |
| 312 | |
| 313 | # --------------------------------- |
| 314 | # Switch Up Exporting Graph to File |
| 315 | # --------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 316 | |
| 317 | 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] | 318 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 319 | tryCatch( ggsave( errBarOutputFileUp, |
| 320 | width = imageWidth, |
| 321 | height = imageHeight, |
| 322 | dpi = imageDPI ), |
| 323 | error = function( e ){ |
| 324 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 325 | print( e ) |
| 326 | quit( status = 1 ) |
| 327 | } |
| 328 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 329 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 330 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) ) |
| 331 | |
| 332 | # ------------------------------ |
| 333 | # Switch Down Generate Main Plot |
| 334 | # ------------------------------ |
| 335 | |
| 336 | print( "Creating main plot (Switch Down Latency)." ) |
| 337 | |
| 338 | mainPlot <- ggplot( data = downAvgsData, aes( x = scale, |
| 339 | y = ms, |
| 340 | fill = type, |
| 341 | ymin = fileData[ 'down_end_to_end_avg' ], |
| 342 | ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 343 | |
| 344 | # ------------------------------------------ |
| 345 | # Switch Down Fundamental Variables Assigned |
| 346 | # ------------------------------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 347 | |
| 348 | print( "Generating fundamental graph data (Switch Down Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 349 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 350 | colors <- scale_fill_manual( values=c( "#F77670", # Red |
| 351 | "#619DFA", # Blue |
| 352 | "#18BA48" ) ) # Green |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 353 | |
Jeremy Ronquillo | 94f99dd | 2018-01-05 11:11:27 -0800 | [diff] [blame] | 354 | title <- labs( title = "Switch Down Latency", subtitle = subtitle ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 355 | |
| 356 | fundamentalGraphData <- mainPlot + |
| 357 | xScaleConfig + |
| 358 | xLabel + |
| 359 | yLabel + |
| 360 | theme + |
| 361 | title |
| 362 | |
| 363 | # --------------------------------------- |
| 364 | # Switch Down Generating Bar Graph Format |
| 365 | # --------------------------------------- |
| 366 | |
| 367 | print( "Generating bar graph with error bars (Switch Down Latency)." ) |
| 368 | barGraphFormat <- geom_bar( stat = "identity", width = barWidth ) |
| 369 | errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor ) |
| 370 | |
| 371 | barGraphValues <- geom_text( aes( x = downAvgsData$scale, |
| 372 | y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ), |
| 373 | label = format( sumOfDownAvgs, |
| 374 | digits = 3, |
| 375 | big.mark = ",", |
| 376 | scientific = FALSE ) ), |
| 377 | size = 7.0, |
| 378 | fontface = "bold" ) |
| 379 | |
| 380 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
| 381 | |
| 382 | result <- fundamentalGraphData + |
| 383 | barGraphFormat + |
| 384 | colors + |
| 385 | errorBarFormat + |
| 386 | barGraphValues + |
| 387 | wrapLegend |
| 388 | |
| 389 | # ----------------------------------- |
| 390 | # Switch Down Exporting Graph to File |
| 391 | # ----------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 392 | |
| 393 | 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] | 394 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 395 | tryCatch( ggsave( errBarOutputFileDown, |
| 396 | width = imageWidth, |
| 397 | height = imageHeight, |
| 398 | dpi = imageDPI ), |
| 399 | error = function( e ){ |
| 400 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 401 | print( e ) |
| 402 | quit( status = 1 ) |
| 403 | } |
| 404 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 405 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 406 | 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] | 407 | quit( status = 0 ) |