2024-06-27 22:12:36 -06:00
package com.astatin3.scoutingapp2025.scoutingData ;
2024-06-26 13:31:31 -06:00
2024-07-03 10:20:40 -06:00
import com.astatin3.scoutingapp2025.types.input.dropdownType ;
import com.astatin3.scoutingapp2025.types.input.inputType ;
2024-07-29 22:29:59 -06:00
import com.astatin3.scoutingapp2025.types.input.tallyType ;
2024-07-23 12:27:45 -06:00
import com.astatin3.scoutingapp2025.types.input.textType ;
2024-07-03 10:20:40 -06:00
import com.astatin3.scoutingapp2025.types.input.sliderType ;
2024-07-23 12:27:45 -06:00
import com.astatin3.scoutingapp2025.types.input.textType ;
2024-07-29 22:29:59 -06:00
import com.astatin3.scoutingapp2025.ui.scouting.TallyCounterView ;
2024-07-24 15:27:13 -06:00
import com.astatin3.scoutingapp2025.utility.AlertManager ;
2024-06-28 15:44:38 -06:00
import com.astatin3.scoutingapp2025.utility.fileEditor ;
2024-06-27 22:12:36 -06:00
import com.astatin3.scoutingapp2025.utility.BuiltByteParser ;
import com.astatin3.scoutingapp2025.utility.ByteBuilder ;
2024-06-26 17:24:00 -06:00
import java.util.ArrayList ;
2024-06-26 13:31:31 -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
2024-07-03 10:20:40 -06:00
public static final inputType [ ] [ ] default_match_fields = new inputType [ ] [ ] {
2024-06-27 22:12:36 -06:00
{
2024-07-30 17:41:28 -06:00
new tallyType ( " Auto Notes " , 0 ) ,
2024-09-14 18:02:31 -06:00
new sliderType ( " Auto Performance " , 5 , 0 , 10 ) ,
new textType ( " Auto Comments " , " " ) ,
2024-07-30 17:41:28 -06:00
new tallyType ( " Teleop Notes " , 0 ) ,
2024-09-14 18:02:31 -06:00
new sliderType ( " Teleop Performance " , 5 , 0 , 10 ) ,
new textType ( " Teleop Comments " , " " ) ,
new sliderType ( " Overall Driving Performance " , 5 , 0 , 10 ) ,
new textType ( " Overall Driving Comments " , " " ) ,
new sliderType ( " Score area (AMP <-> Speaker) " , 5 , 0 , 10 ) ,
new dropdownType ( " End Condition " , new String [ ] { " Nothing " , " Attempted Climb " , " Successful Climbed " , " Climbed with multiple robots " , " Climbed with trap " } , 0 ) ,
new dropdownType ( " Robot Condition " , new String [ ] { " Everything was working " , " Something seemed to be broken " , " Something was broken " , " Missing robot (Joe Johnson) " } , 0 ) ,
new textType ( " Other Comments " , " " )
2024-07-30 17:41:28 -06:00
}
2024-06-27 22:12:36 -06:00
} ;
2024-06-26 17:24:00 -06:00
2024-07-03 10:20:40 -06:00
public static final inputType [ ] [ ] default_pit_fields = new inputType [ ] [ ] {
2024-06-28 15:44:38 -06:00
{
2024-07-03 10:20:40 -06:00
new sliderType ( " How good is robot " , 5 , 0 , 10 ) ,
2024-09-14 18:02:31 -06:00
new textType ( " notes " , " " ) ,
2024-06-28 15:44:38 -06:00
} , {
2024-07-03 10:20:40 -06:00
new sliderType ( " How good is robot " , 5 , 0 , 10 ) ,
new sliderType ( " Test " , 1 , 0 , 10 ) ,
2024-09-14 18:02:31 -06:00
new textType ( " notes " , " " ) ,
2024-06-28 15:44:38 -06:00
}
} ;
2024-07-03 10:20:40 -06:00
public static boolean save ( String filename , inputType [ ] [ ] 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 ] ) ) ;
}
2024-06-28 15:44:38 -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);
}
}
2024-07-03 10:20:40 -06:00
private static byte [ ] save_version ( inputType [ ] 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 ( ) ;
}
2024-07-03 10:20:40 -06:00
public static inputType [ ] [ ] load ( String filename ) {
2024-06-28 15:44:38 -06:00
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 ( ) ;
2024-07-03 10:20:40 -06:00
inputType [ ] [ ] values = new inputType [ 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
}
}
2024-07-03 10:20:40 -06:00
private static inputType [ ] 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 ( ) ;
2024-07-03 10:20:40 -06:00
inputType [ ] output = new inputType [ objects . size ( ) ] ;
2024-06-26 17:24:00 -06:00
for ( int i = 0 ; i < objects . size ( ) ; i + + ) {
BuiltByteParser . parsedObject obj = objects . get ( i ) ;
2024-07-03 10:20:40 -06:00
inputType t = null ;
2024-06-26 17:24:00 -06:00
switch ( obj . getType ( ) ) {
2024-07-03 10:20:40 -06:00
case inputType . slider_type_id :
t = new sliderType ( ) ;
2024-06-26 17:24:00 -06:00
break ;
2024-07-03 10:20:40 -06:00
case inputType . dropdownType :
t = new dropdownType ( ) ;
2024-06-26 17:24:00 -06:00
break ;
2024-07-03 10:20:40 -06:00
case inputType . notesType :
2024-07-23 12:27:45 -06:00
t = new textType ( ) ;
2024-06-26 17:24:00 -06:00
break ;
2024-07-29 22:29:59 -06:00
case inputType . tallyType :
t = new tallyType ( ) ;
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-28 15:44:38 -06:00
// public static void test(){
// ScoutingVersion.transferType[][] transferValues = sv.get_transfer_values(values);
//
// ScoutingVersion.ScoutingArray msa = sv.new ScoutingArray(0, new ScoutingVersion.dataType[]{
// sv.new stringType("name", "test-username"),
// sv.new intType("How good is robot", 12)
// }, values, transferValues);
//
// msa.update();
//
// for(ScoutingVersion.dataType dt : msa.array){
// if(dt == null) continue;
// switch (dt.getValueType()){
// case NUM:
// System.out.println(dt.name + " " + (int) dt.get());
// break;
// case STRING:
// System.out.println(dt.name + " " + (String) dt.get());
// break;
// }
//
// }
// }
2024-06-26 13:31:31 -06:00
}