Files
RidgeScout/app/src/main/java/com/ridgebotics/ridgescout/scoutingData/Fields.java
T

142 lines
6.0 KiB
Java
Raw Normal View History

2024-09-15 22:47:45 -06:00
package com.ridgebotics.ridgescout.scoutingData;
2024-06-26 13:31:31 -06:00
import com.ridgebotics.ridgescout.types.input.CheckboxType;
import com.ridgebotics.ridgescout.types.input.DropdownType;
import com.ridgebotics.ridgescout.types.input.FieldposType;
import com.ridgebotics.ridgescout.types.input.FieldType;
import com.ridgebotics.ridgescout.types.input.NumberType;
import com.ridgebotics.ridgescout.types.input.TallyType;
import com.ridgebotics.ridgescout.types.input.TextType;
import com.ridgebotics.ridgescout.types.input.SliderType;
2024-09-15 22:47:45 -06:00
import com.ridgebotics.ridgescout.utility.AlertManager;
import com.ridgebotics.ridgescout.utility.FileEditor;
2024-09-15 22:47:45 -06:00
import com.ridgebotics.ridgescout.utility.BuiltByteParser;
import com.ridgebotics.ridgescout.utility.ByteBuilder;
import java.util.ArrayList;
import java.util.UUID;
2025-04-21 12:06:37 -06:00
// The mechanism to load, save, and create the fields based off of the raw types from ScoutingDataWriter.java
public class Fields {
// public static ScoutingVersion sv = new ScoutingVersion();
2024-06-28 15:44:38 -06:00
public static final String matchFieldsFilename = "matches.fields";
2024-06-29 17:51:40 -06:00
public static final String pitsFieldsFilename = "pits.fields";
private static String uuid(){
return UUID.randomUUID().toString();
}
public static final FieldType[][] default_match_fields = new FieldType[][] {
2024-06-27 22:12:36 -06:00
{
2026-02-13 17:26:07 -07:00
new FieldposType(uuid(),"Auto start pos", "Where does the robot start its auto?", new int[]{0,0})
2024-07-30 17:41:28 -06:00
}
2024-06-27 22:12:36 -06:00
};
public static final FieldType[][] default_pit_fields = new FieldType[][] {
2024-06-28 15:44:38 -06:00
{
new DropdownType(uuid(),"Drivetrain type", "What type of drivetrain does this team have?", new String[]{"Swerve Drive", "Tank Drive (Differential)", "Other, Info in comments"}, 0),
new DropdownType(uuid(),"Intake type", "What type of intake does this team have?", new String[]{"Ground only", "Player Station only", "Both", "Other, Info in comments"}, 0),
new DropdownType(uuid(),"Intake Consistency", "How consistent is the robot at intakeing?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0),
2025-02-28 22:54:02 -07:00
new DropdownType(uuid(),"Scoring Consistency", "How consistent is the robot at Scoring?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0),
2025-02-28 22:54:02 -07:00
new TextType(uuid(),"Auto Capability", "What autos does this team have?", ""),
new DropdownType(uuid(),"Auto Consistency", "How consistent is the robot at Auto?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0),
2025-02-28 22:54:02 -07:00
new DropdownType(uuid(),"Climb type", "What does the robot do to climb?", new String[]{"No Climb", "Only Shallow", "Only Deep", "Both Shallow and Deep"}, 0),
new DropdownType(uuid(),"Climb Consistency", "How consistent is the robot at climbing?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0),
2025-02-28 22:54:02 -07:00
new TextType(uuid(),"Cool Comments", "Is there anything cool about the robot?", ""),
new TextType(uuid(),"Comments", "Things go here", "Day 1:\n\nDay 2:\n\nDay 3:\n")
2024-06-28 15:44:38 -06:00
}
};
public static boolean save(String filename, FieldType[][] values){
try {
ByteBuilder bb = new ByteBuilder();
for (int i = 0; i < values.length; i++) {
bb.addRaw(127, save_version(values[i]));
}
FileEditor.writeFile(filename, bb.build());
return true;
}catch (ByteBuilder.buildingException e) {
AlertManager.error(e);
return false;
// throw new RuntimeException(e);
}
}
private static byte[] save_version(FieldType[] values) throws ByteBuilder.buildingException {
ByteBuilder bb = new ByteBuilder();
for(int i =0; i < values.length; i++){
bb.addRaw(values[i].get_byte_id(), values[i].encode());
}
return bb.build();
}
public static FieldType[][] load(String filename){
byte[] bytes = FileEditor.readFile(filename);
2024-07-03 19:31:20 -06:00
// System.out.println(bytes);
2024-06-27 22:12:36 -06:00
try {
BuiltByteParser bbp = new BuiltByteParser(bytes);
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
FieldType[][] values = new FieldType[objects.size()][];
for(int i = 0 ; i < objects.size(); i++){
values[i] = load_version((byte[]) objects.get(i).get());
}
2024-06-28 15:44:38 -06:00
return values;
2024-06-27 22:12:36 -06:00
} catch (Exception e) {
AlertManager.error(e);
2024-06-28 15:44:38 -06:00
return null;
}
}
private static FieldType[] load_version(byte[] bytes) throws BuiltByteParser.byteParsingExeption{
BuiltByteParser bbp = new BuiltByteParser(bytes);
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
FieldType[] output = new FieldType[objects.size()];
for(int i = 0 ; i < objects.size(); i++){
BuiltByteParser.parsedObject obj = objects.get(i);
FieldType t = null;
switch (obj.getType()){
case FieldType.slider_type_id:
t = new SliderType();
break;
case FieldType.dropdownType:
t = new DropdownType();
break;
case FieldType.notesType:
t = new TextType();
break;
case FieldType.tallyType:
t = new TallyType();
2024-09-28 12:43:19 -06:00
break;
case FieldType.numberType:
t = new NumberType();
2024-09-28 12:43:19 -06:00
break;
case FieldType.checkboxType:
t = new CheckboxType();
2024-09-28 12:43:19 -06:00
break;
case FieldType.fieldposType:
t = new FieldposType();
2024-07-29 22:29:59 -06:00
break;
}
t.decode((byte[]) obj.get());
2024-07-29 22:29:59 -06:00
output[i] = t;
}
return output;
}
2024-06-26 13:31:31 -06:00
}