mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
improvements
This commit is contained in:
+2
-1
@@ -2,6 +2,7 @@ package org.diylc.plugins.chatbot.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -24,7 +25,7 @@ public class JsonToHtmlConverter {
|
||||
.append(" <meta charset=\"UTF-8\">\n")
|
||||
.append(" <title>Validation Report</title>\n")
|
||||
.append(" <style>\n")
|
||||
.append(" body { font-family: Arial, sans-serif; }\n")
|
||||
.append(" body { font-family: ").append(new JLabel().getFont().getName()).append(", sans-serif; }\n")
|
||||
.append(" h2 { color: #444; }\n")
|
||||
.append(" ul { list-style: disc; margin-left: 20px; }\n")
|
||||
.append(" li { margin-bottom: 5px; }\n")
|
||||
|
||||
+14
-25
@@ -14,7 +14,6 @@ import org.diylc.presenter.Presenter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -55,28 +54,6 @@ public class CompareService {
|
||||
java.util.function.Function<Node, String> nodeKey = node ->
|
||||
node.getComponent().getName() + ":" + node.getComponent().getControlPointNodeName(node.getPointIndex());
|
||||
|
||||
// Get all component names from both netlists
|
||||
Set<String> components1 = netlist1.getComponents().stream()
|
||||
.map(component -> component.getName())
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> components2 = netlist2.getComponents().stream()
|
||||
.map(component -> component.getName())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// Find components that are only in netlist1
|
||||
for (String component : components1) {
|
||||
if (!components2.contains(component)) {
|
||||
componentDiffs.add(new ComponentDiff(component, true));
|
||||
}
|
||||
}
|
||||
|
||||
// Find components that are only in netlist2
|
||||
for (String component : components2) {
|
||||
if (!components1.contains(component)) {
|
||||
componentDiffs.add(new ComponentDiff(component, false));
|
||||
}
|
||||
}
|
||||
|
||||
// For each group in netlist1, check if it exists in netlist2
|
||||
for (Group group1 : groups1) {
|
||||
boolean groupFound = false;
|
||||
@@ -87,10 +64,16 @@ public class CompareService {
|
||||
}
|
||||
}
|
||||
if (!groupFound) {
|
||||
// If group not found, add connection differences for each pair of nodes
|
||||
// If group not found, all components in this group are different
|
||||
List<Node> nodes = new ArrayList<>(group1.getNodes());
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
Node node = nodes.get(i);
|
||||
// Add component difference
|
||||
componentDiffs.add(new ComponentDiff(
|
||||
node.getComponent().getName(),
|
||||
true));
|
||||
|
||||
// Add connection differences for each pair of nodes
|
||||
for (int j = i + 1; j < nodes.size(); j++) {
|
||||
Node otherNode = nodes.get(j);
|
||||
connectionDiffs.add(new ConnectionDiff(
|
||||
@@ -114,10 +97,16 @@ public class CompareService {
|
||||
}
|
||||
}
|
||||
if (!groupFound) {
|
||||
// If group not found, add connection differences for each pair of nodes
|
||||
// If group not found, all components in this group are different
|
||||
List<Node> nodes = new ArrayList<>(group2.getNodes());
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
Node node = nodes.get(i);
|
||||
// Add component difference
|
||||
componentDiffs.add(new ComponentDiff(
|
||||
node.getComponent().getName(),
|
||||
false));
|
||||
|
||||
// Add connection differences for each pair of nodes
|
||||
for (int j = i + 1; j < nodes.size(); j++) {
|
||||
Node otherNode = nodes.get(j);
|
||||
connectionDiffs.add(new ConnectionDiff(
|
||||
|
||||
+89
-44
@@ -1,9 +1,13 @@
|
||||
package org.diylc.plugins.compare.util;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import org.diylc.plugins.compare.model.CompareResults;
|
||||
import org.diylc.plugins.compare.model.ConnectionDiff;
|
||||
import org.diylc.plugins.compare.model.ComponentDiff;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CompareResultsHtmlReport {
|
||||
|
||||
public static String generateReport(CompareResults results) {
|
||||
@@ -11,66 +15,107 @@ public class CompareResultsHtmlReport {
|
||||
html.append("<!DOCTYPE html>\n");
|
||||
html.append("<html>\n");
|
||||
html.append("<head>\n");
|
||||
html.append("<style>\n");
|
||||
html.append("body { font-family: Arial, sans-serif; margin: 20px; color: black; }\n");
|
||||
html.append("table { border-collapse: collapse; width: 100%; margin-top: 10px; }\n");
|
||||
html.append("th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }\n");
|
||||
html.append("th { background-color: #f2f2f2; }\n");
|
||||
html.append(".result { font-size: 18px; }\n");
|
||||
html.append("h2 { font-size: 14px; margin-top: 20px; }\n");
|
||||
html.append("</style>\n");
|
||||
html.append(" <title>Circuit Comparison Results</title>\n");
|
||||
html.append(" <style>\n");
|
||||
html.append(" body { font-family: ").append(new JLabel().getFont().getName()).append(", sans-serif; margin: 10px; color: black; font-size: 12px; }\n");
|
||||
html.append(" .result { font-size: 14px; margin-bottom: 8px; }\n");
|
||||
html.append(" .section { margin: 6px 0; }\n");
|
||||
html.append(" table { width: 100%; border-collapse: collapse; margin: 4px 0; }\n");
|
||||
html.append(" th, td { padding: 4px; text-align: left; border: 1px solid #ddd; font-size: 11px; }\n");
|
||||
html.append(" th { background-color: #f5f5f5; }\n");
|
||||
html.append(" tr:nth-child(even) { background-color: #f9f9f9; }\n");
|
||||
html.append(" h2 { font-size: 12px; margin-top: 6px; margin-bottom: 4px; }\n");
|
||||
html.append(" </style>\n");
|
||||
html.append("</head>\n");
|
||||
html.append("<body>\n");
|
||||
|
||||
// Start with bold results
|
||||
if (results.matches()) {
|
||||
html.append("<p class=\"result\"><strong>The circuits match exactly.</strong></p>\n");
|
||||
} else {
|
||||
html.append("<p class=\"result\"><strong>The circuits do not match.</strong></p>\n");
|
||||
}
|
||||
// Main result
|
||||
html.append(" <p class=\"result\"><strong>The circuits ").append(results.matches() ? "match" : "do not match").append(".</strong></p>\n");
|
||||
|
||||
if (!results.matches()) {
|
||||
// Component differences section
|
||||
if (!results.componentDiffs().isEmpty()) {
|
||||
html.append("<h2>Component Differences</h2>\n");
|
||||
html.append("<table>\n");
|
||||
html.append("<tr><th>Component</th><th>Status</th></tr>\n");
|
||||
|
||||
for (ComponentDiff diff : results.componentDiffs()) {
|
||||
html.append("<tr>\n");
|
||||
html.append("<td>").append(diff.componentName()).append("</td>\n");
|
||||
html.append("<td>");
|
||||
html.append(diff.presentInCurrent() ? "Missing in target circuit" : "Extra in target circuit");
|
||||
html.append("</td>\n");
|
||||
html.append("</tr>\n");
|
||||
html.append(" <div class=\"section\">\n");
|
||||
html.append(" <h2>Component Differences</h2>\n");
|
||||
html.append(" <table>\n");
|
||||
html.append(" <tr>\n");
|
||||
html.append(" <th>Component</th>\n");
|
||||
html.append(" <th>Status</th>\n");
|
||||
html.append(" </tr>\n");
|
||||
|
||||
List<ComponentDiff> missingComponents = results.componentDiffs().stream()
|
||||
.filter(ComponentDiff::presentInCurrent)
|
||||
.collect(Collectors.toList());
|
||||
List<ComponentDiff> extraComponents = results.componentDiffs().stream()
|
||||
.filter(diff -> !diff.presentInCurrent())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (ComponentDiff diff : missingComponents) {
|
||||
html.append(" <tr>\n");
|
||||
html.append(" <td>").append(diff.componentName()).append("</td>\n");
|
||||
html.append(" <td>Missing in target circuit</td>\n");
|
||||
html.append(" </tr>\n");
|
||||
}
|
||||
|
||||
html.append("</table>\n");
|
||||
|
||||
for (ComponentDiff diff : extraComponents) {
|
||||
html.append(" <tr>\n");
|
||||
html.append(" <td>").append(diff.componentName()).append("</td>\n");
|
||||
html.append(" <td>Extra in target circuit</td>\n");
|
||||
html.append(" </tr>\n");
|
||||
}
|
||||
|
||||
html.append(" </table>\n");
|
||||
html.append(" </div>\n");
|
||||
}
|
||||
|
||||
// Connection differences section
|
||||
if (!results.connectionDiffs().isEmpty()) {
|
||||
html.append("<h2>Connection Differences</h2>\n");
|
||||
html.append("<table>\n");
|
||||
html.append("<tr><th>From Component</th><th>From Node</th><th>To Component</th><th>To Node</th><th>Status</th></tr>\n");
|
||||
|
||||
for (ConnectionDiff diff : results.connectionDiffs()) {
|
||||
html.append("<tr>\n");
|
||||
html.append("<td>").append(diff.fromComponent()).append("</td>\n");
|
||||
html.append("<td>").append(diff.fromNodeName()).append("</td>\n");
|
||||
html.append("<td>").append(diff.toComponent()).append("</td>\n");
|
||||
html.append("<td>").append(diff.toNodeName()).append("</td>\n");
|
||||
html.append("<td>");
|
||||
html.append(diff.presentInCurrent() ? "Missing in target circuit" : "Extra in target circuit");
|
||||
html.append("</td>\n");
|
||||
html.append("</tr>\n");
|
||||
html.append(" <div class=\"section\">\n");
|
||||
html.append(" <h2>Connection Differences</h2>\n");
|
||||
html.append(" <table>\n");
|
||||
html.append(" <tr>\n");
|
||||
html.append(" <th>From Component</th>\n");
|
||||
html.append(" <th>From Node</th>\n");
|
||||
html.append(" <th>To Component</th>\n");
|
||||
html.append(" <th>To Node</th>\n");
|
||||
html.append(" <th>Status</th>\n");
|
||||
html.append(" </tr>\n");
|
||||
|
||||
List<ConnectionDiff> missingConnections = results.connectionDiffs().stream()
|
||||
.filter(ConnectionDiff::presentInCurrent)
|
||||
.collect(Collectors.toList());
|
||||
List<ConnectionDiff> extraConnections = results.connectionDiffs().stream()
|
||||
.filter(diff -> !diff.presentInCurrent())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (ConnectionDiff diff : missingConnections) {
|
||||
html.append(" <tr>\n");
|
||||
html.append(" <td>").append(diff.fromComponent()).append("</td>\n");
|
||||
html.append(" <td>").append(diff.fromNodeName()).append("</td>\n");
|
||||
html.append(" <td>").append(diff.toComponent()).append("</td>\n");
|
||||
html.append(" <td>").append(diff.toNodeName()).append("</td>\n");
|
||||
html.append(" <td>Missing in target circuit</td>\n");
|
||||
html.append(" </tr>\n");
|
||||
}
|
||||
|
||||
html.append("</table>\n");
|
||||
|
||||
for (ConnectionDiff diff : extraConnections) {
|
||||
html.append(" <tr>\n");
|
||||
html.append(" <td>").append(diff.fromComponent()).append("</td>\n");
|
||||
html.append(" <td>").append(diff.fromNodeName()).append("</td>\n");
|
||||
html.append(" <td>").append(diff.toComponent()).append("</td>\n");
|
||||
html.append(" <td>").append(diff.toNodeName()).append("</td>\n");
|
||||
html.append(" <td>Extra in target circuit</td>\n");
|
||||
html.append(" </tr>\n");
|
||||
}
|
||||
|
||||
html.append(" </table>\n");
|
||||
html.append(" </div>\n");
|
||||
}
|
||||
}
|
||||
|
||||
html.append("</body>\n");
|
||||
html.append("</html>");
|
||||
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
}
|
||||
+21
-34
@@ -48,42 +48,34 @@ public class CompareServiceTest {
|
||||
|
||||
@Test
|
||||
public void testCompare_MissingConnectionsInSecondNetlist() {
|
||||
Map<String, IDIYComponent<?>> componentMap1 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap2 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap = new HashMap<>();
|
||||
// Group will have 3 nodes
|
||||
Netlist netlist1 = createNetlist(componentMap1, "Component1", "Node1", "Component2", "Node2", "Component3", "Node3");
|
||||
Netlist netlist2 = createNetlist(componentMap2, "Component1", "Node1"); // Missing group with 2 nodes
|
||||
Netlist netlist1 = createNetlist(componentMap, "Component1", "Node1", "Component2", "Node2", "Component3", "Node3");
|
||||
Netlist netlist2 = createNetlist(componentMap, "Component1", "Node1"); // Missing group with 2 nodes
|
||||
|
||||
CompareResults results = compareService.compare(netlist1, netlist2);
|
||||
|
||||
assertTrue(!results.matches());
|
||||
// 2 components missing in second netlist = 2 component diffs
|
||||
// 2 components missing = 2 component diffs
|
||||
assertEquals(2, results.componentDiffs().size());
|
||||
// 3 nodes = 3 connections (1-2, 1-3, 2-3)
|
||||
assertEquals(3, results.connectionDiffs().size());
|
||||
|
||||
// Verify all component diffs are from first netlist
|
||||
assertTrue(results.componentDiffs().stream().allMatch(ComponentDiff::presentInCurrent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompare_MissingConnectionsInFirstNetlist() {
|
||||
Map<String, IDIYComponent<?>> componentMap1 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap2 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap = new HashMap<>();
|
||||
// Group will have 3 nodes
|
||||
Netlist netlist1 = createNetlist(componentMap1, "Component1", "Node1");
|
||||
Netlist netlist2 = createNetlist(componentMap2, "Component1", "Node1", "Component2", "Node2", "Component3", "Node3");
|
||||
Netlist netlist1 = createNetlist(componentMap, "Component1", "Node1");
|
||||
Netlist netlist2 = createNetlist(componentMap, "Component1", "Node1", "Component2", "Node2", "Component3", "Node3");
|
||||
|
||||
CompareResults results = compareService.compare(netlist1, netlist2);
|
||||
|
||||
assertTrue(!results.matches());
|
||||
// 2 components missing in first netlist = 2 component diffs
|
||||
// 2 components missing = 2 component diffs
|
||||
assertEquals(2, results.componentDiffs().size());
|
||||
// 2 nodes = 1 connection (2-3)
|
||||
assertEquals(1, results.connectionDiffs().size());
|
||||
|
||||
// Verify all component diffs are from second netlist
|
||||
assertTrue(results.componentDiffs().stream().noneMatch(ComponentDiff::presentInCurrent));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,16 +150,15 @@ public class CompareServiceTest {
|
||||
|
||||
@Test
|
||||
public void testCompare_MultipleGroups_ExtraGroup() {
|
||||
Map<String, IDIYComponent<?>> componentMap1 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap2 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap = new HashMap<>();
|
||||
// Each group has 2 nodes
|
||||
Netlist netlist1 = new Netlist(new ArrayList<>());
|
||||
netlist1.add(createGroup(componentMap1, "Component1", "Node1", "Component2", "Node2"));
|
||||
netlist1.add(createGroup(componentMap1, "Component3", "Node3", "Component4", "Node4"));
|
||||
netlist1.add(createGroup(componentMap, "Component1", "Node1", "Component2", "Node2"));
|
||||
netlist1.add(createGroup(componentMap, "Component3", "Node3", "Component4", "Node4"));
|
||||
Netlist netlist2 = new Netlist(new ArrayList<>());
|
||||
netlist2.add(createGroup(componentMap2, "Component1", "Node1", "Component2", "Node2"));
|
||||
netlist2.add(createGroup(componentMap2, "Component3", "Node3", "Component4", "Node4"));
|
||||
netlist2.add(createGroup(componentMap2, "Component5", "Node5", "Component6", "Node6"));
|
||||
netlist2.add(createGroup(componentMap, "Component1", "Node1", "Component2", "Node2"));
|
||||
netlist2.add(createGroup(componentMap, "Component3", "Node3", "Component4", "Node4"));
|
||||
netlist2.add(createGroup(componentMap, "Component5", "Node5", "Component6", "Node6"));
|
||||
|
||||
CompareResults results = compareService.compare(netlist1, netlist2);
|
||||
|
||||
@@ -176,28 +167,24 @@ public class CompareServiceTest {
|
||||
assertEquals(2, results.componentDiffs().size());
|
||||
// 1 connection in extra group = 1 connection diff
|
||||
assertEquals(1, results.connectionDiffs().size());
|
||||
|
||||
// Verify all component diffs are from second netlist
|
||||
assertTrue(results.componentDiffs().stream().noneMatch(ComponentDiff::presentInCurrent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompare_MultipleGroups_DifferentConnections() {
|
||||
Map<String, IDIYComponent<?>> componentMap1 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap2 = new HashMap<>();
|
||||
Map<String, IDIYComponent<?>> componentMap = new HashMap<>();
|
||||
// Each group has 2 nodes
|
||||
Netlist netlist1 = new Netlist(new ArrayList<>());
|
||||
netlist1.add(createGroup(componentMap1, "Component1", "Node1", "Component2", "Node2"));
|
||||
netlist1.add(createGroup(componentMap1, "Component3", "Node3", "Component4", "Node4"));
|
||||
netlist1.add(createGroup(componentMap, "Component1", "Node1", "Component2", "Node2"));
|
||||
netlist1.add(createGroup(componentMap, "Component3", "Node3", "Component4", "Node4"));
|
||||
Netlist netlist2 = new Netlist(new ArrayList<>());
|
||||
netlist2.add(createGroup(componentMap2, "Component1", "Node1", "Component3", "Node3"));
|
||||
netlist2.add(createGroup(componentMap2, "Component2", "Node2", "Component4", "Node4"));
|
||||
netlist2.add(createGroup(componentMap, "Component1", "Node1", "Component3", "Node3"));
|
||||
netlist2.add(createGroup(componentMap, "Component2", "Node2", "Component4", "Node4"));
|
||||
|
||||
CompareResults results = compareService.compare(netlist1, netlist2);
|
||||
|
||||
assertTrue(!results.matches());
|
||||
// No component diffs since all components exist in both netlists
|
||||
assertEquals(0, results.componentDiffs().size());
|
||||
// 4 components in different groups = 4 component diffs
|
||||
assertEquals(4, results.componentDiffs().size());
|
||||
// 2 connections in each group = 4 connection diffs
|
||||
assertEquals(4, results.connectionDiffs().size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user