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 | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 31 | print( "Reading commmand-line args." ) |
| 32 | args <- commandArgs( trailingOnly=TRUE ) |
| 33 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 34 | # ---------------- |
| 35 | # Import Libraries |
| 36 | # ---------------- |
| 37 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 38 | print( "Importing libraries." ) |
| 39 | library( ggplot2 ) |
| 40 | library( reshape2 ) |
| 41 | library( RPostgreSQL ) # For databases |
| 42 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 43 | # ------------------- |
| 44 | # Check CLI Arguments |
| 45 | # ------------------- |
| 46 | |
| 47 | print( "Verifying CLI args." ) |
| 48 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 49 | if ( is.na( args[ 8 ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 50 | |
| 51 | print( paste( "Usage: Rscript SCPFInstalledIntentsFlows", |
| 52 | "<has-flowObj>", |
| 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 | fileFlowObjModifier <- "" |
| 72 | sqlFlowObjModifier <- "" |
| 73 | chartTitle <- "Number of Installed Intents & Flows" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 74 | |
| 75 | if ( args[ 1 ] == "y" ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 76 | fileFlowObjModifier <- "_flowObj" |
| 77 | sqlFlowObjModifier <- "fobj_" |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 78 | chartTitle <- "Number of Installed Intents & Flows\n with Flow Objectives" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 81 | outputFile <- paste( args[ 8 ], |
| 82 | args[ 6 ], |
| 83 | fileFlowObjModifier, |
| 84 | "_", |
| 85 | args[ 7 ], |
| 86 | "_errGraph.jpg", |
| 87 | sep="" ) |
| 88 | |
| 89 | # ------------------ |
| 90 | # SQL Initialization |
| 91 | # ------------------ |
| 92 | |
| 93 | print( "Initializing SQL" ) |
| 94 | |
| 95 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 96 | dbname = "onostest", |
| 97 | host = args[ 2 ], |
| 98 | port = strtoi( args[ 3 ] ), |
| 99 | user = args[ 4 ], |
| 100 | password = args[ 5 ] ) |
| 101 | |
| 102 | # ------------------------------- |
| 103 | # Scaling Max Intents SQL Command |
| 104 | # ------------------------------- |
| 105 | |
| 106 | print( "Scaling Max Intents SQL Command" ) |
| 107 | |
| 108 | command <- paste( "SELECT * FROM max_intents_", |
| 109 | sqlFlowObjModifier, |
| 110 | "tests WHERE branch = '", |
| 111 | args[ 7 ], |
| 112 | "' AND date IN ( SELECT MAX( date ) FROM max_intents_", |
| 113 | sqlFlowObjModifier, |
| 114 | "tests WHERE branch = '", |
| 115 | args[ 7 ], |
| 116 | "' ) ", |
| 117 | sep="" ) |
| 118 | |
| 119 | print( "Sending SQL command:" ) |
| 120 | print( command ) |
| 121 | fileData <- dbGetQuery( con, command ) |
| 122 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 123 | # ********************************************************** |
| 124 | # STEP 2: Organize data. |
| 125 | # ********************************************************** |
| 126 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 127 | print( "**********************************************************" ) |
| 128 | print( "STEP 2: Organize Data." ) |
| 129 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 130 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 131 | # ------------ |
| 132 | # Data Sorting |
| 133 | # ------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 134 | |
| 135 | print( "Sorting data." ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 136 | |
| 137 | avgs <- c( fileData[ 'max_intents_ovs' ], |
| 138 | fileData[ 'max_flows_ovs' ] ) |
| 139 | |
| 140 | # -------------------- |
| 141 | # Construct Data Frame |
| 142 | # -------------------- |
| 143 | |
| 144 | print( "Constructing Data Frame" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 145 | |
| 146 | dataFrame <- melt( avgs ) |
| 147 | dataFrame$scale <- fileData$scale |
| 148 | |
| 149 | colnames( dataFrame ) <- c( "ms", "type", "scale" ) |
| 150 | |
| 151 | dataFrame$type <- as.character( dataFrame$type ) |
| 152 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 153 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 154 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 155 | |
| 156 | print( "Data Frame Results:" ) |
| 157 | print( dataFrame ) |
| 158 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 159 | # ********************************************************** |
| 160 | # STEP 3: Generate graphs. |
| 161 | # ********************************************************** |
| 162 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 163 | print( "**********************************************************" ) |
| 164 | print( "STEP 3: Generate Graph." ) |
| 165 | print( "**********************************************************" ) |
| 166 | |
| 167 | # ------------------ |
| 168 | # Generate Main Plot |
| 169 | # ------------------ |
| 170 | |
| 171 | print( "Creating main plot." ) |
| 172 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 173 | y = ms, |
| 174 | fill = type ) ) |
| 175 | |
| 176 | # ------------------------------ |
| 177 | # Fundamental Variables Assigned |
| 178 | # ------------------------------ |
| 179 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 180 | print( "Generating fundamental graph data." ) |
| 181 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 182 | barWidth <- 1.3 |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 183 | 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] | 184 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 185 | xLabel <- xlab( "Scale" ) |
| 186 | yLabel <- ylab( "Max Number of Intents/Flow Rules" ) |
| 187 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 188 | imageWidth <- 15 |
| 189 | imageHeight <- 10 |
| 190 | imageDPI <- 200 |
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 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 193 | legend.position = "bottom", |
| 194 | legend.text = element_text( size=22 ), |
| 195 | legend.title = element_blank(), |
| 196 | legend.key.size = unit( 1.5, 'lines' ) ) |
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 | colors <- scale_fill_manual( values = c( "#F77670", |
| 199 | "#619DFA" ) ) |
| 200 | |
| 201 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 202 | title <- ggtitle( chartTitle ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 203 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 204 | fundamentalGraphData <- mainPlot + |
| 205 | xScaleConfig + |
| 206 | xLabel + |
| 207 | yLabel + |
| 208 | fillLabel + |
| 209 | theme + |
| 210 | wrapLegend + |
| 211 | title + |
| 212 | colors |
| 213 | |
| 214 | # --------------------------- |
| 215 | # Generating Bar Graph Format |
| 216 | # --------------------------- |
| 217 | |
| 218 | print( "Generating bar graph." ) |
| 219 | |
| 220 | barGraphFormat <- geom_bar( stat = "identity", |
| 221 | position = position_dodge(), |
| 222 | width = barWidth ) |
| 223 | |
| 224 | values <- geom_text( aes( x = dataFrame$scale, |
| 225 | y = dataFrame$ms + 0.015 * max( dataFrame$ms ), |
| 226 | label = format( dataFrame$ms, |
| 227 | digits=3, |
| 228 | big.mark = ",", |
| 229 | scientific = FALSE ) ), |
| 230 | size = 5.2, |
| 231 | fontface = "bold", |
| 232 | position = position_dodge( width = 1.25 ) ) |
| 233 | |
| 234 | result <- fundamentalGraphData + |
| 235 | barGraphFormat + |
| 236 | values |
| 237 | |
| 238 | # ----------------------- |
| 239 | # Exporting Graph to File |
| 240 | # ----------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 241 | |
| 242 | print( paste( "Saving bar chart to", outputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 243 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 244 | ggsave( outputFile, |
| 245 | width = imageWidth, |
| 246 | height = imageHeight, |
| 247 | dpi = imageDPI ) |
| 248 | |
| 249 | print( paste( "[SUCCESS] Successfully wrote bar chart out to", outputFile ) ) |