Skip to content

Commit

Permalink
ensure URI encoding of project name and fix datatables jquery for htm…
Browse files Browse the repository at this point in the history
…l output
  • Loading branch information
spencerspitz committed Feb 10, 2022
1 parent c438647 commit c152728
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package com.gocypher.cybench.services;

import java.io.File;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -139,7 +141,7 @@ public static Map<String, Map<String, ComparedBenchmark>> parseRecentReport(File
}

public boolean getProjectSummary(String projectName, String accessToken) {
String serviceUrl = projectSummaryUrl + projectName + "/providedAccessToken";
String serviceUrl = projectSummaryUrl + URLEncoder.encode(projectName, StandardCharsets.UTF_8).toString() + "/providedAccessToken";
if (serviceUrl != null && projectName != null) {
try {
log.info("* Fetching project data for {}", projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
Expand All @@ -38,8 +37,6 @@
import com.gocypher.cybench.model.ComparedBenchmark;
import com.gocypher.cybench.model.ComparisonConfig;
import com.gocypher.cybench.model.ComparedBenchmark.CompareState;
import com.gocypher.cybench.model.ComparisonConfig.Method;
import com.gocypher.cybench.model.ComparisonConfig.Threshold;
import com.gocypher.cybench.model.ComparisonConfig.Type;
import com.gocypher.cybench.services.Requests;

Expand Down Expand Up @@ -72,8 +69,9 @@ public static void generatePage() {

String runTime = getDateTimeForFileName();
htmlStr = htmlStr.replace("$" + "runTime", runTime);
String projectName = Requests.project.replace("/", " ");
File htmlFile = new File(
"htmlReports/" + Requests.project + " v" + Requests.currentVersion + " - " + runTime + ".html");
"htmlReports/" + projectName + " v" + Requests.currentVersion + " - " + runTime + ".html");
FileUtils.writeStringToFile(htmlFile, htmlStr, utf8);


Expand Down Expand Up @@ -136,12 +134,12 @@ private static void fillBenchmarkTable(File htmlFile, List<ComparedBenchmark> be
+ "<th>Delta</th>"
+ "<th>Percent Change</th>"
+ "<th>Deviations From Mean</th>"
+ "</tr></thead>", utf8, true);
+ "</tr></thead><tbody>", utf8, true);

for (ComparedBenchmark benchmark : benchmarks) {
ComparisonConfig comparisonConfig = benchmark.getComparisonConfig();
String testType = getTestType(comparisonConfig);
FileUtils.writeStringToFile(htmlFile, "<tbody><tr>"
FileUtils.writeStringToFile(htmlFile, "<tr>"
+ "<td>" + testType + "</td>"
+ "<td style='text-align:left'>" + benchmark.getDisplayName() + "</td>"
+ "<td>" + benchmark.getMode() + "</td>"
Expand All @@ -152,8 +150,9 @@ private static void fillBenchmarkTable(File htmlFile, List<ComparedBenchmark> be
+ "<td>" + benchmark.getRoundedDelta() + "</td>"
+ "<td>" + benchmark.getRoundedPercentChange() + "%</td>"
+ "<td>" + benchmark.getRoundedDeviationsFromMean() + "</td>"
+ "</tr></tbody></table><br>", utf8, true);
+ "</tr>", utf8, true);
}
FileUtils.writeStringToFile(htmlFile, "</tbody></table><br>", utf8, true);
} catch (Exception e) {
log.error("Error filling HTML table with benchmark data!");
throw e;
Expand All @@ -171,19 +170,17 @@ private static String getTestType(ComparisonConfig comparisonConfig) {
}


private static void generateStylingFile() throws Exception{
InputStream styleIn = WebpageGenerator.class.getResourceAsStream("/styles.css");
File tempStyleFile = new File("htmlReports/styles/styles.css");
String resultStyle;
private static void generateStylingFile() throws Exception {
InputStream stream = WebpageGenerator.class.getResourceAsStream("/styles.css");
File styleFile = new File("htmlReports/styles/styles.css");
try {
resultStyle = IOUtils.toString(styleIn, utf8);
FileUtils.writeStringToFile(tempStyleFile, resultStyle, utf8);
styleIn.close();
String styles = IOUtils.toString(stream, utf8);
FileUtils.writeStringToFile(styleFile, styles, utf8);
stream.close();
} catch (Exception e) {
log.error("Failed to generate styling for HTML report.");
log.error("Failed to generate HTML styling");
throw e;
}

}

private static void deleteTempFiles() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ table.dataTable.no-footer {
border-style: double;
}

.passedTableCaption {
.passedCaption {
border-style: double;
background-color: #65e665;
font-weight: bold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.js"></script>

<script>
$(document).ready(function () {
$('#passedTable').DataTable({
"pageLength": 50,
"pageLength": 10,
"order": [[1, "desc"]]
});
$('#anomalyTable').DataTable({
"pageLength": 50,
"pageLength": 10,
"order": [[1, "desc"]]
});
$('#skippedTable').DataTable({
"pageLength": 50,
"pageLength": 10,
"order": [[1, "desc"]]
});

Expand Down

0 comments on commit c152728

Please sign in to comment.