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 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 110 | latestBuildDate <- fileData$date[1] |
| 111 | |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 112 | # ------------ |
| 113 | # Data Sorting |
| 114 | # ------------ |
| 115 | |
| 116 | print( "Sorting data." ) |
| 117 | |
| 118 | requiredColumns <- c( "avg" ) |
| 119 | |
| 120 | tryCatch( avgs <- c( fileData[ requiredColumns ] ), |
| 121 | error = function( e ) { |
| 122 | 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." ) |
| 123 | print( "Required columns: " ) |
| 124 | print( requiredColumns ) |
| 125 | print( "Actual columns: " ) |
| 126 | print( names( fileData ) ) |
| 127 | print( "Error dump:" ) |
| 128 | print( e ) |
| 129 | quit( status = 1 ) |
| 130 | } |
| 131 | ) |
| 132 | |
| 133 | # -------------------- |
| 134 | # Construct Data Frame |
| 135 | # -------------------- |
| 136 | |
| 137 | print( "Constructing Data Frame" ) |
| 138 | |
| 139 | dataFrame <- melt( avgs ) |
| 140 | dataFrame$scale <- fileData$scale |
| 141 | dataFrame$std <- fileData$std |
| 142 | |
| 143 | colnames( dataFrame ) <- c( "ms", |
| 144 | "type", |
| 145 | "scale", |
| 146 | "std" ) |
| 147 | |
| 148 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 149 | |
| 150 | print( "Data Frame Results:" ) |
| 151 | print( dataFrame ) |
| 152 | |
| 153 | # ********************************************************** |
| 154 | # STEP 3: Generate graphs. |
| 155 | # ********************************************************** |
| 156 | |
| 157 | print( "**********************************************************" ) |
| 158 | print( "STEP 3: Generate Graph." ) |
| 159 | print( "**********************************************************" ) |
| 160 | |
| 161 | # ------------------ |
| 162 | # Generate Main Plot |
| 163 | # ------------------ |
| 164 | |
| 165 | print( "Creating main plot." ) |
| 166 | |
| 167 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 168 | y = ms, |
| 169 | ymin = ms, |
| 170 | ymax = ms + std ) ) |
| 171 | |
| 172 | # ------------------------------ |
| 173 | # Fundamental Variables Assigned |
| 174 | # ------------------------------ |
| 175 | |
| 176 | print( "Generating fundamental graph data." ) |
| 177 | |
| 178 | defaultTextSize() |
| 179 | |
| 180 | barWidth <- 0.9 |
| 181 | |
| 182 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
| 183 | |
| 184 | xLabel <- xlab( "Scale" ) |
| 185 | yLabel <- ylab( "Latency (ms)" ) |
| 186 | fillLabel <- labs( fill="Type" ) |
| 187 | |
| 188 | theme <- graphTheme() |
| 189 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 190 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 191 | |
| 192 | errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 ) |
| 193 | |
| 194 | fundamentalGraphData <- mainPlot + |
| 195 | xScaleConfig + |
| 196 | xLabel + |
| 197 | yLabel + |
| 198 | fillLabel + |
| 199 | theme + |
| 200 | title |
| 201 | |
| 202 | # --------------------------- |
| 203 | # Generating Bar Graph Format |
| 204 | # --------------------------- |
| 205 | |
| 206 | print( "Generating bar graph with error bars." ) |
| 207 | |
| 208 | barGraphFormat <- geom_bar( stat = "identity", |
| 209 | position = position_dodge(), |
| 210 | width = barWidth, |
| 211 | fill = webColor( "purple" ) ) |
| 212 | |
| 213 | errorBarFormat <- geom_errorbar( position = position_dodge(), |
| 214 | width = barWidth, |
| 215 | color = webColor( "darkerGray" ) ) |
| 216 | |
| 217 | values <- geom_text( aes( x=dataFrame$scale, |
| 218 | y=dataFrame$ms + 0.06 * max( dataFrame$ms ), |
| 219 | label = format( dataFrame$ms, |
| 220 | digits=3, |
| 221 | big.mark = ",", |
| 222 | scientific = FALSE ) ), |
| 223 | size = 7.0, |
| 224 | fontface = "bold" ) |
| 225 | |
| 226 | result <- fundamentalGraphData + |
| 227 | barGraphFormat + |
| 228 | errorBarFormat + |
| 229 | values |
| 230 | |
| 231 | # ----------------------- |
| 232 | # Exporting Graph to File |
| 233 | # ----------------------- |
| 234 | |
| 235 | saveGraph( errBarOutputFile ) |