2024-02-12 19:45:35 -08:00
|
|
|
package com.rusefi.can.analysis;
|
|
|
|
|
|
|
|
import com.rusefi.can.CANPacket;
|
2024-04-10 15:36:17 -07:00
|
|
|
import com.rusefi.can.reader.dbc.DbcFile;
|
|
|
|
import com.rusefi.can.reader.dbc.DbcPacket;
|
2024-02-12 19:45:35 -08:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.Writer;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TreeMap;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
public class PacketRatio {
|
|
|
|
|
2024-04-10 15:36:17 -07:00
|
|
|
public static void write(DbcFile dbc, String reportDestinationFolder, List<CANPacket> logFileContent, String simpleFileName) throws IOException {
|
2024-02-12 19:45:35 -08:00
|
|
|
|
|
|
|
Map<Integer, AtomicInteger> countBySID = new TreeMap<>();
|
|
|
|
|
|
|
|
for (CANPacket packet : logFileContent) {
|
|
|
|
AtomicInteger counter = countBySID.computeIfAbsent(packet.getId(), integer -> new AtomicInteger());
|
|
|
|
counter.incrementAndGet();
|
|
|
|
}
|
|
|
|
|
2024-02-13 07:40:45 -08:00
|
|
|
Writer w = new FileWriter(reportDestinationFolder + File.separator + "distribution_" + simpleFileName + ".txt");
|
2024-02-12 19:45:35 -08:00
|
|
|
|
|
|
|
for (Map.Entry<Integer, AtomicInteger> e : countBySID.entrySet()) {
|
|
|
|
double ratio = 100.0 * e.getValue().get() / logFileContent.size();
|
2024-04-10 15:36:17 -07:00
|
|
|
Integer sid = e.getKey();
|
|
|
|
DbcPacket packet = dbc == null ? null : dbc.packets.get(sid);
|
|
|
|
String key = packet == null ? Integer.toString(sid) : packet.getName();
|
|
|
|
w.write(key + ": " + ratio + "\n");
|
2024-02-12 19:45:35 -08:00
|
|
|
}
|
|
|
|
w.close();
|
|
|
|
}
|
|
|
|
}
|