Fix stored int offset bug

This commit is contained in:
Astatin3
2024-09-14 18:02:31 -06:00
parent 6eff9179f4
commit 4f4c39bc92
14 changed files with 124 additions and 74 deletions
+3 -2
View File
@@ -8,18 +8,19 @@ Ridgebotics 2025 scouting app in Android
#### Data Analysis: #### Data Analysis:
- Statbotics intigration - Statbotics intigration
- AI overview of scouting data for a team??? - AI overview of scouting data for a team???
- Make the "Compare" menu, cross comparing team's stats.
#### Functionality: #### Functionality:
- When a field is created, make updated scouting data return null values, not the default value
- Make the system for blank and unselected fields better. - Make the system for blank and unselected fields better.
- Add more types of data fields. - Add more types of data fields.
- Make server software to allow for easy sync over wifi - Make server software to allow for easy sync over wifi
- Test the scouting app - Test the scouting app
- Deploy to F-Droid
## In Progress: ## In Progress:
#### Scouting: #### Scouting:
- When a field is created, make updated scouting data return null values, not the default value
- Fix scouting offset bug - Fix scouting offset bug
#### Data Analysis: #### Data Analysis:
- Make the "Compare" menu, cross comparing team's stats.
#### Functionality: #### Functionality:
@@ -26,9 +26,11 @@ public class ScoutingDataWriter {
switch (data[i].getValueType()){ switch (data[i].getValueType()){
case NUM: case NUM:
bb.addInt((int) data[i].forceGetValue()); bb.addInt((int) data[i].forceGetValue());
System.out.println("Saved INT: " + data[i].getName() + ", ("+ data[i].get() +")");
break; break;
case STRING: case STRING:
bb.addString((String) data[i].forceGetValue()); bb.addString((String) data[i].forceGetValue());
System.out.println("Saved STR: " + data[i].getName() + ", ("+ data[i].get() +")");
break; break;
} }
} }
@@ -64,12 +66,12 @@ public class ScoutingDataWriter {
case 1: // Int case 1: // Int
dataTypes[i] = intType.newNull(values[version][i].name); dataTypes[i] = intType.newNull(values[version][i].name);
dataTypes[i].forceSetValue(objects.get(i+2).get()); dataTypes[i].forceSetValue(objects.get(i+2).get());
//System.out.println("Loaded INT: " + values[version][i].name + ", ("+ dataTypes[i].get() +")"); System.out.println("Loaded INT: " + values[version][i].name + ", ("+ dataTypes[i].get() +")");
break; break;
case 2: // String case 2: // String
dataTypes[i] = stringType.newNull(values[version][i].name); dataTypes[i] = stringType.newNull(values[version][i].name);
dataTypes[i].forceSetValue(objects.get(i+2).get()); dataTypes[i].forceSetValue(objects.get(i+2).get());
//System.out.println("Loaded STR: " + values[version][i].name + ", ("+ dataTypes[i].get() +")"); System.out.println("Loaded STR: " + values[version][i].name + ", ("+ dataTypes[i].get() +")");
break; break;
} }
} }
@@ -23,28 +23,28 @@ public class fields {
public static final inputType[][] default_match_fields = new inputType[][] { public static final inputType[][] default_match_fields = new inputType[][] {
{ {
new tallyType("Auto Notes", 0), new tallyType("Auto Notes", 0),
new sliderType("Auto Performance", 5, 1, 10), new sliderType("Auto Performance", 5, 0, 10),
new textType("Auto Comments", "None"), new textType("Auto Comments", ""),
new tallyType("Teleop Notes", 0), new tallyType("Teleop Notes", 0),
new sliderType("Teleop Performance", 5, 1, 10), new sliderType("Teleop Performance", 5, 0, 10),
new textType("Teleop Comments", "None"), new textType("Teleop Comments", ""),
new sliderType("Overall Driving Performance", 5, 1, 10), new sliderType("Overall Driving Performance", 5, 0, 10),
new textType("Overall Driving Comments", "None"), new textType("Overall Driving Comments", ""),
new sliderType("Score area (AMP <-> Speaker)", 5, 1, 10), 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"}, 1), 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)"}, 1), 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", "None") new textType("Other Comments", "")
} }
}; };
public static final inputType[][] default_pit_fields = new inputType[][] { public static final inputType[][] default_pit_fields = new inputType[][] {
{ {
new sliderType("How good is robot", 5, 0, 10), new sliderType("How good is robot", 5, 0, 10),
new textType("notes", "<no-notes>"), new textType("notes", ""),
},{ },{
new sliderType("How good is robot", 5, 0, 10), new sliderType("How good is robot", 5, 0, 10),
new sliderType("Test", 1, 0, 10), new sliderType("Test", 1, 0, 10),
new textType("notes", "<no-notes>"), new textType("notes", ""),
} }
}; };
@@ -88,11 +88,9 @@ public class fields {
return values; return values;
// return true;
} catch (Exception e) { } catch (Exception e) {
AlertManager.error(e); AlertManager.error(e);
return null; return null;
// return false;
} }
} }
@@ -82,9 +82,9 @@ public class ScoutingArray {
inputType it = get_input_type_by_name(version+1, tv.name); inputType it = get_input_type_by_name(version+1, tv.name);
switch (it.getValueType()){ switch (it.getValueType()){
case NUM: case NUM:
return new intType(it.name, (int) it.default_value); return intType.newNull(it.name);
case STRING: case STRING:
return new stringType(it.name, (String) it.default_value); return stringType.newNull(it.name);
} }
return null; return null;
} }
@@ -21,7 +21,7 @@ public abstract class dataType {
// public abstract Object getUnselectedValue(); // public abstract Object getUnselectedValue();
public abstract boolean isNull(); public abstract boolean isNull();
public abstract boolean isUnselected(); // public abstract boolean isUnselected();
public String getName() {return name;} public String getName() {return name;}
@@ -1,9 +1,8 @@
package com.astatin3.scoutingapp2025.types.data; package com.astatin3.scoutingapp2025.types.data;
public class intType extends dataType { public class intType extends dataType {
public static final int nullval = 0; public static final int nullval = 255;
public static final int unselectedval = 1; // public static final int unselectedval = 1;
public static final int offset = 2;
public valueTypes getValueType() { public valueTypes getValueType() {
return valueTypes.NUM; return valueTypes.NUM;
@@ -17,11 +16,11 @@ public class intType extends dataType {
// } // }
public Object get(){ public Object get(){
return (int) forceGetValue()-2; return (int) forceGetValue();
} }
public void set(Object value){ public void set(Object value){
forceSetValue((int) value + 2); forceSetValue((int) value);
} }
public intType(String name, int value) { public intType(String name, int value) {
@@ -35,11 +34,11 @@ public class intType extends dataType {
return a; return a;
} }
public static intType newUnselected(String name){ // public static intType newUnselected(String name){
final intType a = new intType(name, 0); // final intType a = new intType(name, 0);
a.forceSetValue(unselectedval); // a.forceSetValue(unselectedval);
return a; // return a;
} // }
public static boolean isNull(int obj){ public static boolean isNull(int obj){
return obj == nullval; return obj == nullval;
@@ -48,10 +47,10 @@ public class intType extends dataType {
return isNull((int) forceGetValue()); return isNull((int) forceGetValue());
} }
public static boolean isUnselected(int obj){ // public static boolean isUnselected(int obj){
return obj == unselectedval; // return obj == unselectedval;
} // }
public boolean isUnselected() { // public boolean isUnselected() {
return isUnselected((int) forceGetValue()); // return isUnselected((int) forceGetValue());
} // }
} }
@@ -1,8 +1,8 @@
package com.astatin3.scoutingapp2025.types.data; package com.astatin3.scoutingapp2025.types.data;
public class stringType extends dataType{ public class stringType extends dataType{
public static final String nullval = "ƒ"; public static final String nullval = "null";
public static final String unselectedval = ""; // public static final String unselectedval = "■";
public valueTypes getValueType() { public valueTypes getValueType() {
return valueTypes.STRING; return valueTypes.STRING;
@@ -34,11 +34,11 @@ public class stringType extends dataType{
return a; return a;
} }
public static stringType newUnselected(String name){ // public static stringType newUnselected(String name){
final stringType a = new stringType(name, ""); // final stringType a = new stringType(name, "");
a.forceSetValue(unselectedval); // a.forceSetValue(unselectedval);
return a; // return a;
} // }
public static boolean isNull(String obj){ public static boolean isNull(String obj){
return obj.equals(nullval); return obj.equals(nullval);
@@ -48,10 +48,10 @@ public class stringType extends dataType{
} }
public static boolean isUnselected(String obj){ // public static boolean isUnselected(String obj){
return obj.equals(unselectedval); // return obj.equals(unselectedval);
} // }
public boolean isUnselected() { // public boolean isUnselected() {
return isUnselected((String) forceGetValue()); // return isUnselected((String) forceGetValue());
} // }
} }
@@ -8,6 +8,7 @@ import android.widget.LinearLayout;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import com.astatin3.scoutingapp2025.types.data.dataType; import com.astatin3.scoutingapp2025.types.data.dataType;
import com.astatin3.scoutingapp2025.ui.data.FieldEditorHelper;
import com.astatin3.scoutingapp2025.utility.BuiltByteParser; import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder; import com.astatin3.scoutingapp2025.utility.ByteBuilder;
@@ -35,19 +36,6 @@ public abstract class inputType {
this.name = name; this.name = name;
} }
// public enum parameterType {
// NUMBER,
// STRING,
// STRINGARRAY
// }
// public static parameterType[] parameterTypeByInputType(inputTypes t){
// switch (t){
// case SLIDER:
// return new parameterType[]{parameterType.NUMBER, };
// }
// }
public abstract String get_type_name(); public abstract String get_type_name();
public abstract byte[] encode() throws ByteBuilder.buildingException; public abstract byte[] encode() throws ByteBuilder.buildingException;
@@ -64,6 +52,48 @@ public abstract class inputType {
public abstract dataType getViewValue(); public abstract dataType getViewValue();
// private enum parameterTypeEnum {
// paramNumber,
// paramString,
// paramStringArray
// }
//
// public static class parameterType {
// public String name;
// public parameterTypeEnum id;
// }
//
// public static class paramNumber extends parameterType {
// public int val;
// public paramNumber(String name, int val){
// this.name = name + " (Number)";
// this.val = val;
// this.id = parameterTypeEnum.paramNumber;
// }
// }
//
// public static class paramString extends parameterType {
// public String val;
// public paramString(String name, String val){
// this.name = name + " (String)";
// this.val = val;
// this.id = parameterTypeEnum.paramString;
// }
// }
//
// public static class paramStringArray extends parameterType {
// public String[] val;
// public paramStringArray(String name, String[] val){
// this.name = name + " (String array)";
// this.val = val;
// this.id = parameterTypeEnum.paramStringArray;
// }
// }
// public abstract parameterType[] getDefaultParameters();
public abstract void add_individual_view(LinearLayout parent, dataType data); public abstract void add_individual_view(LinearLayout parent, dataType data);
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import com.astatin3.scoutingapp2025.types.data.dataType; import com.astatin3.scoutingapp2025.types.data.dataType;
import com.astatin3.scoutingapp2025.types.data.intType; import com.astatin3.scoutingapp2025.types.data.intType;
import com.astatin3.scoutingapp2025.types.data.stringType; import com.astatin3.scoutingapp2025.types.data.stringType;
import com.astatin3.scoutingapp2025.utility.AlertManager;
import com.astatin3.scoutingapp2025.utility.BuiltByteParser; import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder; import com.astatin3.scoutingapp2025.utility.ByteBuilder;
import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.charts.LineChart;
@@ -91,8 +92,17 @@ public class sliderType extends inputType {
float step_size = (float) 1/(max-min); float step_size = (float) 1/(max-min);
int round_position = Math.round(slider_position / step_size); int round_position = Math.round(slider_position / step_size);
isBlank = false; isBlank = false;
float slidervalue = round_position*step_size;
if(slidervalue > 1 || slidervalue < 0) {
AlertManager.error("Error loading slider " + name);
slider.setValue(0);
}else{
slider.setValue(slidervalue);
}
slider.setVisibility(View.VISIBLE); slider.setVisibility(View.VISIBLE);
slider.setValue(round_position*step_size);
} }
public dataType getViewValue(){ public dataType getViewValue(){
if(slider == null) return null; if(slider == null) return null;
@@ -116,9 +126,15 @@ public class sliderType extends inputType {
float slider_position = (float) ((int) data.get()-min) / (max-min); float slider_position = (float) ((int) data.get()-min) / (max-min);
float step_size = (float) 1/(max-min); float step_size = (float) 1/(max-min);
int round_position = Math.round(slider_position / step_size); int round_position = Math.round(slider_position / step_size);
slider.setValue(round_position*step_size); float value = round_position*step_size;
if(value > 1 || value < 0) {
AlertManager.error("Error loading slider " + name);
slider.setValue(0);
}else{
slider.setValue(value);
slider.setStepSize((float) 1 / (max-min));
}
slider.setStepSize((float) 1 / (max-min));
slider.setEnabled(false); slider.setEnabled(false);
parent.addView(slider); parent.addView(slider);
} }
@@ -73,14 +73,14 @@ public class tallyType extends inputType {
public void setViewValue(Object value) { public void setViewValue(Object value) {
if(tally == null) return; if(tally == null) return;
System.out.println(value); System.out.println(value);
if((int)value == intType.nullval || (int)value == intType.unselectedval){ if(intType.isNull((int)value)){
nullify(); nullify();
return; return;
} }
isBlank = false; isBlank = false;
tally.setVisibility(View.VISIBLE); tally.setVisibility(View.VISIBLE);
tally.setValue((int) value-2); tally.setValue((int) value);
} }
public void nullify(){ public void nullify(){
isBlank = true; isBlank = true;
@@ -88,7 +88,7 @@ public class tallyType extends inputType {
} }
public dataType getViewValue(){ public dataType getViewValue(){
if(tally == null) return null; if(tally == null) return null;
if(tally.getVisibility() == View.GONE) return new intType(name, 0); if(tally.getVisibility() == View.GONE) return intType.newNull(name);
return new intType(name, tally.getValue()); return new intType(name, tally.getValue());
} }
@@ -1,7 +1,5 @@
package com.astatin3.scoutingapp2025.types.input; package com.astatin3.scoutingapp2025.types.input;
import static com.astatin3.scoutingapp2025.types.data.intType.offset;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.text.Editable; import android.text.Editable;
@@ -340,7 +340,13 @@ public class MatchScoutingFragment extends Fragment {
for(int i = 0; i < DataManager.match_latest_values.length; i++){ for(int i = 0; i < DataManager.match_latest_values.length; i++){
// types[i] = latest_values[i].getViewValue(); // types[i] = latest_values[i].getViewValue();
DataManager.match_latest_values[i].setViewValue(types[i].get()); try {
DataManager.match_latest_values[i].setViewValue(types[i].get());
} catch (Exception e){
AlertManager.error(e);
DataManager.match_latest_values[i].setViewValue(DataManager.match_latest_values[i].default_value);
}
if(DataManager.match_latest_values[i].isBlank){ if(DataManager.match_latest_values[i].isBlank){
titles[i].setBackgroundColor(0xffff0000); titles[i].setBackgroundColor(0xffff0000);
@@ -18,7 +18,7 @@ public class BuiltByteParser {
} }
public static String unBlankStrNull(String str){ public static String unBlankStrNull(String str){
if(str.equals("null")){ if(str.equals("ƒ")){
return ""; return "";
} }
else return str; else return str;
@@ -27,7 +27,7 @@ public class ByteBuilder {
public static String blankStrNull(String str){ public static String blankStrNull(String str){
if(str.isEmpty() || str.isEmpty()){ if(str.isEmpty() || str.isEmpty()){
return "null"; return "ƒ";
} }
else return str; else return str;
} }