mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Generate transfer_values based off of fields, save field versions to a file.
This commit is contained in:
@@ -8,16 +8,23 @@ import java.util.ArrayList;
|
|||||||
public class BuiltByteParser {
|
public class BuiltByteParser {
|
||||||
public static final Integer intType = 0;
|
public static final Integer intType = 0;
|
||||||
public static final Integer stringType = 1;
|
public static final Integer stringType = 1;
|
||||||
|
public static final Integer intArrayType = 2;
|
||||||
|
public static final Integer stringArrayType = 3;
|
||||||
|
|
||||||
public class byteParsingExeption extends Exception {
|
public class byteParsingExeption extends Exception {
|
||||||
public byteParsingExeption() {}
|
public byteParsingExeption() {}
|
||||||
public byteParsingExeption(String message) {
|
public byteParsingExeption(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract class parsedObject {
|
public abstract class parsedObject {
|
||||||
public abstract Integer getType();
|
public abstract Integer getType();
|
||||||
public abstract Object get();
|
public abstract Object get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class intObject extends parsedObject{
|
public class intObject extends parsedObject{
|
||||||
int num;
|
int num;
|
||||||
public Integer getType(){return intType;}
|
public Integer getType(){return intType;}
|
||||||
@@ -28,6 +35,20 @@ public class BuiltByteParser {
|
|||||||
public Integer getType(){return stringType;}
|
public Integer getType(){return stringType;}
|
||||||
public Object get(){return str;}
|
public Object get(){return str;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class intArrayObject extends parsedObject{
|
||||||
|
int[] arr;
|
||||||
|
public Integer getType(){return intArrayType;}
|
||||||
|
public Object get(){return arr;}
|
||||||
|
}
|
||||||
|
public class stringArrayObject extends parsedObject{
|
||||||
|
String[] arr;
|
||||||
|
public Integer getType(){return stringArrayType;}
|
||||||
|
public Object get(){return arr;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class rawObject extends parsedObject {
|
public class rawObject extends parsedObject {
|
||||||
private int type;
|
private int type;
|
||||||
public rawObject(int type){this.type = type;}
|
public rawObject(int type){this.type = type;}
|
||||||
@@ -73,6 +94,35 @@ public class BuiltByteParser {
|
|||||||
so.str = new String(block, StandardCharsets.UTF_8);
|
so.str = new String(block, StandardCharsets.UTF_8);
|
||||||
objects.add(so);
|
objects.add(so);
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
BuiltByteParser int_bbp = new BuiltByteParser(block);
|
||||||
|
ArrayList<parsedObject> intArrayObjects = int_bbp.parse();
|
||||||
|
|
||||||
|
int[] intArr = new int[intArrayObjects.size()];
|
||||||
|
|
||||||
|
for(int i = 0; i < intArrayObjects.size(); i ++){
|
||||||
|
intArr[i] = (int) intArrayObjects.get(i).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
intArrayObject ia = new intArrayObject();
|
||||||
|
ia.arr = intArr;
|
||||||
|
objects.add(ia);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
|
||||||
|
BuiltByteParser str_bbp = new BuiltByteParser(block);
|
||||||
|
ArrayList<parsedObject> strArrayObjects = str_bbp.parse();
|
||||||
|
|
||||||
|
String[] StringArr = new String[strArrayObjects.size()];
|
||||||
|
|
||||||
|
for(int i = 0; i < strArrayObjects.size(); i ++){
|
||||||
|
StringArr[i] = (String) strArrayObjects.get(i).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
stringArrayObject sa = new stringArrayObject();
|
||||||
|
sa.arr = StringArr;
|
||||||
|
objects.add(sa);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
rawObject ro = new rawObject(type);
|
rawObject ro = new rawObject(type);
|
||||||
ro.bytes = block;
|
ro.bytes = block;
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ByteBuilder {
|
public class ByteBuilder {
|
||||||
|
public static final int int_id = 0;
|
||||||
|
public static final int string_id = 1;
|
||||||
|
public static final int int_arr_id = 2;
|
||||||
|
public static final int string_arr_id = 3;
|
||||||
|
|
||||||
ArrayList<byteType> bytesToBuild = new ArrayList<>();
|
ArrayList<byteType> bytesToBuild = new ArrayList<>();
|
||||||
|
|
||||||
public class buildingException extends Exception {
|
public class buildingException extends Exception {
|
||||||
@@ -26,7 +31,7 @@ public class ByteBuilder {
|
|||||||
private class intType extends byteType {
|
private class intType extends byteType {
|
||||||
public int precision;
|
public int precision;
|
||||||
public int num;
|
public int num;
|
||||||
public byte getType(){return 0;}
|
public byte getType(){return int_id;}
|
||||||
public int length(){return precision;}
|
public int length(){return precision;}
|
||||||
public byte[] build(){
|
public byte[] build(){
|
||||||
return fileEditor.toBytes(num, precision);
|
return fileEditor.toBytes(num, precision);
|
||||||
@@ -60,7 +65,7 @@ public class ByteBuilder {
|
|||||||
|
|
||||||
private class stringType extends byteType {
|
private class stringType extends byteType {
|
||||||
public byte[] bytes;
|
public byte[] bytes;
|
||||||
public byte getType(){return 1;}
|
public byte getType(){return string_id;}
|
||||||
public int length(){return bytes.length;}
|
public int length(){return bytes.length;}
|
||||||
public byte[] build(){
|
public byte[] build(){
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -78,6 +83,54 @@ public class ByteBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class intArrayType extends byteType {
|
||||||
|
public byte[] bytes;
|
||||||
|
public byte getType(){return int_arr_id;}
|
||||||
|
public int length(){return bytes.length;}
|
||||||
|
public byte[] build(){
|
||||||
|
return bytes;
|
||||||
|
// return str.getBytes(charset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ByteBuilder addIntArray(int[] arr) throws buildingException {
|
||||||
|
intArrayType intArrayType = new intArrayType();
|
||||||
|
|
||||||
|
ByteBuilder bb = new ByteBuilder();
|
||||||
|
|
||||||
|
for(int i = 0; i < arr.length; i++){
|
||||||
|
bb.addInt(arr[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
intArrayType.bytes = bb.build();
|
||||||
|
|
||||||
|
bytesToBuild.add(intArrayType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class stringArrayType extends byteType {
|
||||||
|
public byte[] bytes;
|
||||||
|
public byte getType(){return string_arr_id;}
|
||||||
|
public int length(){return bytes.length;}
|
||||||
|
public byte[] build(){
|
||||||
|
return bytes;
|
||||||
|
// return str.getBytes(charset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ByteBuilder addStringArray(String[] arr) throws buildingException {
|
||||||
|
stringArrayType stringArrayType = new stringArrayType();
|
||||||
|
|
||||||
|
ByteBuilder bb = new ByteBuilder();
|
||||||
|
|
||||||
|
for(int i = 0; i < arr.length; i++){
|
||||||
|
bb.addString(arr[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringArrayType.bytes = bb.build();
|
||||||
|
|
||||||
|
bytesToBuild.add(stringArrayType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private class rawType extends byteType {
|
private class rawType extends byteType {
|
||||||
public int type;
|
public int type;
|
||||||
public byte[] bytes;
|
public byte[] bytes;
|
||||||
|
|||||||
-126
@@ -1,126 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+194
-51
@@ -1,8 +1,17 @@
|
|||||||
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
|
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
|
||||||
|
|
||||||
|
import com.astatin3.scoutingapp2025.BuiltByteParser;
|
||||||
|
import com.astatin3.scoutingapp2025.ByteBuilder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ScoutingVersion {
|
public class ScoutingVersion {
|
||||||
|
public static final int slider_type_id = 255;
|
||||||
|
public static final int dropdownType = 254;
|
||||||
|
public static final int notesType = 253;
|
||||||
|
|
||||||
public enum inputTypes {
|
public enum inputTypes {
|
||||||
USERNAME,
|
// USERNAME,
|
||||||
SLIDER,
|
SLIDER,
|
||||||
DROPDOWN,
|
DROPDOWN,
|
||||||
NOTES_INPUT
|
NOTES_INPUT
|
||||||
@@ -18,59 +27,113 @@ public class ScoutingVersion {
|
|||||||
public Object default_value;
|
public Object default_value;
|
||||||
public abstract inputTypes getInputType();
|
public abstract inputTypes getInputType();
|
||||||
public abstract valueTypes getValueType();
|
public abstract valueTypes getValueType();
|
||||||
|
public abstract int get_byte_id();
|
||||||
|
public inputType(){}
|
||||||
public inputType(String name){
|
public inputType(String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
public abstract byte[] encode() throws ByteBuilder.buildingException;
|
||||||
|
public abstract void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class usernameType extends inputType {
|
// public class usernameType extends inputType {
|
||||||
public String defaultValue;
|
// public String defaultValue;
|
||||||
public inputTypes getInputType(){return inputTypes.USERNAME;}
|
// public inputTypes getInputType(){return inputTypes.USERNAME;}
|
||||||
public valueTypes getValueType(){return valueTypes.STRING;}
|
// public valueTypes getValueType(){return valueTypes.STRING;}
|
||||||
public usernameType(String name, String defaultValue){
|
// public usernameType(String name, String defaultValue){
|
||||||
super(name);
|
// super(name);
|
||||||
this.defaultValue = defaultValue;
|
// this.defaultValue = defaultValue;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public class sliderType extends inputType {
|
public class sliderType extends inputType {
|
||||||
// public int defaultValue;
|
// public int defaultValue;
|
||||||
public int min;
|
public int min;
|
||||||
public int max;
|
public int max;
|
||||||
|
public int get_byte_id() {return slider_type_id;}
|
||||||
public inputTypes getInputType(){return inputTypes.SLIDER;}
|
public inputTypes getInputType(){return inputTypes.SLIDER;}
|
||||||
public valueTypes getValueType(){return valueTypes.NUM;}
|
public valueTypes getValueType(){return valueTypes.NUM;}
|
||||||
|
public sliderType(){};
|
||||||
public sliderType(String name, int defaultValue, int min, int max){
|
public sliderType(String name, int defaultValue, int min, int max){
|
||||||
super(name);
|
super(name);
|
||||||
this.default_value = defaultValue;
|
this.default_value = defaultValue;
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
public byte[] encode() throws ByteBuilder.buildingException {
|
||||||
|
ByteBuilder bb = new ByteBuilder();
|
||||||
|
bb.addString(name);
|
||||||
|
bb.addInt((int)default_value);
|
||||||
|
bb.addInt(min);
|
||||||
|
bb.addInt(max);
|
||||||
|
return bb.build();
|
||||||
|
}
|
||||||
|
public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption {
|
||||||
|
BuiltByteParser bbp = new BuiltByteParser(bytes);
|
||||||
|
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
|
||||||
|
|
||||||
|
name = (String) objects.get(0).get();
|
||||||
|
default_value = objects.get(1).get();
|
||||||
|
min = (int) objects.get(2).get();
|
||||||
|
max = (int) objects.get(3).get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class dropdownType extends inputType {
|
public class dropdownType extends inputType {
|
||||||
public String[] text_options;
|
public String[] text_options;
|
||||||
// public int defaultSelIndex;
|
public int get_byte_id() {return dropdownType;}
|
||||||
public inputTypes getInputType(){return inputTypes.DROPDOWN;}
|
public inputTypes getInputType(){return inputTypes.DROPDOWN;}
|
||||||
public valueTypes getValueType(){return valueTypes.NUM;}
|
public valueTypes getValueType(){return valueTypes.NUM;}
|
||||||
|
public dropdownType(){};
|
||||||
public dropdownType(String name, String[] text_options, int defaultSelIndex){
|
public dropdownType(String name, String[] text_options, int defaultSelIndex){
|
||||||
super(name);
|
super(name);
|
||||||
this.text_options = text_options;
|
this.text_options = text_options;
|
||||||
this.default_value = defaultSelIndex;
|
this.default_value = defaultSelIndex;
|
||||||
}
|
}
|
||||||
|
public byte[] encode() throws ByteBuilder.buildingException {
|
||||||
|
ByteBuilder bb = new ByteBuilder();
|
||||||
|
bb.addString(name);
|
||||||
|
bb.addInt((int)default_value);
|
||||||
|
bb.addStringArray(text_options);
|
||||||
|
return bb.build();
|
||||||
|
}
|
||||||
|
public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption {
|
||||||
|
BuiltByteParser bbp = new BuiltByteParser(bytes);
|
||||||
|
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
|
||||||
|
|
||||||
|
name = (String) objects.get(0).get();
|
||||||
|
default_value = objects.get(1).get();
|
||||||
|
text_options = (String[]) objects.get(2).get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class notesType extends inputType {
|
public class notesType extends inputType {
|
||||||
// public String default_text;
|
public int get_byte_id() {return notesType;}
|
||||||
public inputTypes getInputType(){return inputTypes.NOTES_INPUT;}
|
public inputTypes getInputType(){return inputTypes.NOTES_INPUT;}
|
||||||
public valueTypes getValueType(){return valueTypes.STRING;}
|
public valueTypes getValueType(){return valueTypes.STRING;}
|
||||||
|
public notesType(){};
|
||||||
public notesType(String name, String default_text){
|
public notesType(String name, String default_text){
|
||||||
super(name);
|
super(name);
|
||||||
this.default_value = default_text;
|
this.default_value = default_text;
|
||||||
}
|
}
|
||||||
|
public byte[] encode() throws ByteBuilder.buildingException {
|
||||||
|
ByteBuilder bb = new ByteBuilder();
|
||||||
|
bb.addString(name);
|
||||||
|
bb.addString((String) default_value);
|
||||||
|
return bb.build();
|
||||||
|
}
|
||||||
|
public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption {
|
||||||
|
BuiltByteParser bbp = new BuiltByteParser(bytes);
|
||||||
|
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
|
||||||
|
|
||||||
|
name = (String) objects.get(0).get();
|
||||||
|
default_value = objects.get(1).get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class dataType {
|
public abstract class dataType {
|
||||||
public String name;
|
public String name;
|
||||||
public Object value;
|
public Object value;
|
||||||
@@ -106,7 +169,7 @@ public class ScoutingVersion {
|
|||||||
|
|
||||||
public enum transferValue {
|
public enum transferValue {
|
||||||
DIRECT,
|
DIRECT,
|
||||||
RENAME,
|
// RENAME,
|
||||||
CREATE
|
CREATE
|
||||||
// DELETE
|
// DELETE
|
||||||
// UP_TO_DATE
|
// UP_TO_DATE
|
||||||
@@ -127,14 +190,14 @@ public class ScoutingVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class renameTransferType extends transferType {
|
// public class renameTransferType extends transferType {
|
||||||
public String new_name;
|
// public String new_name;
|
||||||
public transferValue getType() {return transferValue.RENAME;}
|
// public transferValue getType() {return transferValue.RENAME;}
|
||||||
public renameTransferType(String name, String new_name){
|
// public renameTransferType(String name, String new_name){
|
||||||
super(name);
|
// super(name);
|
||||||
this.new_name = new_name;
|
// this.new_name = new_name;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public class createTransferType extends transferType {
|
public class createTransferType extends transferType {
|
||||||
@@ -161,35 +224,115 @@ public class ScoutingVersion {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public boolean save(String filename){
|
public class ScoutingArray {
|
||||||
// ByteBuilder bb = new ByteBuilder();
|
public int version;
|
||||||
// try {
|
public dataType[] array;
|
||||||
// bb.addInt(getVersion());
|
public ScoutingVersion.inputType[][] values;
|
||||||
// for(dataType data : getTypes()){
|
public int latest_version_num;
|
||||||
// if(data.getType() == intType){
|
public transferType[][] transfer_values;
|
||||||
// bb.addInt((int)data.get());
|
|
||||||
// } else if (data.getType() == stringType) {
|
public ScoutingArray(int version, dataType[] array, ScoutingVersion.inputType[][] values, transferType[][] transfer_values){
|
||||||
// bb.addString((String)data.get());
|
this.version = version;
|
||||||
// }else{
|
this.array = array;
|
||||||
// bb.addRaw(data.getType(), (byte[])data.get());
|
this.values = values;
|
||||||
// }
|
this.latest_version_num = values.length-1;
|
||||||
// }
|
this.transfer_values = transfer_values;
|
||||||
// return fileEditor.writeFile(filename, bb.build());
|
}
|
||||||
// } catch (ByteBuilder.buildingException e) {
|
|
||||||
// e.printStackTrace();
|
public ScoutingArray(int version, dataType[] array, ScoutingVersion.inputType[][] values){
|
||||||
// return false;
|
this(version, array, values, get_transfer_values(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private dataType get_data_type_by_name(String name){
|
||||||
|
for(dataType dt : array){
|
||||||
|
if(dt.name.equals(name)){
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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){
|
||||||
// public void load(String filename){
|
inputType it = get_input_type_by_name(version+1, tv.name);
|
||||||
// byte[] bytes = fileEditor.readFile(filename);
|
// System.out.println(tv.name);
|
||||||
// BuiltByteParser bbp = new BuiltByteParser(bytes);
|
switch (it.getValueType()){
|
||||||
// try {
|
case NUM:
|
||||||
// ArrayList<BuiltByteParser.parsedObject> parsedObjects = bbp.parse();
|
return new intType(it.name, (int) it.default_value);
|
||||||
// parse((int)parsedObjects.get(0).get(), parsedObjects);
|
case STRING:
|
||||||
// } catch (BuiltByteParser.byteParsingExeption e) {
|
return new stringType(it.name, (String) it.default_value);
|
||||||
// e.printStackTrace();
|
}
|
||||||
//// throw new RuntimeException(e);
|
System.out.println(2);
|
||||||
// }
|
return null;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private inputType get_input_type_by_name(inputType[] values, String name){
|
||||||
|
for(inputType it : values){
|
||||||
|
if(it.name.equals(name)){
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public transferType[][] get_transfer_values(inputType[][] values) {
|
||||||
|
transferType[][] output = new transferType[values.length][];
|
||||||
|
for(int a = 1; a < values.length; a++){
|
||||||
|
transferType[] v = new transferType[values[a].length];
|
||||||
|
for(int b = 0; b < values[a].length; b++){
|
||||||
|
String name = values[a][b].name;
|
||||||
|
if(get_input_type_by_name(values[a-1], name) != null){
|
||||||
|
v[b] = new directTransferType(name);
|
||||||
|
}else{
|
||||||
|
v[b] = new createTransferType(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output[a-1] = v;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,127 @@
|
|||||||
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
|
package com.astatin3.scoutingapp2025.ScoutingDataVersion;
|
||||||
|
|
||||||
|
import com.astatin3.scoutingapp2025.BuiltByteParser;
|
||||||
|
import com.astatin3.scoutingapp2025.ByteBuilder;
|
||||||
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class fields {
|
public class fields {
|
||||||
|
private static ScoutingVersion sv = new ScoutingVersion();
|
||||||
|
public static final String fieldsFilename = "data.fields";
|
||||||
|
|
||||||
|
public static ScoutingVersion.inputType[][] values = new ScoutingVersion.inputType[][]{};
|
||||||
|
|
||||||
|
// public static ScoutingVersion.inputType[][] values = new ScoutingVersion.inputType[][] {
|
||||||
|
// {
|
||||||
|
// sv.new notesType("name", "Unset-Username"),
|
||||||
|
// sv.new sliderType("How good is robot", 5, 0, 10)
|
||||||
|
// }, {
|
||||||
|
// sv.new notesType("name", "Unset-Username"),
|
||||||
|
// sv.new sliderType("How good is robot", 5, 0, 10),
|
||||||
|
// sv.new notesType("notes", "No-Notes")
|
||||||
|
// }, {
|
||||||
|
// sv.new notesType("name", "Unset-Username"),
|
||||||
|
// sv.new notesType("notes", "No-Notes")
|
||||||
|
// }, {
|
||||||
|
// sv.new notesType("name", "Unset-Username")
|
||||||
|
// }, {
|
||||||
|
// sv.new notesType("name", "Unset-Username"),
|
||||||
|
// sv.new sliderType("How good is robot", 5, 0, 10)
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
public static boolean save(){
|
||||||
|
try {
|
||||||
|
ByteBuilder bb = new ByteBuilder();
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
bb.addRaw(127, save_version(values[i]));
|
||||||
|
}
|
||||||
|
fileEditor.writeFile(fieldsFilename, bb.build());
|
||||||
|
return true;
|
||||||
|
}catch (ByteBuilder.buildingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] save_version(ScoutingVersion.inputType[] 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 boolean load(){
|
||||||
|
byte[] bytes = fileEditor.readFile(fieldsFilename);
|
||||||
|
|
||||||
|
try {
|
||||||
|
BuiltByteParser bbp = new BuiltByteParser(bytes);
|
||||||
|
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
|
||||||
|
values = new ScoutingVersion.inputType[objects.size()][];
|
||||||
|
|
||||||
|
for(int i = 0 ; i < objects.size(); i++){
|
||||||
|
values[i] = load_version((byte[]) objects.get(i).get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (BuiltByteParser.byteParsingExeption e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ScoutingVersion.inputType[] load_version(byte[] bytes) throws BuiltByteParser.byteParsingExeption{
|
||||||
|
BuiltByteParser bbp = new BuiltByteParser(bytes);
|
||||||
|
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
|
||||||
|
ScoutingVersion.inputType[] output = new ScoutingVersion.inputType[objects.size()];
|
||||||
|
|
||||||
|
for(int i = 0 ; i < objects.size(); i++){
|
||||||
|
BuiltByteParser.parsedObject obj = objects.get(i);
|
||||||
|
ScoutingVersion.inputType t = null;
|
||||||
|
switch (obj.getType()){
|
||||||
|
case ScoutingVersion.slider_type_id:
|
||||||
|
t = sv.new sliderType();
|
||||||
|
break;
|
||||||
|
case ScoutingVersion.dropdownType:
|
||||||
|
t = sv.new dropdownType();
|
||||||
|
break;
|
||||||
|
case ScoutingVersion.notesType:
|
||||||
|
t = sv.new notesType();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
t.decode((byte[]) obj.get());
|
||||||
|
output[i] = t
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.astatin3.scoutingapp2025.ui.scouting;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
|
|
||||||
|
public class matchScoutingView extends ConstraintLayout {
|
||||||
|
public matchScoutingView(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,8 +10,9 @@ 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.ScoutingDataVersion.MatchScouting;
|
import com.astatin3.scoutingapp2025.BuiltByteParser;
|
||||||
import com.astatin3.scoutingapp2025.ScoutingDataVersion.ScoutingVersion;
|
import com.astatin3.scoutingapp2025.ByteBuilder;
|
||||||
|
import com.astatin3.scoutingapp2025.ScoutingDataVersion.fields;
|
||||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding;
|
import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding;
|
||||||
|
|
||||||
@@ -33,27 +34,50 @@ public class scoutingFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.matchScoutingButton.setOnClickListener(v -> {
|
binding.matchScoutingButton.setOnClickListener(v -> {
|
||||||
MatchScouting.MatchScoutingArray msa = MatchScouting.ms.new MatchScoutingArray(0, new ScoutingVersion.dataType[]{
|
// byte[] bytes = fields.save();
|
||||||
MatchScouting.msv.new stringType("name", "test-username"),
|
// System.out.println(bytes.length);
|
||||||
MatchScouting.msv.new intType("How good is robot", 12)
|
// System.out.println(fields.load(bytes)[0].length);
|
||||||
});
|
|
||||||
// System.out.println(Arrays.toString(msa.array));
|
|
||||||
|
|
||||||
msa.update();
|
System.out.println(fields.load());
|
||||||
|
|
||||||
for(ScoutingVersion.dataType dt : msa.array){
|
fields.test();
|
||||||
if(dt == null) continue;
|
|
||||||
switch (dt.getValueType()){
|
// fields.test();
|
||||||
case NUM:
|
|
||||||
System.out.println(dt.name + " " + (int) dt.get());
|
// ByteBuilder bb = new ByteBuilder();
|
||||||
break;
|
// try {
|
||||||
case STRING:
|
// bb.addInt(1243);
|
||||||
System.out.println(dt.name + " " + (String) dt.get());
|
// bb.addStringArray(new String[]{"Test", "Test2", "Tljewhgr"});
|
||||||
break;
|
// bb.addIntArray(new int[]{4, 3, 8, 8});
|
||||||
}
|
// byte[] bytes = bb.build();
|
||||||
// case ScoutingVersion.valueTypes.NUM:
|
//
|
||||||
|
// BuiltByteParser bbp = new BuiltByteParser(bytes);
|
||||||
|
// BuiltByteParser.parsedObject[] objects = bbp.parse().toArray(new BuiltByteParser.parsedObject[0]);
|
||||||
|
//
|
||||||
|
// for(BuiltByteParser.parsedObject object : objects){
|
||||||
|
// switch (object.getType()){
|
||||||
|
// case 0:
|
||||||
|
// System.out.println((int) object.get());
|
||||||
|
// break;
|
||||||
|
// case 1:
|
||||||
|
// System.out.println((String) object.get());
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// System.out.println(Arrays.toString((int[]) object.get()));
|
||||||
|
// break;
|
||||||
|
// case 3:
|
||||||
|
// System.out.println(Arrays.toString((String[]) object.get()));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// } catch (ByteBuilder.buildingException e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// } catch (BuiltByteParser.byteParsingExeption e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
//
|
//
|
||||||
// binding.pitScoutingButton.setOnClickListener(v -> {
|
// binding.pitScoutingButton.setOnClickListener(v -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user