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