blob: b82f255dbc7c67150e960fa7fbf7aba959753b3a [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
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800110latestBuildDate <- fileData$date[1]
111
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800112# ------------
113# Data Sorting
114# ------------
115
116print( "Sorting data." )
117
118requiredColumns <- c( "avg" )
119
120tryCatch( avgs <- c( fileData[ requiredColumns ] ),
121 error = function( e ) {
122 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." )
123 print( "Required columns: " )
124 print( requiredColumns )
125 print( "Actual columns: " )
126 print( names( fileData ) )
127 print( "Error dump:" )
128 print( e )
129 quit( status = 1 )
130 }
131 )
132
133# --------------------
134# Construct Data Frame
135# --------------------
136
137print( "Constructing Data Frame" )
138
139dataFrame <- melt( avgs )
140dataFrame$scale <- fileData$scale
141dataFrame$std <- fileData$std
142
143colnames( dataFrame ) <- c( "ms",
144 "type",
145 "scale",
146 "std" )
147
148dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
149
150print( "Data Frame Results:" )
151print( dataFrame )
152
153# **********************************************************
154# STEP 3: Generate graphs.
155# **********************************************************
156
157print( "**********************************************************" )
158print( "STEP 3: Generate Graph." )
159print( "**********************************************************" )
160
161# ------------------
162# Generate Main Plot
163# ------------------
164
165print( "Creating main plot." )
166
167mainPlot <- ggplot( data = dataFrame, aes( x = scale,
168 y = ms,
169 ymin = ms,
170 ymax = ms + std ) )
171
172# ------------------------------
173# Fundamental Variables Assigned
174# ------------------------------
175
176print( "Generating fundamental graph data." )
177
178defaultTextSize()
179
180barWidth <- 0.9
181
182xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
183
184xLabel <- xlab( "Scale" )
185yLabel <- ylab( "Latency (ms)" )
186fillLabel <- labs( fill="Type" )
187
188theme <- graphTheme()
189
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800190title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800191
192errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
193
194fundamentalGraphData <- mainPlot +
195 xScaleConfig +
196 xLabel +
197 yLabel +
198 fillLabel +
199 theme +
200 title
201
202# ---------------------------
203# Generating Bar Graph Format
204# ---------------------------
205
206print( "Generating bar graph with error bars." )
207
208barGraphFormat <- geom_bar( stat = "identity",
209 position = position_dodge(),
210 width = barWidth,
211 fill = webColor( "purple" ) )
212
213errorBarFormat <- geom_errorbar( position = position_dodge(),
214 width = barWidth,
215 color = webColor( "darkerGray" ) )
216
217values <- geom_text( aes( x=dataFrame$scale,
218 y=dataFrame$ms + 0.06 * max( dataFrame$ms ),
219 label = format( dataFrame$ms,
220 digits=3,
221 big.mark = ",",
222 scientific = FALSE ) ),
223 size = 7.0,
224 fontface = "bold" )
225
226result <- fundamentalGraphData +
227 barGraphFormat +
228 errorBarFormat +
229 values
230
231# -----------------------
232# Exporting Graph to File
233# -----------------------
234
235saveGraph( errBarOutputFile )