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 | # This is the R script that generates the SCPF front page graphs. |
| 24 | |
| 25 | |
| 26 | # ********************************************************** |
| 27 | # STEP 1: Data management. |
| 28 | # ********************************************************** |
| 29 | |
| 30 | # Args 1 through 6 reside in fundamentalGraphData.R |
| 31 | num_dates = 7 |
| 32 | sql_commands = 8 |
| 33 | y_axis = 9 |
| 34 | old_flow = 10 |
| 35 | save_directory = 11 |
| 36 | |
| 37 | print( "**********************************************************" ) |
| 38 | print( "STEP 1: Data management." ) |
| 39 | print( "**********************************************************" ) |
| 40 | |
| 41 | # ---------------- |
| 42 | # Import Libraries |
| 43 | # ---------------- |
| 44 | |
| 45 | print( "Importing libraries." ) |
| 46 | library( ggplot2 ) |
| 47 | library( reshape2 ) |
| 48 | library( RPostgreSQL ) |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 49 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 50 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 51 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 52 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 53 | |
| 54 | # ------------------- |
| 55 | # Check CLI Arguments |
| 56 | # ------------------- |
| 57 | |
| 58 | print( "Verifying CLI args." ) |
| 59 | |
| 60 | args <- commandArgs( trailingOnly=TRUE ) |
| 61 | |
| 62 | # Check if sufficient args are provided. |
| 63 | if ( length( args ) != save_directory ){ |
| 64 | specialArgs <- c( "#-dates", |
| 65 | "SQL-command", |
| 66 | "y-axis-title", |
| 67 | "using-old-flow" ) |
| 68 | usage( "trendSCPF.R", specialArgs ) |
| 69 | quit( status = 1 ) |
| 70 | } |
| 71 | |
| 72 | # ------------------------------- |
| 73 | # Create Title and Graph Filename |
| 74 | # ------------------------------- |
| 75 | |
| 76 | print( "Creating title of graph" ) |
| 77 | |
| 78 | # Title of graph based on command line args. |
| 79 | |
| 80 | title <- args[ graph_title ] |
| 81 | title <- paste( title, if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "" ) |
| 82 | |
| 83 | print( "Creating graph filename." ) |
| 84 | |
| 85 | # Filenames for the output graph include the testname, branch, and the graph type. |
| 86 | outputFile <- paste( args[ save_directory ], |
| 87 | "SCPF_Front_Page_", |
| 88 | gsub( " ", "_", args[ graph_title ] ), |
| 89 | "_", |
| 90 | args[ branch_name ], |
| 91 | "_", |
| 92 | args[ num_dates ], |
| 93 | "-dates", |
| 94 | if( args[ old_flow ] == "y" ) "_OldFlow" else "", |
| 95 | "_graph.jpg", |
| 96 | sep="" ) |
| 97 | |
| 98 | # ------------------ |
| 99 | # SQL Initialization |
| 100 | # ------------------ |
| 101 | |
| 102 | print( "Initializing SQL" ) |
| 103 | con <- initSQL( args[ database_host ], args[ database_port ], args[ database_u_id ], args[ database_pw ] ) |
| 104 | |
| 105 | fileData <- retrieveData( con, args[ sql_commands ] ) |
| 106 | |
| 107 | # ********************************************************** |
| 108 | # STEP 2: Organize data. |
| 109 | # ********************************************************** |
| 110 | |
| 111 | print( "**********************************************************" ) |
| 112 | print( "STEP 2: Organize Data." ) |
| 113 | print( "**********************************************************" ) |
| 114 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 115 | latestBuildDate <- fileData$date[1] |
| 116 | |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 117 | # Create lists c() and organize data into their corresponding list. |
| 118 | print( "Combine data retrieved from databases into a list." ) |
| 119 | |
| 120 | buildNums <- fileData$build |
| 121 | fileData$build <- c() |
Jeremy Ronquillo | 5d9e725 | 2020-01-15 10:35:18 -0800 | [diff] [blame] | 122 | fileData <- subset( fileData, select=-c( date ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 123 | print( fileData ) |
| 124 | |
| 125 | if ( ncol( fileData ) > 1 ){ |
| 126 | for ( i in 2:ncol( fileData ) ){ |
| 127 | fileData[ i ] <- fileData[ i - 1 ] + fileData[ i ] |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
| 132 | # -------------------- |
| 133 | # Construct Data Frame |
| 134 | # -------------------- |
| 135 | |
| 136 | print( "Constructing data frame from combined data." ) |
| 137 | |
| 138 | dataFrame <- melt( fileData ) |
| 139 | dataFrame$date <- fileData$date |
| 140 | |
| 141 | colnames( dataFrame ) <- c( "Legend", |
| 142 | "Values" ) |
| 143 | |
| 144 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 145 | dataFrame$Legend <- as.character( dataFrame$Legend ) |
| 146 | dataFrame$Legend <- factor( dataFrame$Legend, levels=unique( dataFrame$Legend ) ) |
| 147 | dataFrame$build <- buildNums |
| 148 | |
| 149 | # Adding a temporary iterative list to the dataFrame so that there are no gaps in-between date numbers. |
| 150 | dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 151 | |
| 152 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 153 | |
| 154 | print( "Data Frame Results:" ) |
| 155 | print( dataFrame ) |
| 156 | |
| 157 | # ********************************************************** |
| 158 | # STEP 3: Generate graphs. |
| 159 | # ********************************************************** |
| 160 | |
| 161 | print( "**********************************************************" ) |
| 162 | print( "STEP 3: Generate Graph." ) |
| 163 | print( "**********************************************************" ) |
| 164 | |
| 165 | # ------------------- |
| 166 | # Main Plot Generated |
| 167 | # ------------------- |
| 168 | |
| 169 | print( "Creating main plot." ) |
| 170 | # Create the primary plot here. |
| 171 | # ggplot contains the following arguments: |
| 172 | # - data: the data frame that the graph will be based off of |
| 173 | # - aes: the asthetics of the graph which require: |
| 174 | # - x: x-axis values (usually iterative, but it will become date # later) |
| 175 | # - y: y-axis values (usually tests) |
| 176 | # - color: the category of the colored lines (usually legend of test) |
| 177 | |
| 178 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 179 | y = Values, |
| 180 | color = Legend ) ) |
| 181 | |
| 182 | # ------------------- |
| 183 | # Main Plot Formatted |
| 184 | # ------------------- |
| 185 | |
| 186 | print( "Formatting main plot." ) |
| 187 | |
| 188 | limitExpansion <- expand_limits( y = 0 ) |
| 189 | |
| 190 | tickLength <- 3 |
| 191 | breaks <- seq( max( dataFrame$iterative ) %% tickLength, max( dataFrame$iterative ), by = tickLength ) |
| 192 | breaks <- breaks[ which( breaks != 0 ) ] |
| 193 | |
| 194 | maxYDisplay <- max( dataFrame$Values ) * 1.05 |
| 195 | yBreaks <- ceiling( max( dataFrame$Values ) / 10 ) |
| 196 | yScaleConfig <- scale_y_continuous( breaks = seq( 0, maxYDisplay, by = yBreaks ) ) |
| 197 | xScaleConfig <- scale_x_continuous( breaks = breaks, label = rev( dataFrame$build )[ breaks ] ) |
| 198 | |
| 199 | # ------------------------------ |
| 200 | # Fundamental Variables Assigned |
| 201 | # ------------------------------ |
| 202 | |
| 203 | print( "Generating fundamental graph data." ) |
| 204 | |
| 205 | defaultTextSize() |
| 206 | xLabel <- xlab( "Build" ) |
| 207 | yLabel <- ylab( args[ y_axis ] ) |
| 208 | |
| 209 | # Set other graph configurations here. |
| 210 | theme <- graphTheme() |
| 211 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 212 | title <- labs( title = title, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 213 | |
| 214 | # Colors used for the lines. |
| 215 | # Note: graphs that have X lines will use the first X colors in this list. |
| 216 | colors <- scale_color_manual( values=c( webColor( "black" ), # black |
| 217 | webColor( "blue" ), # blue |
| 218 | webColor( "red" ), # red |
| 219 | webColor( "green" ), # green |
| 220 | webColor( "yellow" ), # yellow |
| 221 | webColor( "purple" ) ) ) # purple (not used) |
| 222 | |
| 223 | wrapLegend <- wrapLegend() |
| 224 | |
| 225 | fundamentalGraphData <- mainPlot + |
| 226 | limitExpansion + |
| 227 | xScaleConfig + |
| 228 | yScaleConfig + |
| 229 | xLabel + |
| 230 | yLabel + |
| 231 | theme + |
| 232 | colors + |
| 233 | wrapLegend + |
| 234 | title |
| 235 | |
| 236 | # ---------------------------- |
| 237 | # Generating Line Graph Format |
| 238 | # ---------------------------- |
| 239 | |
| 240 | print( "Generating line graph." ) |
| 241 | |
| 242 | lineGraphFormat <- geom_line( size = 0.75 ) |
| 243 | pointFormat <- geom_point( size = 1.75 ) |
| 244 | |
| 245 | result <- fundamentalGraphData + |
| 246 | lineGraphFormat + |
| 247 | pointFormat |
| 248 | |
| 249 | # ----------------------- |
| 250 | # Exporting Graph to File |
| 251 | # ----------------------- |
| 252 | |
| 253 | saveGraph( outputFile ) # from saveGraph.R |
| 254 | quit( status = 0 ) |