blob: b67712337182c718a7de87caf747a6da36c552cb [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
115# Create lists c() and organize data into their corresponding list.
116print( "Combine data retrieved from databases into a list." )
117
118buildNums <- fileData$build
119fileData$build <- c()
Jeremy Ronquillocf1b6602020-01-15 10:35:18 -0800120fileData <- subset( fileData, select=-c( date ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800121print( fileData )
122
123if ( ncol( fileData ) > 1 ){
124 for ( i in 2:ncol( fileData ) ){
125 fileData[ i ] <- fileData[ i - 1 ] + fileData[ i ]
126 }
127}
128
129
130# --------------------
131# Construct Data Frame
132# --------------------
133
134print( "Constructing data frame from combined data." )
135
136dataFrame <- melt( fileData )
137dataFrame$date <- fileData$date
138
139colnames( dataFrame ) <- c( "Legend",
140 "Values" )
141
142# Format data frame so that the data is in the same order as it appeared in the file.
143dataFrame$Legend <- as.character( dataFrame$Legend )
144dataFrame$Legend <- factor( dataFrame$Legend, levels=unique( dataFrame$Legend ) )
145dataFrame$build <- buildNums
146
147# Adding a temporary iterative list to the dataFrame so that there are no gaps in-between date numbers.
148dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
149
150dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
151
152print( "Data Frame Results:" )
153print( dataFrame )
154
155# **********************************************************
156# STEP 3: Generate graphs.
157# **********************************************************
158
159print( "**********************************************************" )
160print( "STEP 3: Generate Graph." )
161print( "**********************************************************" )
162
163# -------------------
164# Main Plot Generated
165# -------------------
166
167print( "Creating main plot." )
168# Create the primary plot here.
169# ggplot contains the following arguments:
170# - data: the data frame that the graph will be based off of
171# - aes: the asthetics of the graph which require:
172# - x: x-axis values (usually iterative, but it will become date # later)
173# - y: y-axis values (usually tests)
174# - color: the category of the colored lines (usually legend of test)
175
176mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
177 y = Values,
178 color = Legend ) )
179
180# -------------------
181# Main Plot Formatted
182# -------------------
183
184print( "Formatting main plot." )
185
186limitExpansion <- expand_limits( y = 0 )
187
188tickLength <- 3
189breaks <- seq( max( dataFrame$iterative ) %% tickLength, max( dataFrame$iterative ), by = tickLength )
190breaks <- breaks[ which( breaks != 0 ) ]
191
192maxYDisplay <- max( dataFrame$Values ) * 1.05
193yBreaks <- ceiling( max( dataFrame$Values ) / 10 )
194yScaleConfig <- scale_y_continuous( breaks = seq( 0, maxYDisplay, by = yBreaks ) )
195xScaleConfig <- scale_x_continuous( breaks = breaks, label = rev( dataFrame$build )[ breaks ] )
196
197# ------------------------------
198# Fundamental Variables Assigned
199# ------------------------------
200
201print( "Generating fundamental graph data." )
202
203defaultTextSize()
204xLabel <- xlab( "Build" )
205yLabel <- ylab( args[ y_axis ] )
206
207# Set other graph configurations here.
208theme <- graphTheme()
209
210title <- labs( title = title, subtitle = lastUpdatedLabel() )
211
212# Colors used for the lines.
213# Note: graphs that have X lines will use the first X colors in this list.
214colors <- scale_color_manual( values=c( webColor( "black" ), # black
215 webColor( "blue" ), # blue
216 webColor( "red" ), # red
217 webColor( "green" ), # green
218 webColor( "yellow" ), # yellow
219 webColor( "purple" ) ) ) # purple (not used)
220
221wrapLegend <- wrapLegend()
222
223fundamentalGraphData <- mainPlot +
224 limitExpansion +
225 xScaleConfig +
226 yScaleConfig +
227 xLabel +
228 yLabel +
229 theme +
230 colors +
231 wrapLegend +
232 title
233
234# ----------------------------
235# Generating Line Graph Format
236# ----------------------------
237
238print( "Generating line graph." )
239
240lineGraphFormat <- geom_line( size = 0.75 )
241pointFormat <- geom_point( size = 1.75 )
242
243result <- fundamentalGraphData +
244 lineGraphFormat +
245 pointFormat
246
247# -----------------------
248# Exporting Graph to File
249# -----------------------
250
251saveGraph( outputFile ) # from saveGraph.R
252quit( status = 0 )