Comparing each file with each file
This commit is contained in:
parent
8d67dad8f5
commit
31fdf3eff1
|
@ -2,12 +2,15 @@ package com.rusefi.can;
|
|||
|
||||
import com.rusefi.can.reader.CANLineReader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
|
||||
public class ByteRateOfChange {
|
||||
|
||||
public static void process(String fullFileName) throws IOException {
|
||||
public static TraceReport process(String fullFileName, String reportDestinationFolder, String simpleFileName) throws IOException {
|
||||
List<CANPacket> packets = CANLineReader.getReader().readFile(fullFileName);
|
||||
|
||||
HashMap<ByteId, ByteStatistics> statistics = new HashMap<>();
|
||||
|
@ -25,13 +28,16 @@ public class ByteRateOfChange {
|
|||
|
||||
System.out.println(allStats);
|
||||
|
||||
PrintStream ps = new PrintStream(new FileOutputStream(reportDestinationFolder + File.separator + simpleFileName + ".txt", false));
|
||||
|
||||
for (ByteStatistics byteStatistics : allStats) {
|
||||
ByteId key = byteStatistics.key;
|
||||
System.out.println(dualSid(key.sid) + " at index " + key.index + " has " + byteStatistics.getUniqueValues() + " unique values");
|
||||
ps.println(dualSid(key.sid) + " at index " + key.index + " has " + byteStatistics.getUniqueValues() + " unique value(s)");
|
||||
}
|
||||
|
||||
ps.close();
|
||||
|
||||
return new TraceReport(simpleFileName, statistics);
|
||||
}
|
||||
|
||||
public static String dualSid(int sid) {
|
||||
|
@ -91,4 +97,21 @@ public class ByteRateOfChange {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TraceReport extends HashMap<ByteId, ByteStatistics> {
|
||||
private final String simpleFileName;
|
||||
private final HashMap<ByteId, ByteStatistics> statistics;
|
||||
|
||||
public TraceReport(String simpleFileName, HashMap<ByteId, ByteStatistics> statistics) {
|
||||
this.simpleFileName = simpleFileName;
|
||||
this.statistics = statistics;
|
||||
}
|
||||
|
||||
public String getSimpleFileName() {
|
||||
return simpleFileName;
|
||||
}
|
||||
|
||||
public HashMap<ByteId, ByteStatistics> getStatistics() {
|
||||
return statistics;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,6 @@ public class ConvertTrcToMegaLogViewerWithDBC {
|
|||
};
|
||||
|
||||
|
||||
FolderUtil.handleFolder(inputFolderName, fileAction);
|
||||
FolderUtil.handleFolder(inputFolderName, fileAction, ".trc");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import java.io.IOException;
|
|||
import java.util.Objects;
|
||||
|
||||
public class FolderUtil {
|
||||
public static void handleFolder(String inputFolderName, FileAction fileAction) throws IOException {
|
||||
public static void handleFolder(String inputFolderName, FileAction fileAction, String suffix) throws IOException {
|
||||
File inputFolder = new File(inputFolderName);
|
||||
for (String simpleFileName : Objects.requireNonNull(inputFolder.list((dir, name) -> name.endsWith(".trc")))) {
|
||||
for (String simpleFileName : Objects.requireNonNull(inputFolder.list((dir, name) -> name.endsWith(suffix)))) {
|
||||
System.out.println("Handling input file " + simpleFileName);
|
||||
String fullInputFile = inputFolderName + File.separator + simpleFileName;
|
||||
|
||||
|
|
|
@ -1,13 +1,67 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import com.rusefi.can.reader.ReaderType;
|
||||
import com.rusefi.util.FolderUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ByteRateOfChangeSandbox {
|
||||
public static void main(String[] args) throws IOException {
|
||||
ReaderTypeHolder.INSTANCE.type = ReaderType.CANHACKER;
|
||||
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
|
||||
|
||||
ByteRateOfChange.process("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Nissan\\2011_Xterra\\2011-nissan-CAN-June-2021\\engine-not-running.trc");
|
||||
String folder = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\Nissan\\2011_Xterra\\2011-nissan-CAN-June-2021";
|
||||
|
||||
String reportDestinationFolder = folder + File.separator + "processed";
|
||||
new File(reportDestinationFolder).mkdirs();
|
||||
|
||||
|
||||
List<ByteRateOfChange.TraceReport> reports = new ArrayList<>();
|
||||
|
||||
FolderUtil.handleFolder(folder, new FolderUtil.FileAction() {
|
||||
@Override
|
||||
public void doJob(String simpleFileName, String fullFileName) throws IOException {
|
||||
ByteRateOfChange.TraceReport report = ByteRateOfChange.process(fullFileName, reportDestinationFolder, simpleFileName);
|
||||
reports.add(report);
|
||||
}
|
||||
}, "pcan.trc");
|
||||
|
||||
|
||||
for (int i = 0; i < reports.size(); i++) {
|
||||
for (int j = i + 1; j < reports.size(); j++)
|
||||
compare(reports.get(i), reports.get(j));
|
||||
}
|
||||
}
|
||||
|
||||
private static void compare(ByteRateOfChange.TraceReport traceReport1, ByteRateOfChange.TraceReport traceReport2) {
|
||||
Set<ByteRateOfChange.ByteId> allKeys = new HashSet<>();
|
||||
allKeys.addAll(traceReport1.getStatistics().keySet());
|
||||
allKeys.addAll(traceReport2.getStatistics().keySet());
|
||||
|
||||
PrintStream report = System.out;
|
||||
|
||||
report.println("Between " + traceReport1.getSimpleFileName() + " and " + traceReport2.getSimpleFileName());
|
||||
|
||||
int totalDifferences = 0;
|
||||
|
||||
for (ByteRateOfChange.ByteId id : allKeys) {
|
||||
ByteRateOfChange.ByteStatistics s1 = traceReport1.getStatistics().computeIfAbsent(id, byteId -> new ByteRateOfChange.ByteStatistics(byteId));
|
||||
ByteRateOfChange.ByteStatistics s2 = traceReport2.getStatistics().computeIfAbsent(id, byteId -> new ByteRateOfChange.ByteStatistics(byteId));
|
||||
|
||||
if (s1.getUniqueValues() != s2.getUniqueValues()) {
|
||||
report.println(id + ": " + s1.getUniqueValues() + " vs " + s2.getUniqueValues());
|
||||
totalDifferences++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
report.println(totalDifferences + " total differences");
|
||||
report.println();
|
||||
report.println();
|
||||
report.println();
|
||||
report.println();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue