2024-09-15 22:47:45 -06:00
package com.ridgebotics.ridgescout.scoutingData ;
2024-06-26 13:31:31 -06:00
2025-04-04 14:15:30 -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 ;
2025-04-04 14:15:30 -06:00
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 ;
2024-06-26 17:24:00 -06:00
import java.util.ArrayList ;
2025-04-03 08:38:24 -06:00
import java.util.UUID ;
2024-06-26 17:24:00 -06:00
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
2025-04-04 14:15:30 -06:00
public class Fields {
2024-07-03 10:20:40 -06:00
// public static ScoutingVersion sv = new ScoutingVersion();
2024-06-26 17:24:00 -06:00
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 " ;
2024-06-26 17:24:00 -06:00
2025-04-03 08:38:24 -06:00
private static String uuid ( ) {
return UUID . randomUUID ( ) . toString ( ) ;
}
2025-04-04 14:15:30 -06:00
public static final FieldType [ ] [ ] default_match_fields = new FieldType [ ] [ ] {
2024-06-27 22:12:36 -06:00
{
2025-04-04 14:15:30 -06:00
new FieldposType ( uuid ( ) , " Auto start pos " , " Where does the robot start its auto? " , new int [ ] { 0 , 0 } ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new TallyType ( uuid ( ) , " Auto L4 Coral " , " How many coral did this robot score in L4 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Auto L3 Coral " , " How many coral did this robot score in L3 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Auto L2 Coral " , " How many coral did this robot score in L2 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Auto L1/Trough Coral " , " How many coral did this robot score in L1 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Auto Processor Algae " , " How many algae did this robot score in the Barge during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Auto Barge Algae " , " How many algae did this robot score in the Barge during auto? " , 0 ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new DropdownType ( uuid ( ) , " Auto Quality " , " How did the robot drive during auto? " , new String [ ] { " Smooth " , " Jittery " } , 0 ) ,
new TextType ( uuid ( ) , " Auto Comments " , " Anything interesting about auto " , " " ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new TallyType ( uuid ( ) , " Teleop L4 Coral " , " How many coral did this robot score in L4 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Teleop L3 Coral " , " How many coral did this robot score in L3 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Teleop L2 Coral " , " How many coral did this robot score in L2 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Teleop L1 Coral " , " How many coral did this robot score in L1 during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Teleop Processor Algae " , " How many algae did this robot score in the Barge during auto? " , 0 ) ,
new TallyType ( uuid ( ) , " Teleop Barge Algae " , " How many algae did this robot score in the Barge during auto? " , 0 ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new CheckboxType ( uuid ( ) , " Upper Algae Removal " , " Did the robot remove upper Algae? " , 0 ) ,
new CheckboxType ( uuid ( ) , " Lower Algae Removal " , " Did the robot remove lower Algae? " , 0 ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new DropdownType ( uuid ( ) , " Teleop Quality " , " How did the robot drive during Teleop? " , new String [ ] { " Smooth " , " Jittery " } , 0 ) ,
new TextType ( uuid ( ) , " Teleop Comments " , " Anything interesting about Teleop " , " " ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new DropdownType ( uuid ( ) , " Climb State " , " What was the final condition of the robot? " , new String [ ] { " Nothing " , " Continued Cycling " , " Park " , " Attempted Shallow " , " Shallow " , " Attempted Deep " , " Deep " } , 0 ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new DropdownType ( uuid ( ) , " Robot Condition " , " Was anything broken? " , new String [ ] { " Everything was working " , " Something was maybe broken " , " Something was broken " , " Robot was disabled for part of the match " , " Missing robot " } , 0 ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new TextType ( uuid ( ) , " Other Comments " , " Any other comments you have " , " " )
2024-07-30 17:41:28 -06:00
}
2024-06-27 22:12:36 -06:00
} ;
2024-06-26 17:24:00 -06:00
2025-04-04 14:15:30 -06:00
public static final FieldType [ ] [ ] default_pit_fields = new FieldType [ ] [ ] {
2024-06-28 15:44:38 -06:00
{
2025-04-04 14:15:30 -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
2025-04-04 14:15:30 -06:00
new DropdownType ( uuid ( ) , " Score Area " , " What does this robot score? " , new String [ ] { " Only Algae " , " Mostly Algae " , " Both " , " Mostly Coral " , " Only Coral " } , 0 ) ,
2025-02-28 22:54:02 -07:00
2025-04-04 14:15:30 -06:00
new CheckboxType ( uuid ( ) , " L4 Scoring " , " Will the robot score in Layer 4? " , 0 ) ,
new CheckboxType ( uuid ( ) , " L3 Scoring " , " Will the robot score in Layer 3? " , 0 ) ,
new CheckboxType ( uuid ( ) , " L2 Scoring " , " Will the robot score in Layer 3? " , 0 ) ,
new CheckboxType ( uuid ( ) , " L1/Trough Scoring " , " Will the robot score in Layer 1? " , 0 ) ,
new CheckboxType ( uuid ( ) , " Processor Scoring " , " Will the robot score in the Processor? " , 0 ) ,
new CheckboxType ( uuid ( ) , " Barge Scoring " , " Will the robot score algae in the Barge? " , 0 ) ,
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
2025-04-04 14:15:30 -06: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
2025-04-04 14:15:30 -06: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
2025-04-04 14:15:30 -06:00
new TextType ( uuid ( ) , " Cool Comments " , " Is there anything cool about the robot? " , " " ) ,
2025-03-07 12:24:16 -07:00
2025-04-04 14:15:30 -06:00
new TextType ( uuid ( ) , " Comments " , " Things go here " , " Day 1: \ n \ nDay 2: \ n \ nDay 3: \ n " )
2024-06-28 15:44:38 -06:00
}
} ;
2025-04-04 14:15:30 -06:00
public static boolean save ( String filename , FieldType [ ] [ ] values ) {
2024-06-26 17:24:00 -06:00
try {
ByteBuilder bb = new ByteBuilder ( ) ;
for ( int i = 0 ; i < values . length ; i + + ) {
bb . addRaw ( 127 , save_version ( values [ i ] ) ) ;
}
2025-04-04 14:15:30 -06:00
FileEditor . writeFile ( filename , bb . build ( ) ) ;
2024-06-26 17:24:00 -06:00
return true ;
} catch ( ByteBuilder . buildingException e ) {
2024-07-24 15:27:13 -06:00
AlertManager . error ( e ) ;
2024-06-26 17:24:00 -06:00
return false ;
// throw new RuntimeException(e);
}
}
2025-04-04 14:15:30 -06:00
private static byte [ ] save_version ( FieldType [ ] values ) throws ByteBuilder . buildingException {
2024-06-26 17:24:00 -06:00
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 ( ) ;
}
2025-04-04 14:15:30 -06:00
public static FieldType [ ] [ ] load ( String filename ) {
byte [ ] bytes = FileEditor . readFile ( filename ) ;
2024-06-26 17:24:00 -06:00
2024-07-03 19:31:20 -06:00
// System.out.println(bytes);
2024-06-27 22:12:36 -06:00
2024-06-26 17:24:00 -06:00
try {
BuiltByteParser bbp = new BuiltByteParser ( bytes ) ;
ArrayList < BuiltByteParser . parsedObject > objects = bbp . parse ( ) ;
2025-04-04 14:15:30 -06:00
FieldType [ ] [ ] values = new FieldType [ objects . size ( ) ] [ ] ;
2024-06-26 17:24:00 -06:00
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 ) {
2024-07-24 15:27:13 -06:00
AlertManager . error ( e ) ;
2024-06-28 15:44:38 -06:00
return null ;
2024-06-26 17:24:00 -06:00
}
}
2025-04-04 14:15:30 -06:00
private static FieldType [ ] load_version ( byte [ ] bytes ) throws BuiltByteParser . byteParsingExeption {
2024-06-26 17:24:00 -06:00
BuiltByteParser bbp = new BuiltByteParser ( bytes ) ;
ArrayList < BuiltByteParser . parsedObject > objects = bbp . parse ( ) ;
2025-04-04 14:15:30 -06:00
FieldType [ ] output = new FieldType [ objects . size ( ) ] ;
2024-06-26 17:24:00 -06:00
for ( int i = 0 ; i < objects . size ( ) ; i + + ) {
BuiltByteParser . parsedObject obj = objects . get ( i ) ;
2025-04-04 14:15:30 -06:00
FieldType t = null ;
2024-06-26 17:24:00 -06:00
switch ( obj . getType ( ) ) {
2025-04-04 14:15:30 -06:00
case FieldType . slider_type_id :
t = new SliderType ( ) ;
2024-06-26 17:24:00 -06:00
break ;
2025-04-04 14:15:30 -06:00
case FieldType . dropdownType :
t = new DropdownType ( ) ;
2024-06-26 17:24:00 -06:00
break ;
2025-04-04 14:15:30 -06:00
case FieldType . notesType :
t = new TextType ( ) ;
2024-06-26 17:24:00 -06:00
break ;
2025-04-04 14:15:30 -06:00
case FieldType . tallyType :
t = new TallyType ( ) ;
2024-09-28 12:43:19 -06:00
break ;
2025-04-04 14:15:30 -06:00
case FieldType . numberType :
t = new NumberType ( ) ;
2024-09-28 12:43:19 -06:00
break ;
2025-04-04 14:15:30 -06:00
case FieldType . checkboxType :
t = new CheckboxType ( ) ;
2024-09-28 12:43:19 -06:00
break ;
2025-04-04 14:15:30 -06:00
case FieldType . fieldposType :
t = new FieldposType ( ) ;
2024-07-29 22:29:59 -06:00
break ;
2024-06-26 17:24:00 -06:00
}
t . decode ( ( byte [ ] ) obj . get ( ) ) ;
2024-07-29 22:29:59 -06:00
output [ i ] = t ;
2024-06-26 17:24:00 -06:00
}
return output ;
}
2024-06-26 13:31:31 -06:00
}