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