Skip to content

Commit

Permalink
Update MABHandler.java
Browse files Browse the repository at this point in the history
ArmWeight is now Arm
armWeights is now arms
armWeight is now arm

public class Arm {

    public String name;
    public Float weight;
    public String matrix;

...
  • Loading branch information
g-revanth authored Dec 15, 2023
1 parent e361a7b commit f0e3dff
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public class MABHandler {
private static final String TAG = "MABHandler";

public static String getArm(String dataSource, IScope2 scope) {
List<ArmWeight> armWeights = getArmWeights(dataSource, scope);
ArmWeight selectedArm = selectArm(armWeights);
Log.d(TAG, "getArm: list = "+armWeights);
Log.d(TAG, "getArm: selected = "+selectedArm);
List<Arm> arms = getarms(dataSource, scope);
Arm selectedArm = selectArm(arms);
Log.d(TAG, "getArm: list = " + arms);
Log.d(TAG, "getArm: selected = " + selectedArm);
return "";
}

// Selects an arm from a list of arms
private static ArmWeight selectArm(List<ArmWeight> armWeights) {
private static Arm selectArm(List<Arm> arms) {
float sum = 0;
for (ArmWeight arm : armWeights) {
for (Arm arm : arms) {
sum += arm.weight;
}

Expand All @@ -50,7 +50,7 @@ private static ArmWeight selectArm(List<ArmWeight> armWeights) {

// find out where p lies
float bottom = 0;
for (ArmWeight arm : armWeights) {
for (Arm arm : arms) {
float top = bottom + arm.weight;
if (bottom <= p && p <= top) {
return arm;
Expand All @@ -66,30 +66,34 @@ private static float getRandom(float min, float max) {
}


private static List<ArmWeight> getArmWeights(String dataSource, IScope2 scope) {
private static List<Arm> getarms(String dataSource, IScope2 scope) {
String jsonData = JSON_Helper.cacheData(dataSource);
List<ArmWeight> armWeights = new ArrayList<>();
List<Arm> arms = new ArrayList<>();
try {
JSONObject rootObject = new JSONObject(jsonData);
JSONArray rootArray = rootObject.getJSONArray(KEY_ARRAY);
armWeights = parseArray(rootArray, scope);

arms = parseArray(rootArray, scope);

// Adding logging to print arms
for (Arm arm : arms) {
Log.d(TAG, "Arm: " + arm.name + ", Weight: " + arm.weight + ", Matrix Path" + arm.matrix);
}

} catch (Exception e) {
Log.e(TAG, "Error in getArmWeights: " + e.getMessage());
Log.e(TAG, "Error in getarms: " + e.getMessage());
}
return armWeights;
return arms;
}


private static List<ArmWeight> parseArray(JSONArray array, IScope2 scope) throws JSONException {
List<ArmWeight> armWeights = new ArrayList<>();
private static List<Arm> parseArray(JSONArray array, IScope2 scope) throws JSONException {
List<Arm> arms = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
JSONObject armWeightJSON = array.getJSONObject(i);
ArmWeight armWeight = new ArmWeight(armWeightJSON, scope);
armWeights.add(armWeight);
JSONObject armJSON = array.getJSONObject(i);
Arm arm = new Arm(armJSON, scope);
arms.add(arm);
}
return armWeights;
return arms;
}


Expand Down

0 comments on commit f0e3dff

Please sign in to comment.