only:Improve toolset for default tune canned tune generation #4871

This commit is contained in:
rusefillc 2023-06-17 10:21:53 -04:00
parent f68cdbf4e2
commit 9da3bcc9b4
2 changed files with 49 additions and 23 deletions

View File

@ -29,6 +29,7 @@ public class IniFileModel {
// this is only used while reading model - TODO extract reader
private final List<DialogModel.Field> fieldsOfCurrentDialog = new ArrayList<>();
public Map<String, IniField> allIniFields = new LinkedHashMap<>();
public final List<DialogModel.Field> fieldsInUiOrder = new ArrayList<>();
public Map<String, String> tooltips = new TreeMap<>();
public Map<String, String> protocolMeta = new TreeMap<>();
@ -101,6 +102,7 @@ public class IniFileModel {
if (dialogUiName == null)
dialogUiName = dialogId;
dialogs.put(dialogUiName, new DialogModel(dialogId, dialogUiName, fieldsOfCurrentDialog));
fieldsInUiOrder.addAll(fieldsOfCurrentDialog);
dialogId = null;
fieldsOfCurrentDialog.clear();
@ -164,6 +166,9 @@ public class IniFileModel {
switch (first) {
case "field":
handleField(list);
break;
case "dialog":
handleDialog(list);
break;
@ -245,6 +250,20 @@ public class IniFileModel {
allIniFields.put(field.getName(), field);
}
private void handleField(LinkedList<String> list) {
list.removeFirst(); // "field"
String uiFieldName = list.isEmpty() ? "" : list.removeFirst();
String key = list.isEmpty() ? null : list.removeFirst();
DialogModel.Field field = new DialogModel.Field(key, uiFieldName);
if (key != null)
fieldsOfCurrentDialog.add(field);
log.debug("IniFileModel: Field label=[" + uiFieldName + "] : key=[" + key + "]");
}
private void handleDialog(LinkedList<String> list) {
finishDialog();
list.removeFirst(); // "dialog"

View File

@ -1,14 +1,16 @@
package com.rusefi.tune;
import com.opensr5.ini.DialogModel;
import com.opensr5.ini.IniFileModel;
import com.rusefi.core.preferences.storage.Node;
import com.rusefi.tune.xml.Constant;
import com.rusefi.tune.xml.Msq;
import com.rusefi.tune.xml.Page;
import org.junit.Assert;
import org.junit.Test;
import static com.rusefi.tune.TuneReadWriteTest.SRC_TEST_RESOURCES;
import static com.rusefi.tune.TuneReadWriteTest.TEST_INI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
public class LoadOlderTuneTest {
@ -20,35 +22,40 @@ public class LoadOlderTuneTest {
Msq lessOldDefaultTune = Msq.readTune(SRC_TEST_RESOURCES + "simulator_tune-2023-06.xml");
int noLongerPresent = 0;
int sameValueCounter = 0;
int notSameValueCounter = 0;
IniFileModel ini = new IniFileModel().readIniFile(TEST_INI);
assertFalse(ini.fieldsInUiOrder.isEmpty());
for (String name : ini.allIniFields.keySet()) {
StringBuilder sb = new StringBuilder();
for (DialogModel.Field f : ini.fieldsInUiOrder) {
String name = f.getKey();
Constant customValue = customOldTune.getConstantsAsMap().get(name);
Constant newerDefault = lessOldDefaultTune.getConstantsAsMap().get(name);
if (newerDefault == null) {
noLongerPresent++;
System.out.println("No longer present " + name);
} else {
boolean isSameValue = simplerSpaces(newerDefault.getValue()).equals(simplerSpaces(customValue.getValue()));
if (isSameValue) {
System.out.println("Still around " + name);
sameValueCounter++;
} else {
notSameValueCounter++;
System.out.println("Newer default " + newerDefault + " older value " + customValue);
Constant defaultValue = lessOldDefaultTune.getConstantsAsMap().get(name);
if (defaultValue == null) {
// no longer present
continue;
}
boolean isSameValue = simplerSpaces(defaultValue.getValue()).equals(simplerSpaces(customValue.getValue()));
if (!isSameValue) {
if (!Node.isNumeric(customValue.getValue())) {
// todo: smarter logic for enums
continue;
}
sb.append("\tengineConfiguration->" + customValue.getName() + " = " + customValue.getValue() + ";\n");
}
}
Assert.assertTrue(noLongerPresent > 0);
Assert.assertTrue(sameValueCounter > 0);
Assert.assertTrue(notSameValueCounter > 0);
System.out.printf(ini.toString());
assertEquals("\tengineConfiguration->cylindersCount = 4;\n" +
"\tengineConfiguration->tps1SecondaryMin = 0.0;\n" +
"\tengineConfiguration->tps1SecondaryMax = 1000.0;\n" +
"\tengineConfiguration->tps2SecondaryMin = 0.0;\n" +
"\tengineConfiguration->tps2SecondaryMax = 1000.0;\n" +
"\tengineConfiguration->throttlePedalSecondaryUpVoltage = 0.0;\n" +
"\tengineConfiguration->mc33_hvolt = 0.0;\n" +
"\tengineConfiguration->mc33_i_boost = 0.0;\n" +
"\tengineConfiguration->mc33_i_peak = 0.0;\n" +
"\tengineConfiguration->mc33_i_hold = 0.0;\n" +
"\tengineConfiguration->mc33_t_max_boost = 0.", sb.substring(0, 500));
}
private static Object simplerSpaces(String value) {