Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [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, |
| 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
| 22 | |
| 23 | # ********************************************************** |
| 24 | # STEP 1: Data management. |
| 25 | # ********************************************************** |
| 26 | |
| 27 | print( "**********************************************************" ) |
| 28 | print( "STEP 1: Data management." ) |
| 29 | print( "**********************************************************" ) |
| 30 | |
| 31 | save_directory = 7 |
| 32 | |
| 33 | # Command line arguments are read. |
| 34 | print( "Reading commmand-line args." ) |
| 35 | args <- commandArgs( trailingOnly=TRUE ) |
| 36 | |
| 37 | # ---------------- |
| 38 | # Import Libraries |
| 39 | # ---------------- |
| 40 | |
| 41 | print( "Importing libraries." ) |
| 42 | library( ggplot2 ) |
| 43 | library( reshape2 ) |
| 44 | library( RPostgreSQL ) # For databases |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 45 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 46 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 47 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 48 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 49 | |
| 50 | # ------------------- |
| 51 | # Check CLI Arguments |
| 52 | # ------------------- |
| 53 | |
| 54 | print( "Verifying CLI args." ) |
| 55 | |
| 56 | if ( length( args ) != save_directory ){ |
| 57 | usage( "SCPFhostLat.R" ) |
| 58 | quit( status = 1 ) |
| 59 | } |
| 60 | |
| 61 | # ----------------- |
| 62 | # Create File Names |
| 63 | # ----------------- |
| 64 | |
| 65 | print( "Creating filenames and title of graph." ) |
| 66 | |
| 67 | errBarOutputFile <- paste( args[ save_directory ], |
| 68 | args[ graph_title ], |
| 69 | "_", |
| 70 | args[ branch_name ], |
| 71 | "_errGraph.jpg", |
| 72 | sep="" ) |
| 73 | |
| 74 | chartTitle <- "Host Latency" |
| 75 | # ------------------ |
| 76 | # SQL Initialization |
| 77 | # ------------------ |
| 78 | |
| 79 | print( "Initializing SQL" ) |
| 80 | |
| 81 | con <- initSQL( args[ database_host ], |
| 82 | args[ database_port ], |
| 83 | args[ database_u_id ], |
| 84 | args[ database_pw ] ) |
| 85 | |
| 86 | # ------------------------ |
| 87 | # Host Latency SQL Command |
| 88 | # ------------------------ |
| 89 | |
| 90 | print( "Generating Host Latency SQL Command" ) |
| 91 | |
| 92 | command <- paste( "SELECT * FROM host_latency_tests WHERE branch = '", |
| 93 | args[ branch_name ], |
| 94 | "' AND date IN ( SELECT MAX( date ) FROM host_latency_tests WHERE branch = '", |
| 95 | args[ branch_name ], |
| 96 | "' ) ", |
| 97 | sep = "" ) |
| 98 | |
| 99 | fileData <- retrieveData( con, command ) |
| 100 | |
| 101 | |
| 102 | # ********************************************************** |
| 103 | # STEP 2: Organize data. |
| 104 | # ********************************************************** |
| 105 | |
| 106 | print( "**********************************************************" ) |
| 107 | print( "STEP 2: Organize Data." ) |
| 108 | print( "**********************************************************" ) |
| 109 | |
| 110 | # ------------ |
| 111 | # Data Sorting |
| 112 | # ------------ |
| 113 | |
| 114 | print( "Sorting data." ) |
| 115 | |
| 116 | requiredColumns <- c( "avg" ) |
| 117 | |
| 118 | tryCatch( avgs <- c( fileData[ requiredColumns ] ), |
| 119 | error = function( e ) { |
| 120 | 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." ) |
| 121 | print( "Required columns: " ) |
| 122 | print( requiredColumns ) |
| 123 | print( "Actual columns: " ) |
| 124 | print( names( fileData ) ) |
| 125 | print( "Error dump:" ) |
| 126 | print( e ) |
| 127 | quit( status = 1 ) |
| 128 | } |
| 129 | ) |
| 130 | |
| 131 | # -------------------- |
| 132 | # Construct Data Frame |
| 133 | # -------------------- |
| 134 | |
| 135 | print( "Constructing Data Frame" ) |
| 136 | |
| 137 | dataFrame <- melt( avgs ) |
| 138 | dataFrame$scale <- fileData$scale |
| 139 | dataFrame$std <- fileData$std |
| 140 | |
| 141 | colnames( dataFrame ) <- c( "ms", |
| 142 | "type", |
| 143 | "scale", |
| 144 | "std" ) |
| 145 | |
| 146 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 147 | |
| 148 | print( "Data Frame Results:" ) |
| 149 | print( dataFrame ) |
| 150 | |
| 151 | # ********************************************************** |
| 152 | # STEP 3: Generate graphs. |
| 153 | # ********************************************************** |
| 154 | |
| 155 | print( "**********************************************************" ) |
| 156 | print( "STEP 3: Generate Graph." ) |
| 157 | print( "**********************************************************" ) |
| 158 | |
| 159 | # ------------------ |
| 160 | # Generate Main Plot |
| 161 | # ------------------ |
| 162 | |
| 163 | print( "Creating main plot." ) |
| 164 | |
| 165 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 166 | y = ms, |
| 167 | ymin = ms, |
| 168 | ymax = ms + std ) ) |
| 169 | |
| 170 | # ------------------------------ |
| 171 | # Fundamental Variables Assigned |
| 172 | # ------------------------------ |
| 173 | |
| 174 | print( "Generating fundamental graph data." ) |
| 175 | |
| 176 | defaultTextSize() |
| 177 | |
| 178 | barWidth <- 0.9 |
| 179 | |
| 180 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
| 181 | |
| 182 | xLabel <- xlab( "Scale" ) |
| 183 | yLabel <- ylab( "Latency (ms)" ) |
| 184 | fillLabel <- labs( fill="Type" ) |
| 185 | |
| 186 | theme <- graphTheme() |
| 187 | |
| 188 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel() ) |
| 189 | |
| 190 | errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 ) |
| 191 | |
| 192 | fundamentalGraphData <- mainPlot + |
| 193 | xScaleConfig + |
| 194 | xLabel + |
| 195 | yLabel + |
| 196 | fillLabel + |
| 197 | theme + |
| 198 | title |
| 199 | |
| 200 | # --------------------------- |
| 201 | # Generating Bar Graph Format |
| 202 | # --------------------------- |
| 203 | |
| 204 | print( "Generating bar graph with error bars." ) |
| 205 | |
| 206 | barGraphFormat <- geom_bar( stat = "identity", |
| 207 | position = position_dodge(), |
| 208 | width = barWidth, |
| 209 | fill = webColor( "purple" ) ) |
| 210 | |
| 211 | errorBarFormat <- geom_errorbar( position = position_dodge(), |
| 212 | width = barWidth, |
| 213 | color = webColor( "darkerGray" ) ) |
| 214 | |
| 215 | values <- geom_text( aes( x=dataFrame$scale, |
| 216 | y=dataFrame$ms + 0.06 * max( dataFrame$ms ), |
| 217 | label = format( dataFrame$ms, |
| 218 | digits=3, |
| 219 | big.mark = ",", |
| 220 | scientific = FALSE ) ), |
| 221 | size = 7.0, |
| 222 | fontface = "bold" ) |
| 223 | |
| 224 | result <- fundamentalGraphData + |
| 225 | barGraphFormat + |
| 226 | errorBarFormat + |
| 227 | values |
| 228 | |
| 229 | # ----------------------- |
| 230 | # Exporting Graph to File |
| 231 | # ----------------------- |
| 232 | |
| 233 | saveGraph( errBarOutputFile ) |