blob: b34010a1b8f51db829c59a41b79e9f2705dca0c3 [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# **********************************************************
24# STEP 1: Data management.
25# **********************************************************
26
27print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
30
31save_directory = 7
32
33# Command line arguments are read.
34print( "Reading commmand-line args." )
35args <- commandArgs( trailingOnly=TRUE )
36
37# ----------------
38# Import Libraries
39# ----------------
40
41print( "Importing libraries." )
42library( ggplot2 )
43library( reshape2 )
44library( RPostgreSQL ) # For databases
Devin Lim324806b2018-05-11 15:36:52 -070045source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
46source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
47source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
48source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080049
50# -------------------
51# Check CLI Arguments
52# -------------------
53
54print( "Verifying CLI args." )
55
56if ( length( args ) != save_directory ){
57 usage( "SCPFhostLat.R" )
58 quit( status = 1 )
59}
60
61# -----------------
62# Create File Names
63# -----------------
64
65print( "Creating filenames and title of graph." )
66
67errBarOutputFile <- paste( args[ save_directory ],
68 args[ graph_title ],
69 "_",
70 args[ branch_name ],
71 "_errGraph.jpg",
72 sep="" )
73
74chartTitle <- "Host Latency"
75# ------------------
76# SQL Initialization
77# ------------------
78
79print( "Initializing SQL" )
80
81con <- 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
90print( "Generating Host Latency SQL Command" )
91
92command <- 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
99fileData <- retrieveData( con, command )
100
101
102# **********************************************************
103# STEP 2: Organize data.
104# **********************************************************
105
106print( "**********************************************************" )
107print( "STEP 2: Organize Data." )
108print( "**********************************************************" )
109
110# ------------
111# Data Sorting
112# ------------
113
114print( "Sorting data." )
115
116requiredColumns <- c( "avg" )
117
118tryCatch( avgs <- c( fileData[ requiredColumns ] ),
119 error = function( e ) {
120 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." )
121 print( "Required columns: " )
122 print( requiredColumns )
123 print( "Actual columns: " )
124 print( names( fileData ) )
125 print( "Error dump:" )
126 print( e )
127 quit( status = 1 )
128 }
129 )
130
131# --------------------
132# Construct Data Frame
133# --------------------
134
135print( "Constructing Data Frame" )
136
137dataFrame <- melt( avgs )
138dataFrame$scale <- fileData$scale
139dataFrame$std <- fileData$std
140
141colnames( dataFrame ) <- c( "ms",
142 "type",
143 "scale",
144 "std" )
145
146dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
147
148print( "Data Frame Results:" )
149print( dataFrame )
150
151# **********************************************************
152# STEP 3: Generate graphs.
153# **********************************************************
154
155print( "**********************************************************" )
156print( "STEP 3: Generate Graph." )
157print( "**********************************************************" )
158
159# ------------------
160# Generate Main Plot
161# ------------------
162
163print( "Creating main plot." )
164
165mainPlot <- ggplot( data = dataFrame, aes( x = scale,
166 y = ms,
167 ymin = ms,
168 ymax = ms + std ) )
169
170# ------------------------------
171# Fundamental Variables Assigned
172# ------------------------------
173
174print( "Generating fundamental graph data." )
175
176defaultTextSize()
177
178barWidth <- 0.9
179
180xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
181
182xLabel <- xlab( "Scale" )
183yLabel <- ylab( "Latency (ms)" )
184fillLabel <- labs( fill="Type" )
185
186theme <- graphTheme()
187
188title <- labs( title = chartTitle, subtitle = lastUpdatedLabel() )
189
190errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
191
192fundamentalGraphData <- mainPlot +
193 xScaleConfig +
194 xLabel +
195 yLabel +
196 fillLabel +
197 theme +
198 title
199
200# ---------------------------
201# Generating Bar Graph Format
202# ---------------------------
203
204print( "Generating bar graph with error bars." )
205
206barGraphFormat <- geom_bar( stat = "identity",
207 position = position_dodge(),
208 width = barWidth,
209 fill = webColor( "purple" ) )
210
211errorBarFormat <- geom_errorbar( position = position_dodge(),
212 width = barWidth,
213 color = webColor( "darkerGray" ) )
214
215values <- geom_text( aes( x=dataFrame$scale,
216 y=dataFrame$ms + 0.06 * max( dataFrame$ms ),
217 label = format( dataFrame$ms,
218 digits=3,
219 big.mark = ",",
220 scientific = FALSE ) ),
221 size = 7.0,
222 fontface = "bold" )
223
224result <- fundamentalGraphData +
225 barGraphFormat +
226 errorBarFormat +
227 values
228
229# -----------------------
230# Exporting Graph to File
231# -----------------------
232
233saveGraph( errBarOutputFile )