blob: ef2f16b6326f80b317943ec1c75e7c2c2b117cf7 [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# 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
31num_dates = 7
32sql_commands = 8
33y_axis = 9
34old_flow = 10
35save_directory = 11
36
37print( "**********************************************************" )
38print( "STEP 1: Data management." )
39print( "**********************************************************" )
40
41# ----------------
42# Import Libraries
43# ----------------
44
45print( "Importing libraries." )
46library( ggplot2 )
47library( reshape2 )
48library( RPostgreSQL )
Devin Lim324806b2018-05-11 15:36:52 -070049source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
50source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
51source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
52source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080053
54# -------------------
55# Check CLI Arguments
56# -------------------
57
58print( "Verifying CLI args." )
59
60args <- commandArgs( trailingOnly=TRUE )
61
62# Check if sufficient args are provided.
63if ( 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
76print( "Creating title of graph" )
77
78# Title of graph based on command line args.
79
80title <- args[ graph_title ]
81title <- paste( title, if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "" )
82
83print( "Creating graph filename." )
84
85# Filenames for the output graph include the testname, branch, and the graph type.
86outputFile <- 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
102print( "Initializing SQL" )
103con <- initSQL( args[ database_host ], args[ database_port ], args[ database_u_id ], args[ database_pw ] )
104
105fileData <- retrieveData( con, args[ sql_commands ] )
106
107# **********************************************************
108# STEP 2: Organize data.
109# **********************************************************
110
111print( "**********************************************************" )
112print( "STEP 2: Organize Data." )
113print( "**********************************************************" )
114
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800115latestBuildDate <- fileData$date[1]
116
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800117# Create lists c() and organize data into their corresponding list.
118print( "Combine data retrieved from databases into a list." )
119
120buildNums <- fileData$build
121fileData$build <- c()
Jeremy Ronquillo5d9e7252020-01-15 10:35:18 -0800122fileData <- subset( fileData, select=-c( date ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800123print( fileData )
124
125if ( 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
136print( "Constructing data frame from combined data." )
137
138dataFrame <- melt( fileData )
139dataFrame$date <- fileData$date
140
141colnames( 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.
145dataFrame$Legend <- as.character( dataFrame$Legend )
146dataFrame$Legend <- factor( dataFrame$Legend, levels=unique( dataFrame$Legend ) )
147dataFrame$build <- buildNums
148
149# Adding a temporary iterative list to the dataFrame so that there are no gaps in-between date numbers.
150dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
151
152dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
153
154print( "Data Frame Results:" )
155print( dataFrame )
156
157# **********************************************************
158# STEP 3: Generate graphs.
159# **********************************************************
160
161print( "**********************************************************" )
162print( "STEP 3: Generate Graph." )
163print( "**********************************************************" )
164
165# -------------------
166# Main Plot Generated
167# -------------------
168
169print( "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
178mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
179 y = Values,
180 color = Legend ) )
181
182# -------------------
183# Main Plot Formatted
184# -------------------
185
186print( "Formatting main plot." )
187
188limitExpansion <- expand_limits( y = 0 )
189
190tickLength <- 3
191breaks <- seq( max( dataFrame$iterative ) %% tickLength, max( dataFrame$iterative ), by = tickLength )
192breaks <- breaks[ which( breaks != 0 ) ]
193
194maxYDisplay <- max( dataFrame$Values ) * 1.05
195yBreaks <- ceiling( max( dataFrame$Values ) / 10 )
196yScaleConfig <- scale_y_continuous( breaks = seq( 0, maxYDisplay, by = yBreaks ) )
197xScaleConfig <- scale_x_continuous( breaks = breaks, label = rev( dataFrame$build )[ breaks ] )
198
199# ------------------------------
200# Fundamental Variables Assigned
201# ------------------------------
202
203print( "Generating fundamental graph data." )
204
205defaultTextSize()
206xLabel <- xlab( "Build" )
207yLabel <- ylab( args[ y_axis ] )
208
209# Set other graph configurations here.
210theme <- graphTheme()
211
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800212title <- labs( title = title, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800213
214# Colors used for the lines.
215# Note: graphs that have X lines will use the first X colors in this list.
216colors <- 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
223wrapLegend <- wrapLegend()
224
225fundamentalGraphData <- 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
240print( "Generating line graph." )
241
242lineGraphFormat <- geom_line( size = 0.75 )
243pointFormat <- geom_point( size = 1.75 )
244
245result <- fundamentalGraphData +
246 lineGraphFormat +
247 pointFormat
248
249# -----------------------
250# Exporting Graph to File
251# -----------------------
252
253saveGraph( outputFile ) # from saveGraph.R
254quit( status = 0 )