Skip to content

Commit

Permalink
Fixed #137 : Finished creating an HTML Report for the differences.
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Jun 20, 2024
1 parent 066b64d commit 362f481
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public LogDataComparison(T in_LogEntry, ChangeType in_changeType, Integer in_ori
this.logEntry = in_LogEntry;
this.changeType = in_changeType;
this.delta = in_newFrequence - in_originalFrequence;
this.deltaRatio = Math.signum(this.delta) * ((in_newFrequence*in_originalFrequence==0) ? 1 : (double) in_originalFrequence / in_newFrequence);
this.deltaRatio = Math.signum(this.delta) * (((in_newFrequence*in_originalFrequence==0) ? 1 : (double) in_newFrequence/ in_originalFrequence)*100);
}

public T getLogEntry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,43 +236,78 @@ public static <T extends StdLogEntry> LogData<T> generateLogData(String in_rootD

/**
* A factory method that creates an html Report of the differences of two log data
* @param in_logDataLeft
* @param in_logDataRight
* @param in_logDataReference The Log data that is used as a referen‡ce base
* @param in_logDataTarget The log data t be compared with the reference
* @param in_reportName Name of the export file
*/
public static <T extends StdLogEntry> File generateDiffReport(LogData<T> in_logDataLeft, LogData<T> in_logDataRight, String in_reportName, List<String> in_headers) {
Map<String, LogDataComparison> comparisonReport = in_logDataLeft.compare(in_logDataRight);
public static <T extends StdLogEntry> File generateDiffReport(LogData<T> in_logDataReference, LogData<T> in_logDataTarget, String in_reportName, List<String> in_headers) {
Map<String, LogDataComparison> comparisonReport = in_logDataReference.compare(in_logDataTarget);
StringBuilder sb = new StringBuilder();
sb.append("<!DOCTYPE html>");
sb.append("<html>");
sb.append("<head>");
sb.append("<style>");
sb.append("table, th, td {");
sb.append(" border: 1px solid black;");
sb.append("}");
sb.append("table.center {");
sb.append(" margin-left: auto;");
sb.append(" margin-right: auto;");
sb.append("}");
sb.append("</style>");
sb.append("</head>");
sb.append("<body>");
sb.append("<link rel='stylesheet' href='src/main/resources/diffTable.css'>");
sb.append("</head>");
sb.append("<body>");
sb.append("<h1>Overview</h1>");
sb.append("Here is an overview of the differences between the two log data sets.");
sb.append("<table class='diffOverView'>");
sb.append("<thead>");
sb.append("<tr>");
sb.append("<th>Metrics</th>");
sb.append("<th>#</th>");
sb.append("</thead> <tbody>");
sb.append("<tr>");
sb.append("<th>New Errors</th>");
sb.append("<td>");
sb.append(comparisonReport.values().stream().filter(l -> l.getChangeType().equals(LogDataComparison.ChangeType.ADDED)).count());
sb.append("</td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<th>Increased Error Numbers</th>");
sb.append("<td>");
sb.append(comparisonReport.values().stream().filter(l -> l.getChangeType().equals(LogDataComparison.ChangeType.MODIFIED)).filter(c -> c.getDelta() > 0).count());
sb.append("</td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<th>Removed Errors</th>");
sb.append("<td>");
sb.append(comparisonReport.values().stream().filter(l -> l.getChangeType().equals(LogDataComparison.ChangeType.REMOVED)).count());
sb.append("</td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<th>Decreased Error Numbers</th>");
sb.append("<td>");
sb.append(comparisonReport.values().stream().filter(l -> l.getChangeType().equals(LogDataComparison.ChangeType.MODIFIED)).filter(c -> c.getDelta() < 0).count());
sb.append("</td>");
sb.append("</tr>");
sb.append("</tbody>");
sb.append("</table>");
sb.append("<h1>Detailed</h1>");
sb.append("Detailed report of the differences between the two log data sets grouped by change type.<p>");
comparisonReport.values().stream().map(LogDataComparison::getChangeType).distinct().forEach(l_changeType -> {
List<LogDataComparison> l_entries = comparisonReport.values().stream().filter(l -> l.getChangeType().equals(l_changeType)).collect(
List<LogDataComparison> l_entries = comparisonReport.values().stream().filter(l -> l.getChangeType().equals(l_changeType)).sorted(Comparator.comparing(LogDataComparison::getDelta)).collect(
Collectors.toList());
sb.append("<h1>").append(l_changeType).append("</h1>");
Collections.reverse(l_entries);
//l_entries.sort(Comparator.comparing(LogDataComparison::getDelta));
sb.append("<h3>").append(l_changeType).append("</h3>");
sb.append("<table>");
sb.append("<thead>");
sb.append("<tr>");
in_headers.forEach(h -> sb.append("<th>").append(h).append("</th>"));
sb.append("<th>delta</th>");
sb.append("<th>deltaRatio</th>");
sb.append("</thead><tbody>");
sb.append("</tr>");
l_entries.forEach(l -> {
sb.append("<tr>");
in_headers.forEach(h -> sb.append("<td>").append(l.getLogEntry().fetchValueMap().get(h)).append("</td>"));
sb.append("<td>").append(l.getDelta()).append("</td>");
sb.append("<td>").append(l.getDeltaRatio()).append("</td>");
sb.append("<td>").append(l.getDeltaRatio()).append(" %</td>");
sb.append("</tr>");
});
sb.append("</tbody>");

sb.append("</table>");
});
sb.append("</body>");
Expand Down
70 changes: 70 additions & 0 deletions src/main/resources/diffTable.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2022 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it.
*/

h1, h2, h3 {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
color: #333;
line-height: 1.6;
}

.diffOverView table {
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
text-align: left;
}
.diffOverView th, td {
text-align: left;
}

table {
border-collapse:separate;
border:solid #7d8d40 1px;
border-radius:25px;
border-spacing: 0;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
overflow: hidden;
margin-left: auto;
margin-right: auto;
}

thead tr {
background-color: #7d8d40;
border-left:solid #7d8d40 0px;
border-top:solid #7d8d40 1px;
border-radius: 25px;
color: White;
text-align: left;
}
th, td {
padding: 12px 15px;
}

tbody tr {
border-bottom: 1px solid #dddddd;
}

tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}

tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}

tbody tr.active-row {
font-weight: bold;
color: #009879;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hamcrest.Matchers;
import org.testng.annotations.Test;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void simpleDifferenceInFrequence() {
assertThat("We should have the correct key",
l_diff.get("12").getDelta(), Matchers.equalTo(1));
assertThat("We should have the correct key",
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(0.5));
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(200.0));
assertThat("We should classify this as Modified", l_diff.get("12").getChangeType(), Matchers.equalTo(LogDataComparison.ChangeType.MODIFIED));

assertThat("We should have stored the original logData", l_diff.get("12").getLogEntry(), Matchers.equalTo(l_cubeData2.get("12")));
Expand All @@ -94,7 +95,7 @@ public void simpleDifferenceEmptyLeftSide() {
assertThat("We should have the correct delta",
l_diff.get("12").getDelta(), Matchers.equalTo(2));
assertThat("We should have the correct key",
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(1.0));
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(100.0));
assertThat("We should classify this as removed", l_diff.get("12").getChangeType(), Matchers.equalTo(LogDataComparison.ChangeType.ADDED));

assertThat("We should have stored the original logData", l_diff.get("12").getLogEntry(), Matchers.equalTo(l_cubeData2.get("12")));
Expand All @@ -120,7 +121,7 @@ public void simpleDifferenceEmptyRightSide() {
assertThat("We should have the correct delta",
l_diff.get("12").getDelta(), Matchers.equalTo(-1));
assertThat("We should have the correct key",
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(-1.0));
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(-100.0));
assertThat("We should classify this as removed", l_diff.get("12").getChangeType(), Matchers.equalTo(LogDataComparison.ChangeType.REMOVED));

assertThat("We should have stored the original logData", l_diff.get("12").getLogEntry(), Matchers.equalTo(l_cubeData.get("12")));
Expand Down Expand Up @@ -150,9 +151,9 @@ public void simpleAddedRemoved() {
assertThat("We should have the correct delta",
l_diff.get("13").getDelta(), Matchers.equalTo(2));
assertThat("We should have the correct key",
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(-1.0));
l_diff.get("12").getDeltaRatio(), Matchers.equalTo(-100.0));
assertThat("We should have the correct key",
l_diff.get("13").getDeltaRatio(), Matchers.equalTo(1.0));
l_diff.get("13").getDeltaRatio(), Matchers.equalTo(100.0));
assertThat("We should classify this as removed", l_diff.get("12").getChangeType(),
Matchers.equalTo(LogDataComparison.ChangeType.REMOVED));
assertThat("We should classify this as removed", l_diff.get("13").getChangeType(),
Expand All @@ -167,6 +168,9 @@ public void simpleAddedRemovedComplex() {
GenericEntry l_inputData = new GenericEntry(l_definition);
l_inputData.getValuesMap().put("AAZ", "12");
LogData<GenericEntry> l_cubeData = new LogData<>(l_inputData);
GenericEntry l_inputData4 = new GenericEntry(l_definition);
l_inputData4.getValuesMap().put("AAZ", "13");
l_cubeData.addEntry(l_inputData4);

//Create second log data
GenericEntry l_inputData2 = new GenericEntry(l_definition);
Expand All @@ -177,11 +181,20 @@ public void simpleAddedRemovedComplex() {
l_inputData3.getValuesMap().put("AAZ", "14");
l_cubeData2.addEntry(l_inputData3);

GenericEntry l_inputData4b = new GenericEntry(l_definition);
l_inputData4b.getValuesMap().put("AAZ", "13");
l_cubeData2.addEntry(l_inputData4b);
l_cubeData2.addEntry(l_inputData4b);
l_cubeData2.addEntry(l_inputData4b);

Map<String, LogDataComparison> l_diff = l_cubeData.compare(l_cubeData2);

LogDataFactory.generateDiffReport(l_cubeData,l_cubeData2, "SimpleDiffReport", Arrays.asList("AAZ"));
}
File l_file = LogDataFactory.generateDiffReport(l_cubeData,l_cubeData2, "SimpleDiffReport", Arrays.asList("AAZ"));

assertThat("We should have created a file", l_file.exists());
assertThat("We should have created a file with the correct name", l_file.getName(), Matchers.equalTo("SimpleDiffReport.html"));

}



Expand Down

0 comments on commit 362f481

Please sign in to comment.