Completely rewrite scouting version stuff

This commit is contained in:
astatin3
2024-06-26 13:31:31 -06:00
parent 799ec190b7
commit 2c4eac9bbc
8 changed files with 363 additions and 240 deletions
@@ -1,137 +0,0 @@
package com.astatin3.scoutingapp2025.MatchScoutingVersionStack;
import com.astatin3.scoutingapp2025.BuiltByteParser;
import com.astatin3.scoutingapp2025.ByteBuilder;
import com.astatin3.scoutingapp2025.fileEditor;
import java.util.ArrayList;
public abstract class MatchScoutingVersion {
public abstract int getVersion();
public abstract dataType[] getTypes();
// public abstract void ();
// public abstract MatchScoutingVersion update(MatchScoutingVersion prev);
public dataType[] test(){return getTypes();}
public static final Integer intType = 0;
public static final Integer stringType = 1;
// public static final Integer update_direct_transfer = 0;
// public static final Integer update_reset_value = 1;
// public static final Integer update_delete_value = 2;
public abstract class dataType {
public String name;
public dataType(String name){
this.name = name;
}
public abstract Integer getType();
public abstract Object get();
public abstract void set(Object obj);
}
public class intData extends MatchScoutingVersion.dataType {
int num;
public intData(String name, int defaultValue){
super(name);
this.num = defaultValue;
}
public Integer getType(){return intType;}
public Object get(){return num;}
public void set(Object obj){
this.num = (int) obj;
};
}
public class stringData extends MatchScoutingVersion.dataType {
public String str;
public stringData(String name, String defaultValue){
super(name);
this.str = defaultValue;
}
public Integer getType(){return stringType;}
public Object get(){return str;}
public void set(Object obj){
this.str = (String) obj;
};
}
public class rawData extends MatchScoutingVersion.dataType {
private int type;
public byte[] bytes;
public rawData(String name, int type, byte[] defaultValue){
super(name);
this.type = type;
this.bytes = defaultValue;
}
public Integer getType(){return type;}
public Object get(){return bytes;}
public void set(Object obj){
this.bytes = (byte[]) obj;
};
}
public dataType get_value(String name){
for(dataType data : getTypes()){
if(data.name.equals(name))
return data;
}
return null;
}
public intData get_int_value(String name){
dataType data = get_value(name);
if(data.getType() != intType)
return null;
return (intData) data;
}
public stringData get_string_value(String name){
dataType data = get_value(name);
if(data.getType() != stringType)
return null;
return (stringData) data;
}
public rawData get_raw_value(String name, int rawType){
dataType data = get_value(name);
if(!data.getType().equals(rawType))
return null;
return (rawData) data;
}
public boolean save(String filename){
ByteBuilder bb = new ByteBuilder();
try {
bb.addInt(getVersion());
for(dataType data : getTypes()){
if(data.getType() == intType){
bb.addInt((int)data.get());
} else if (data.getType() == stringType) {
bb.addString((String)data.get());
}else{
bb.addRaw(data.getType(), (byte[])data.get());
}
}
return fileEditor.writeFile(filename, bb.build());
} catch (ByteBuilder.buildingException e) {
e.printStackTrace();
return false;
}
}
public boolean load(String filename){
byte[] bytes = fileEditor.readFile(filename);
BuiltByteParser bbp = new BuiltByteParser(bytes);
try {
ArrayList<BuiltByteParser.parsedObject> parsedObjects = bbp.parse();
return true;
} catch (BuiltByteParser.byteParsingExeption e) {
e.printStackTrace();
return false;
// throw new RuntimeException(e);
}
}
}
@@ -1,32 +0,0 @@
package com.astatin3.scoutingapp2025.MatchScoutingVersionStack;
import com.astatin3.scoutingapp2025.BuiltByteParser;
import java.util.ArrayList;
public class msv0 extends MatchScoutingVersion{
public static int version_num = 0;
@Override
public int getVersion(){return version_num;}
public dataType[] types = {
new stringData("name", "Unset-Username"),
new intData("team", 0)
};
@Override
public dataType[] getTypes(){
return types;
}
// public MatchScoutingVersion update(MatchScoutingVersion prev) {
// return prev;
// }
public static msv0 parse(int version, ArrayList<BuiltByteParser.parsedObject> parsedObjects) {
msv0 msdata = new msv0();
dataType[] types = msdata.getTypes();
((stringData)types[0]).str = (String)(parsedObjects.get(0)).get();
((intData)types[1]).num = (int)(parsedObjects.get(0)).get();
return msdata;
}
}
@@ -1,51 +0,0 @@
package com.astatin3.scoutingapp2025.MatchScoutingVersionStack;
import com.astatin3.scoutingapp2025.BuiltByteParser;
import java.util.ArrayList;
public class msv1 extends msv0 {
public static int version_num = 1;
@Override
public int getVersion(){return version_num;}
public dataType[] types = {
new stringData("name", "Unset-Username"),
new intData("team", 0),
new intData("scoreArea", -1),
new intData("robotCondition", -1),
new intData("autoPerformance", -1),
new intData("teleopPerformance", -1),
new intData("overallPerformance", -1),
new intData("endState", -1),
new intData("autoNotes", -1),
new intData("teleopNotes", -1),
new stringData("notes", "<No notes>")
};
@Override
public dataType[] getTypes(){
return types;
}
public static msv1 update(msv0 prev) {
msv1 post = new msv1();
post.types = prev.types;
return post;
}
public static msv1 parse(int version, ArrayList<BuiltByteParser.parsedObject> parsedObjects) {
if(version < version_num){
msv0 msdata = msv0.parse(version, parsedObjects);
return update(msdata);
}
msv1 msdata = new msv1();
dataType[] types = msdata.getTypes();
for(int i = 1; i < types.length; i++){
types[i].set(parsedObjects.get(i));
}
return msdata;
}
}
@@ -0,0 +1,126 @@
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
import android.renderscript.Element;
import com.astatin3.scoutingapp2025.ScoutingDataVersion.ScoutingVersion.*;
public class MatchScouting {
public static int latest_version_num = 4;
public static ScoutingVersion msv = new ScoutingVersion();
public static MatchScouting ms = new MatchScouting();
public static inputType[][] values = new inputType[][] {
{
msv.new usernameType("name", "Unset-Username"),
msv.new sliderType("How good is robot", 5, 0, 10)
}, {
msv.new usernameType("name", "Unset-Username"),
msv.new sliderType("How good is robot", 5, 0, 10),
msv.new notesType("notes", "No-Notes")
},{
msv.new usernameType("name", "Unset-Username"),
// msv.new sliderType("How good is robot", 5, 0, 10),
msv.new notesType("notes", "No-Notes")
},{
msv.new usernameType("name", "Unset-Username"),
msv.new sliderType("team_number", 4388, 0, 9999),
msv.new notesType("notes", "No-Notes")
}
};
public static transferType[][] transfer_values = new transferType[][] {
{
msv.new directTransferType("name"),
msv.new directTransferType("How good is robot"),
msv.new createTransferType("notes")
},{
msv.new directTransferType("name"),
msv.new renameTransferType("How good is robot", "robot_preformance"),
msv.new directTransferType("notes")
},{
msv.new directTransferType("name"),
msv.new directTransferType("notes")
},{
msv.new directTransferType("name"),
msv.new createTransferType("team_number"),
msv.new directTransferType("notes")
}
};
public class MatchScoutingArray {
public int version;
public dataType[] array;
public MatchScoutingArray(int version, dataType[] array){
this.version = version;
this.array = array;
}
public void update(){
while(version<latest_version_num){
dataType[] new_values = new dataType[transfer_values[version].length];
for(int i = 0; i < transfer_values[version].length; i++){
transferType tv = transfer_values[version][i];
switch (tv.getType()){
case DIRECT:
new_values[i] = direct_transfer((directTransferType) tv);
continue;
case RENAME:
new_values[i] = rename_transfer((renameTransferType) tv);
continue;
case CREATE:
new_values[i] = create_transfer((createTransferType) tv, i);
continue;
}
System.out.println(new_values[i]);
}
this.array = new_values;
version++;
System.out.println("Updated to " + version);
}
}
private inputType get_input_type_by_name(int version, String name){
for(inputType it : values[version]){
if(it.name.equals(name)){
return it;
}
}
System.out.println(0);
return null;
}
private dataType get_data_type_by_name(String name){
for(dataType dt : array){
if(dt.name.equals(name)){
return dt;
}
}
System.out.println(1);
return null;
}
private dataType direct_transfer(directTransferType tv){
return get_data_type_by_name(tv.name);
}
private dataType rename_transfer(renameTransferType tv){
dataType dt = get_data_type_by_name(tv.name);
dt.name = tv.new_name;
return dt;
}
private dataType create_transfer(createTransferType tv, int index){
inputType it = get_input_type_by_name(version+1, tv.name);
System.out.println(tv.name);
switch (it.getValueType()){
case NUM:
return msv.new intType(it.name, (int) it.default_value);
case STRING:
return msv.new stringType(it.name, (String) it.default_value);
}
System.out.println(2);
return null;
}
}
}
@@ -0,0 +1,195 @@
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
public class ScoutingVersion {
public enum inputTypes {
USERNAME,
SLIDER,
DROPDOWN,
NOTES_INPUT
}
public enum valueTypes {
NUM,
STRING
}
public abstract class inputType {
public String name;
public Object default_value;
public abstract inputTypes getInputType();
public abstract valueTypes getValueType();
public inputType(String name){
this.name = name;
}
}
public class usernameType extends inputType {
public String defaultValue;
public inputTypes getInputType(){return inputTypes.USERNAME;}
public valueTypes getValueType(){return valueTypes.STRING;}
public usernameType(String name, String defaultValue){
super(name);
this.defaultValue = defaultValue;
}
}
public class sliderType extends inputType {
// public int defaultValue;
public int min;
public int max;
public inputTypes getInputType(){return inputTypes.SLIDER;}
public valueTypes getValueType(){return valueTypes.NUM;}
public sliderType(String name, int defaultValue, int min, int max){
super(name);
this.default_value = defaultValue;
this.min = min;
this.max = max;
}
}
public class dropdownType extends inputType {
public String[] text_options;
// public int defaultSelIndex;
public inputTypes getInputType(){return inputTypes.DROPDOWN;}
public valueTypes getValueType(){return valueTypes.NUM;}
public dropdownType(String name, String[] text_options, int defaultSelIndex){
super(name);
this.text_options = text_options;
this.default_value = defaultSelIndex;
}
}
public class notesType extends inputType {
// public String default_text;
public inputTypes getInputType(){return inputTypes.NOTES_INPUT;}
public valueTypes getValueType(){return valueTypes.STRING;}
public notesType(String name, String default_text){
super(name);
this.default_value = default_text;
}
}
public abstract class dataType {
public String name;
public Object value;
public abstract valueTypes getValueType();
public Object get(){
return value;
}
public void set(Object value){
this.value = value;
}
public dataType(String name){
this.name = name;
}
}
public class intType extends dataType{
public valueTypes getValueType() {return valueTypes.NUM;}
public intType(String name, int value){
super(name);
this.value = value;
}
}
public class stringType extends dataType{
public valueTypes getValueType() {return valueTypes.STRING;}
public stringType(String name, String value){
super(name);
this.value = value;
}
}
public enum transferValue {
DIRECT,
RENAME,
CREATE
// DELETE
// UP_TO_DATE
}
public abstract class transferType {
public String name;
public abstract transferValue getType();
public transferType(String name){
this.name = name;
}
}
public class directTransferType extends transferType {
public transferValue getType() {return transferValue.DIRECT;}
public directTransferType(String name){
super(name);
}
}
public class renameTransferType extends transferType {
public String new_name;
public transferValue getType() {return transferValue.RENAME;}
public renameTransferType(String name, String new_name){
super(name);
this.new_name = new_name;
}
}
public class createTransferType extends transferType {
public transferValue getType() {return transferValue.CREATE;}
public createTransferType(String name){
super(name);
}
}
// public class deleteTransferType extends transferType {
// public transferValue getType() {return transferValue.DELETE;}
// public deleteTransferType(String name){
// super(name);
// }
// }
// public class uptodateTransferType extends transferType {
// public String name;
// public transferValue getType() {return transferValue.UP_TO_DATE;}
// public uptodateTransferType(String name){
// super(name);
// }
// }
// public boolean save(String filename){
// ByteBuilder bb = new ByteBuilder();
// try {
// bb.addInt(getVersion());
// for(dataType data : getTypes()){
// if(data.getType() == intType){
// bb.addInt((int)data.get());
// } else if (data.getType() == stringType) {
// bb.addString((String)data.get());
// }else{
// bb.addRaw(data.getType(), (byte[])data.get());
// }
// }
// return fileEditor.writeFile(filename, bb.build());
// } catch (ByteBuilder.buildingException e) {
// e.printStackTrace();
// return false;
// }
// }
//
// public void load(String filename){
// byte[] bytes = fileEditor.readFile(filename);
// BuiltByteParser bbp = new BuiltByteParser(bytes);
// try {
// ArrayList<BuiltByteParser.parsedObject> parsedObjects = bbp.parse();
// parse((int)parsedObjects.get(0).get(), parsedObjects);
// } catch (BuiltByteParser.byteParsingExeption e) {
// e.printStackTrace();
//// throw new RuntimeException(e);
// }
// }
}
@@ -0,0 +1,4 @@
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
public class fields {
}
@@ -24,7 +24,7 @@ import java.util.zip.Deflater;
import java.util.zip.Inflater; import java.util.zip.Inflater;
public final class fileEditor { public final class fileEditor {
private final static String baseDir = "/data/data/com.astatin3.scoutingapp2025/files/"; private final static String baseDir = "/data/data/com.astatin3.scoutingapp2025/";
public static final byte internalDataVersion = 0x01; public static final byte internalDataVersion = 0x01;
public static final int maxCompressedBlockSize = 4096; public static final int maxCompressedBlockSize = 4096;
@@ -5,18 +5,17 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.astatin3.scoutingapp2025.MatchScoutingVersionStack.MatchScoutingVersion; import com.astatin3.scoutingapp2025.ScoutingDataVersion.MatchScouting;
import com.astatin3.scoutingapp2025.MatchScoutingVersionStack.msv1; import com.astatin3.scoutingapp2025.ScoutingDataVersion.ScoutingVersion;
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings; import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding; import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding;
import com.astatin3.scoutingapp2025.fileEditor;
import java.util.Arrays;
public class scoutingFragment extends Fragment { public class scoutingFragment extends Fragment {
@@ -34,26 +33,45 @@ public class scoutingFragment extends Fragment {
} }
binding.matchScoutingButton.setOnClickListener(v -> { binding.matchScoutingButton.setOnClickListener(v -> {
msv1 msdata = new msv1(); MatchScouting.MatchScoutingArray msa = MatchScouting.ms.new MatchScoutingArray(0, new ScoutingVersion.dataType[]{
System.out.println(msdata.save("test.matchscoutdata")); MatchScouting.msv.new stringType("name", "test-username"),
// System.out.println(msdata.test().length); MatchScouting.msv.new intType("How good is robot", 12)
}); });
// System.out.println(Arrays.toString(msa.array));
binding.pitScoutingButton.setOnClickListener(v -> { msa.update();
msv1 msdata = new msv1();
System.out.println(msdata.load("test.matchscoutdata")); for(ScoutingVersion.dataType dt : msa.array){
for(MatchScoutingVersion.dataType data : msdata.getTypes()){ if(dt == null) continue;
// System.out.println(data.getType()); switch (dt.getValueType()){
switch ((int)data.getType()){ case NUM:
case 0: System.out.println(dt.name + " " + (int) dt.get());
System.out.println((int)data.get());
break; break;
case 1: case STRING:
System.out.println((String) data.get()); System.out.println(dt.name + " " + (String) dt.get());
break; break;
} }
// case ScoutingVersion.valueTypes.NUM:
} }
}); });
//
// binding.pitScoutingButton.setOnClickListener(v -> {
// msv1 msdata = new msv1();
//// msdata.types = MatchScoutingVersion.dataType[]5{};
// System.out.println(msdata.load("test.matchscoutdata"));
// for(MatchScoutingVersion.dataType data : msdata.getTypes().fields){
//// System.out.println(data.getType());
// switch (data.getType()){
// case 0:
// System.out.println((int)data.get());
// break;
// case 1:
// System.out.println((String) data.get());
// break;
// }
// }
// });
// msdata.set // msdata.set