nicer package structure
This commit is contained in:
parent
95ce658d5f
commit
79c5eaae69
|
@ -2,6 +2,7 @@ package com.rusefi.can;
|
|||
|
||||
import com.rusefi.can.reader.CANLineReader;
|
||||
import com.rusefi.can.reader.dbc.DbcFile;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.util.FolderUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.can;
|
|||
|
||||
import com.rusefi.can.reader.ReaderType;
|
||||
import com.rusefi.can.reader.dbc.DbcFile;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.rusefi.can;
|
||||
package com.rusefi.can.analysis;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.mlv.LoggingContext;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.can.reader.CANLineReader;
|
||||
import com.rusefi.sensor_logs.BinaryLogEntry;
|
||||
import com.rusefi.sensor_logs.BinarySensorLog;
|
||||
|
@ -39,7 +42,9 @@ public class ByteRateOfChange {
|
|||
|
||||
ps.close();
|
||||
|
||||
TraceReport traceReport = new TraceReport(simpleFileName, statistics);
|
||||
double duration = packets.isEmpty() ? 0 : packets.get(packets.size() - 1).getTimeStamp() - packets.get(0).getTimeStamp();
|
||||
|
||||
TraceReport traceReport = new TraceReport(simpleFileName, statistics, duration);
|
||||
traceReport.createMegaLogViewer(packets);
|
||||
return traceReport;
|
||||
}
|
||||
|
@ -48,7 +53,7 @@ public class ByteRateOfChange {
|
|||
return String.format("%d/0x%x", sid, sid);
|
||||
}
|
||||
|
||||
static class ByteStatistics {
|
||||
public static class ByteStatistics {
|
||||
HashSet<Integer> uniqueValues = new HashSet<>();
|
||||
private final ByteId key;
|
||||
|
||||
|
@ -70,7 +75,7 @@ public class ByteRateOfChange {
|
|||
}
|
||||
|
||||
|
||||
static class ByteId {
|
||||
public static class ByteId {
|
||||
final int sid;
|
||||
final int index;
|
||||
|
||||
|
@ -105,10 +110,16 @@ public class ByteRateOfChange {
|
|||
public static class TraceReport extends HashMap<ByteId, ByteStatistics> {
|
||||
private final String simpleFileName;
|
||||
private final HashMap<ByteId, ByteStatistics> statistics;
|
||||
private double duration;
|
||||
|
||||
public TraceReport(String simpleFileName, HashMap<ByteId, ByteStatistics> statistics) {
|
||||
public TraceReport(String simpleFileName, HashMap<ByteId, ByteStatistics> statistics, double duration) {
|
||||
this.simpleFileName = simpleFileName;
|
||||
this.statistics = statistics;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
String getSummary() {
|
||||
return getSimpleFileName() + " (duration=" + (int)(duration / 1000) + "secs)";
|
||||
}
|
||||
|
||||
public String getSimpleFileName() {
|
|
@ -0,0 +1,61 @@
|
|||
package com.rusefi.can.analysis;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ByteRateOfChangeReports {
|
||||
/**
|
||||
* sweet baby O(n^2)
|
||||
*/
|
||||
public static void compareEachReportAgainstAllOthers(List<ByteRateOfChange.TraceReport> reports) {
|
||||
for (int i = 0; i < reports.size(); i++) {
|
||||
for (int j = i + 1; j < reports.size(); j++)
|
||||
compareTwoReports(reports.get(i), reports.get(j));
|
||||
}
|
||||
}
|
||||
|
||||
private static void compareTwoReports(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("Comparing unique value count per byte " + traceReport1.getSummary() + " and " + traceReport2.getSummary());
|
||||
|
||||
List<ByteVariationDifference> differences = new ArrayList<>();
|
||||
|
||||
for (ByteRateOfChange.ByteId id : allKeys) {
|
||||
ByteRateOfChange.ByteStatistics s1 = traceReport1.getStatistics().computeIfAbsent(id, ByteRateOfChange.ByteStatistics::new);
|
||||
ByteRateOfChange.ByteStatistics s2 = traceReport2.getStatistics().computeIfAbsent(id, ByteRateOfChange.ByteStatistics::new);
|
||||
|
||||
if (s1.getUniqueValues() != s2.getUniqueValues()) {
|
||||
String msg = id + ": " + s1.getUniqueValues() + " vs " + s2.getUniqueValues();
|
||||
differences.add(new ByteVariationDifference(Math.abs(s1.getUniqueValues() - s2.getUniqueValues()), msg));
|
||||
}
|
||||
}
|
||||
differences.sort((o1, o2) -> o2.deltaCount - o1.deltaCount);
|
||||
|
||||
for (ByteVariationDifference difference : differences)
|
||||
report.println(difference.msg);
|
||||
|
||||
report.println(differences.size() + " total differences");
|
||||
report.println();
|
||||
report.println();
|
||||
report.println();
|
||||
report.println();
|
||||
}
|
||||
|
||||
static class ByteVariationDifference {
|
||||
private final int deltaCount;
|
||||
private final String msg;
|
||||
|
||||
public ByteVariationDifference(int deltaCount, String msg) {
|
||||
this.deltaCount = deltaCount;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi.can.reader.dbc;
|
||||
|
||||
import com.rusefi.can.LoggingStrategy;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.sensor_logs.BinaryLogEntry;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.rusefi.can;
|
||||
package com.rusefi.mlv;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.sensor_logs.BinaryLogEntry;
|
||||
import com.rusefi.sensor_logs.BinarySensorLog;
|
||||
|
||||
|
@ -9,11 +11,11 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
class LoggingContext {
|
||||
Map<String, Double> values = new HashMap<>();
|
||||
public class LoggingContext {
|
||||
public Map<String, Double> values = new HashMap<>();
|
||||
AtomicReference<Long> time = new AtomicReference<>();
|
||||
|
||||
BinarySensorLog<BinaryLogEntry> getBinaryLogEntryBinarySensorLog(Collection<BinaryLogEntry> entries, String outputFileName) {
|
||||
public BinarySensorLog<BinaryLogEntry> getBinaryLogEntryBinarySensorLog(Collection<BinaryLogEntry> entries, String outputFileName) {
|
||||
return new BinarySensorLog<>(o -> {
|
||||
Double value = this.values.get(o.getName());
|
||||
if (value == null)
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.can;
|
||||
package com.rusefi.mlv;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.can.reader.dbc.DbcField;
|
||||
import com.rusefi.can.reader.dbc.DbcFile;
|
||||
import com.rusefi.can.reader.dbc.DbcPacket;
|
||||
|
@ -45,7 +46,7 @@ public class LoggingStrategy {
|
|||
context.processPackets(packets, log, logger);
|
||||
}
|
||||
|
||||
interface PacketLogger {
|
||||
public interface PacketLogger {
|
||||
boolean takeValues(CANPacket packetContent);
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import com.rusefi.can.analysis.ByteRateOfChange;
|
||||
import com.rusefi.can.analysis.ByteRateOfChangeReports;
|
||||
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 {
|
||||
|
@ -27,57 +27,6 @@ public class ByteRateOfChangeSandbox {
|
|||
}, "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));
|
||||
}
|
||||
ByteRateOfChangeReports.compareEachReportAgainstAllOthers(reports);
|
||||
}
|
||||
|
||||
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("Comparing " + traceReport1.getSimpleFileName() + " and " + traceReport2.getSimpleFileName());
|
||||
|
||||
List<ByteVariationDifference> differences = new ArrayList<>();
|
||||
|
||||
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()) {
|
||||
String msg = id + ": " + s1.getUniqueValues() + " vs " + s2.getUniqueValues();
|
||||
differences.add(new ByteVariationDifference(Math.abs(s1.getUniqueValues() - s2.getUniqueValues()), msg));
|
||||
}
|
||||
}
|
||||
differences.sort(new Comparator<ByteVariationDifference>() {
|
||||
@Override
|
||||
public int compare(ByteVariationDifference o1, ByteVariationDifference o2) {
|
||||
return o2.deltaCount - o1.deltaCount;
|
||||
}
|
||||
});
|
||||
|
||||
for (ByteVariationDifference difference : differences)
|
||||
report.println(difference.msg);
|
||||
|
||||
report.println(differences.size() + " total differences");
|
||||
report.println();
|
||||
report.println();
|
||||
report.println();
|
||||
report.println();
|
||||
}
|
||||
|
||||
static class ByteVariationDifference {
|
||||
private int deltaCount;
|
||||
private String msg;
|
||||
|
||||
public ByteVariationDifference(int deltaCount, String msg) {
|
||||
this.deltaCount = deltaCount;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.rusefi.can.reader.impl;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.can.LoggingStrategy;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.can.reader.dbc.DbcField;
|
||||
import com.rusefi.can.reader.dbc.DbcFile;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi.can.reader.impl;
|
||||
|
||||
import com.rusefi.can.LoggingStrategy;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.can.reader.dbc.DbcField;
|
||||
import com.rusefi.can.reader.dbc.DbcFile;
|
||||
import com.rusefi.can.reader.dbc.DbcPacket;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.rusefi.can.reader.impl;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.can.LoggingStrategy;
|
||||
import com.rusefi.mlv.LoggingStrategy;
|
||||
import com.rusefi.can.reader.dbc.DbcFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
|
Loading…
Reference in New Issue