Merge "k6 historical graphs"
diff --git a/jjb/onap/cps/prepare-k6-performance-tests-plots.sh b/jjb/onap/cps/prepare-k6-performance-tests-plots.sh
index c8a8282..90c29b4 100755
--- a/jjb/onap/cps/prepare-k6-performance-tests-plots.sh
+++ b/jjb/onap/cps/prepare-k6-performance-tests-plots.sh
@@ -66,14 +66,14 @@
   if [ -s summary.csv ]; then
     # Store the test cases, names, and units
     cut -d, -f1,2,3 summary.csv > test-cases.csv
-    # Process each row in the CSV, storing the limit and actual value for this build
-    while IFS=, read -r test_case test_name units limit actual; do
-      echo "$buildNumber,$limit,$actual" >> "data/$test_case.csv"
+    # Process each row in the CSV, storing the limit cps_expectation and actual value for this build
+    while IFS=, read -r test_case test_name units limit cps_expectation actual; do
+      echo "$buildNumber,$limit,$cps_expectation,$actual" >> "data/$test_case.csv"
     done < summary.csv
   else
     # No CSV data for this build, so record zeroes for this build in each existing data file
     for dataFile in data/*.csv; do
-      echo "$buildNumber,0,0" >> "$dataFile"
+      echo "$buildNumber,0,0,0" >> "$dataFile"
     done
   fi
   recordLatestRecordedBuild "$buildNumber"
@@ -93,6 +93,7 @@
   dataFile="$1"
   chartFileName="$2"
   units="$3"
+  numberOfBuilds="$4"
 
   y_max=$(findMaxPlotRange "$dataFile")
 
@@ -116,11 +117,28 @@
 set xtics rotate
 
 # Use plot command with explicit column assignments and lines for all series
-plot '$dataFile' using 1:2 with lines linestyle 2 title "threshold", \
-     '$dataFile' using 1:3 with lines linestyle 3 title "cps-limit", \
-     '$dataFile' using 1:4:xtic(1) with linespoints linestyle 4 title "measured"
 EOT
 
+  if [ "$numberOfBuilds" -eq 100 ]; then
+    cat <<EOT >>gnuplot_script.gp
+plot '<(tail -n $numberOfBuilds $dataFile)' using 1:2 with lines linestyle 2 title "threshold", \
+     '<(tail -n $numberOfBuilds $dataFile)' using 1:3 with lines linestyle 3 title "cps-limit", \
+     '<(tail -n $numberOfBuilds $dataFile)' using 1:4:xtic(1) with linespoints linestyle 4 title "measured"
+EOT
+  elif [ "$numberOfBuilds" -eq 168 ]; then
+    cat <<EOT >>gnuplot_script.gp
+plot '<(tail -n $numberOfBuilds $dataFile | awk "NR % 2 == 0")' using 1:2 with lines linestyle 2 title "threshold", \
+     '<(tail -n $numberOfBuilds $dataFile | awk "NR % 2 == 0")' using 1:3 with lines linestyle 3 title "cps-limit", \
+     '<(tail -n $numberOfBuilds $dataFile | awk "NR % 2 == 0")' using 1:4:xtic(1) with linespoints linestyle 4 title "measured"
+EOT
+  elif [ "$numberOfBuilds" -eq 720 ]; then
+    cat <<EOT >>gnuplot_script.gp
+plot '<(tail -n $numberOfBuilds $dataFile | awk "NR % 7 == 0")' using 1:2 with lines linestyle 2 title "threshold", \
+     '<(tail -n $numberOfBuilds $dataFile | awk "NR % 7 == 0")' using 1:3 with lines linestyle 3 title "cps-limit", \
+     '<(tail -n $numberOfBuilds $dataFile | awk "NR % 7 == 0")' using 1:4:xtic(1) with linespoints linestyle 4 title "measured"
+EOT
+  fi
+
   # Run the temporary Gnuplot script
   gnuplot gnuplot_script.gp
 
@@ -142,6 +160,53 @@
     print max * 1.2;
   }' "$dataFile"
 }
+
+generateHtmlReport() {
+  local reportTitle="$1"
+  local outputFile="$2"
+  local numberOfBuilds="$3"
+
+  cat <<EOT >"$outputFile"
+  <!DOCTYPE html>
+  <html>
+  <head>
+  <title>$reportTitle</title>
+  </head>
+  <body>
+    <h1 style="text-align: center;">$reportTitle</h1>
+    <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
+    <table align="center">
+EOT
+
+  # Loop through the tests to generate the HTML rows which consists of the plot-image
+  while IFS=, read -r test_case test_name units; do
+    dataFile="data/$test_case.csv"
+    # Plot the image (graph) in png format
+    buildPlotImage "$dataFile" "data/${test_case}_${numberOfBuilds}.png" "$units" "$numberOfBuilds"
+    # Output to HTML
+    cat <<EOF >>"$outputFile"
+      <tr>
+          <td align="center" style="padding: 10px;">
+              <figcaption>$test_case. $test_name ($units)</figcaption>
+              <img src="data/${test_case}_${numberOfBuilds}.png" width="750" height="300">
+          </td>
+      </tr>
+EOF
+  done < test-cases.csv
+
+  # Close the HTML file
+  cat <<EOT >>"$outputFile"
+      </table>
+        <p>The plots are generated from the output of the Nordix Jenkins job:
+          <a href="https://jenkins.nordix.org/job/onap-cps-performance-test-k6/">onap-cps-performance-test-k6</a>.</p>
+        <p>The k6 performance tests run are described in the
+          <a href="https://wiki.onap.org/display/DW/CPS-391Spike%3A+Define+and+Agree+NCMP+REST+Interface#CPS391Spike:DefineandAgreeNCMPRESTInterface-Characteristics">NCMP REST Interface Characteristics</a> documentation.</p>
+    </body>
+  </html>
+EOT
+}
+
+
 #############################################################################################################################
 ################################################ M A I N ####################################################################
 #############################################################################################################################
@@ -173,45 +238,14 @@
   fi
 fi
 
-reportTitle="k6 tests performance review"
-outputFile="k6TestsPerformanceReview.html"
-cat <<EOT >"$outputFile"
-  <!DOCTYPE html>
-  <html>
-  <head>
-  <title>$reportTitle</title>
-  </head>
-  <body>
-    <h1 style="text-align: center;">$reportTitle</h1>
-    <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
-    <table align="center">
-EOT
+reportTitleDaily="daily k6 tests performance review"
+outputFileDaily="k6TestsPerformanceReview.html"
+generateHtmlReport "$reportTitleDaily" "$outputFileDaily" "100"
 
-# Loop through the tests to generate the HTML rows which consists of the plot-image
-while IFS=, read -r test_case test_name units; do
-  dataFile="data/$test_case.csv"
-  # Limit the plots to last 100 builds for each test
-  tail -n 100 "$dataFile" > file.tmp && mv file.tmp "$dataFile"
-  # Plot image files in png format
-  buildPlotImage "$dataFile" "data/$test_case.png" "$units"
-  # Output to HTML
-  cat <<EOF >>"$outputFile"
-      <tr>
-          <td align="center" style="padding: 10px;">
-              <figcaption>$test_case. $test_name ($units)</figcaption>
-              <img src="data/$test_case.png" width="750" height="300">
-          </td>
-      </tr>
-EOF
-done < test-cases.csv
+reportTitleWeekly="weekly k6 tests performance review"
+outputFileWeekly="k6TestsPerformanceReviewWeekly.html"
+generateHtmlReport "$reportTitleWeekly" "$outputFileWeekly" "168"
 
-# Close the HTML file
-cat <<EOT >>"$outputFile"
-      </table>
-        <p>The plots are generated from the output of the Nordix Jenkins job:
-          <a href="https://jenkins.nordix.org/job/onap-cps-performance-test-k6/">onap-cps-performance-test-k6</a>.</p>
-        <p>The k6 performance tests run are described in the
-          <a href="https://wiki.onap.org/display/DW/CPS-391Spike%3A+Define+and+Agree+NCMP+REST+Interface#CPS391Spike:DefineandAgreeNCMPRESTInterface-Characteristics">NCMP REST Interface Characteristics</a> documentation.</p>
-    </body>
-  </html>
-EOT
+reportTitleMonthly="monthly k6 tests performance review"
+outputFileMonthly="k6TestsPerformanceReviewMonthly.html"
+generateHtmlReport "$reportTitleMonthly" "$outputFileMonthly" "720"