mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-08 16:28:00 -06:00
Match Scouting data version stack
This commit is contained in:
+137
@@ -0,0 +1,137 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||
|
||||
public class latestSettings {
|
||||
public static v0 settings = new v0();
|
||||
public static sv0 settings = new sv0();
|
||||
public static void update(){
|
||||
settings.init_settings();
|
||||
settings.update();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||
|
||||
public class v0 extends settingsVersion {
|
||||
public class sv0 extends settingsVersion {
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 0;
|
||||
@@ -12,6 +12,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.astatin3.scoutingapp2025.MatchScoutingVersionStack.MatchScoutingVersion;
|
||||
import com.astatin3.scoutingapp2025.MatchScoutingVersionStack.msv1;
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding;
|
||||
import com.astatin3.scoutingapp2025.fileEditor;
|
||||
@@ -28,8 +30,33 @@ public class scoutingFragment extends Fragment {
|
||||
|
||||
if(latestSettings.settings.get_evcode().equals("unset")){
|
||||
binding.noEventError.setVisibility(View.VISIBLE);
|
||||
binding.buttons.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
binding.matchScoutingButton.setOnClickListener(v -> {
|
||||
msv1 msdata = new msv1();
|
||||
System.out.println(msdata.save("test.matchscoutdata"));
|
||||
// System.out.println(msdata.test().length);
|
||||
});
|
||||
|
||||
binding.pitScoutingButton.setOnClickListener(v -> {
|
||||
msv1 msdata = new msv1();
|
||||
System.out.println(msdata.load("test.matchscoutdata"));
|
||||
for(MatchScoutingVersion.dataType data : msdata.getTypes()){
|
||||
// System.out.println(data.getType());
|
||||
switch ((int)data.getType()){
|
||||
case 0:
|
||||
System.out.println((int)data.get());
|
||||
break;
|
||||
case 1:
|
||||
System.out.println((String) data.get());
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// msdata.set
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
android:id="@+id/no_event_error"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="No match has been specified\nPlease select one"
|
||||
android:text="No event has been specified\nPlease select one"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
android:visibility="gone"
|
||||
|
||||
@@ -14,11 +14,48 @@
|
||||
android:id="@+id/no_event_error"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="No match has been specified\nPlease select one"
|
||||
android:text="No event has been specified\nPlease select one"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/buttons"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/matchScoutingButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Match\n scouting"
|
||||
android:textSize="34sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/pitScoutingButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pitScoutingButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Pit\n Scouting"
|
||||
android:textSize="34sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/matchScoutingButton" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user