From b8175dce50a652e3f67ceffec5f3598d6b4a965c Mon Sep 17 00:00:00 2001 From: ssvaditya Date: Tue, 24 Oct 2023 13:48:14 +0530 Subject: [PATCH 01/17] Cleaned up code in CTutorEngine.java --- .../assets/filtered_translaion.csv | 64 ------------------- .../robotutor/tutorengine/CTutorEngine.java | 20 +++--- 2 files changed, 10 insertions(+), 74 deletions(-) delete mode 100644 app/src/main/assets/tutors/activity_selector/assets/filtered_translaion.csv diff --git a/app/src/main/assets/tutors/activity_selector/assets/filtered_translaion.csv b/app/src/main/assets/tutors/activity_selector/assets/filtered_translaion.csv deleted file mode 100644 index d96f53ddf..000000000 --- a/app/src/main/assets/tutors/activity_selector/assets/filtered_translaion.csv +++ /dev/null @@ -1,64 +0,0 @@ -unfiltered_activity_name,unfiltered_row,unfiltered_column,filtered_activity_name,filtered_row,filtered_column -write.ltr.uc.dic:vow.asc.A..Z.3,0,49,akira:vow.ltr.uc:A..Z.vow.5.asc.say.11,0,50 -write.ltr.uc.dic:all.asc.A..Z.9,2,243,bpop.ltr.uc:A..Z.all.rand.all.stat.noShow.77,2,244 -write.missingLtr:lc.begin.ha.1,6,7,story.echo::begin.wrd.ha.rand.35,6,8 -write.missingLtr:lc.begin.ha.18,6,9,story.hear::begin.wrd.ka.rand.2,6,10 -write.missingLtr:lc.begin.ka.2,6,17,story.echo::begin.wrd.ka.rand.36,6,18 -write.missingLtr:lc.begin.ka.19,6,19,story.hear::begin.wrd.ki.rand.3,6,20 -write.missingLtr:lc.begin.ki.3,6,27,story.echo::begin.wrd.ki.rand.37,6,28 -write.missingLtr:lc.begin.ki.20,6,29,story.hear::begin.wrd.ku.rand.4,6,30 -write.missingLtr:lc.begin.ku.4,6,34,story.echo::begin.wrd.ku.rand.38,6,35 -write.missingLtr:lc.begin.na.5,6,41,bpop.wrd:begin.wrd.na.noShow.10,6,42 -write.missingLtr:lc.begin.na.22,6,44,story.hear::begin.wrd.si.rand.6,6,45 -write.missingLtr:lc.begin.si.6,6,49,bpop.wrd:begin.wrd.si.noShow.12,6,50 -write.missingLtr:lc.begin.si.23,6,52,story.hear::begin.wrd.ta.rand.7,6,53 -write.missingLtr:lc.begin.ta.7,6,56,story.parrot::begin.wrd.ta.rand.24,6,57 -write.missingLtr:lc.begin.ta.24,6,60,story.hear::begin.wrd.wa.rand.8,6,61 -write.missingLtr:lc.begin.wa.8,6,65,bpop.wrd:begin.wrd.wa.noShow.16,6,66 -write.missingLtr:lc.begin.wa.25,6,68,story.hear::end.wrd.ko.rand.9,6,69 -write.missingLtr:lc.end.ko.9,6,73,bpop.wrd:end.wrd.ko.noShow.18,6,74 -write.missingLtr:lc.end.ko.26,6,76,story.hear::end.wrd.le.rand.10,6,77 -write.missingLtr:lc.end.le.10,6,81,bpop.wrd:end.wrd.le.noShow.20,6,82 -write.missingLtr:lc.end.le.27,6,84,story.hear::end.wrd.li.rand.11,6,85 -write.missingLtr:lc.end.li.11,6,89,bpop.wrd:end.wrd.li.noShow.22,6,90 -write.missingLtr:lc.end.li.28,6,92,story.hear::end.wrd.ma.rand.12,6,93 -write.missingLtr:lc.end.ma.12,6,97,bpop.wrd:end.wrd.ma.noShow.24,6,98 -write.missingLtr:lc.end.ma.29,6,100,story.hear::end.wrd.na.rand.13,6,101 -write.missingLtr:lc.end.na.13,6,105,bpop.wrd:end.wrd.na.noShow.26,6,106 -write.missingLtr:lc.end.na.30,6,108,story.hear::end.wrd.ni.rand.14,6,109 -write.missingLtr:lc.end.ni.14,6,113,bpop.wrd:end.wrd.ni.noShow.28,6,114 -write.missingLtr:lc.end.ni.31,6,116,story.hear::end.wrd.sa.rand.15,6,117 -write.missingLtr:lc.end.sa.15,6,121,bpop.wrd:end.wrd.sa.noShow.30,6,122 -write.missingLtr:lc.end.sa.32,6,124,story.hear::end.wrd.wa.rand.16,6,125 -write.missingLtr:lc.end.wa.16,6,129,bpop.wrd:end.wrd.wa.noShow.32,6,130 -write.missingLtr:lc.end.wa.33,6,132,story.hear::end.wrd.we.rand.17,6,133 -write.missingLtr:lc.end.we.17,6,137,bpop.wrd:end.wrd.we.noShow.34,6,138 -write.missingLtr:lc.end.we.34,6,140,bpop.wrd:begin.wrd.all.noShow.35,6,141 -write.missingLtr:1.0.1.fin.v,8,25,bpop.wrd:wrd.4.lc.rand.stat.noShow.2__it_2,8,26 -write.missingLtr:1.0.1.init.c,8,27,bpop.wrd:wrd.4.lc.rand.stat.noShow.2__it_3,8,28 -write.missingLtr:0.1.2.init.s,9,18,story.echo::story_18,9,19 -write.missingLtr:0.1.2.fin.s,9,20,bpop.wrd:wrd.5.lc.rand.stat.noShow.4__it_2,9,21 -write.missingLtr:0.1.3.init.s,10,25,bpop.wrd:wrd.6.lc.rand.stat.noShow.6__it_2,10,27 -write.missingLtr:0.1.3.fin.s,10,26,bpop.wrd:wrd.6.lc.rand.stat.noShow.6__it_2,10,27 -write.missingLtr:0.1.3.med.s,12,17,story.echo::story_36,12,18 -write.missingLtr:0.1.4.init.s,12,19,bpop.wrd:wrd.7.lc.rand.stat.noShow.8__it_2,12,20 -write.missingLtr:0.1.4.fin.s,13,22,story.echo::story_42,13,23 -write.missingLtr:0.1.4.med.s,13,24,bpop.wrd:wrd.8.lc.rand.stat.noShow.10__it_2,13,25 -write.missingLtr:0.1.5.init.s,15,17,story.echo::story_54,15,18 -write.missingLtr:0.1.5.fin.s,15,19,bpop.wrd:wrd.9.lc.rand.stat.noShow.12__it_2,15,20 -write.missingLtr:0.1.5.med.s,16,6,story.echo::HF.wrd.len-10.rand.14,16,7 -write.missingLtr:0.1.6.init.s,16,8,bpop.wrd:wrd.10.lc.rand.stat.noShow.14__it_2,16,9 -write.sen.copy.ltr:story_1.noerror.1.1,17,2,story.read::story_2,17,3 -write.sen.copy.ltr:story_1.noerror.1.2,17,4,story.read::story_3,17,5 -write.sen.copy.ltr:story_1.noerror.1.3,17,6,story.read::story_4,17,7 -write.sen.copy.ltr:story_1.noerror.1.4,17,8,story.read::story_5,17,9 -write.sen.copy.ltr:story_2.noerror.2.1,17,10,story.read::story_6,17,11 -write.sen.copy.ltr:story_2.noerror.2.2,17,12,story.read::story_7,17,13 -write.sen.copy.ltr:story_2.noerror.2.3,17,14,story.read::story_8,17,15 -write.sen.dic.ltr:story_1.noerror.1.1,17,44,story.read::story_22,17,45 -write.sen.dic.ltr:story_1.noerror.1.2,17,46,story.read::story_23,17,47 -write.sen.dic.ltr:story_1.noerror.1.3,17,48,story.read::story_24,17,49 -write.sen.dic.ltr:story_1.noerror.1.4,17,50,story.read::story_25,17,51 -write.sen.dic.ltr:story_2.noerror.2.1,17,52,story.read::story_26,17,53 -write.sen.dic.ltr:story_2.noerror.2.2,17,54,story.read::story_27,17,55 -write.sen.dic.ltr:story_2.noerror.2.3,17,56,story.read::story_28,17,57 diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java index 2fd438e8e..a37539983 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java @@ -815,7 +815,7 @@ private static TransitionMatrixModel loadTransitionMatrixModel() { //String dataFile = "dev_data.json"; String dataFile = RoboTutor.MATRIX_FILE; - // simpler way to refer to languge + // simpler way to refer to language String lang = TCONST.langMap.get(CTutorEngine.language); String dataPath = TCONST.TUTORROOT + "/" + tutorName + "/" + TCONST.TASSETS; @@ -823,15 +823,14 @@ private static TransitionMatrixModel loadTransitionMatrixModel() { String jsonData = JSON_Helper.cacheData(dataPath + dataFile); - // // Load the datasource into a separate class... TransitionMatrixModel matrix = new TransitionMatrixModel(dataPath + dataFile, mRootScope); matrix.validateAll(); System.out.println("dataPath: " + dataPath); - System.out.println("Log pointer"); + System.out.println("Log pointer"); //to locate required data in log - HashMap h2 = loadTranslationTable(Activity.getApplicationContext()); - System.out.println("h2 : " + h2); + HashMap translationTable = loadTranslationTable(Activity.getApplicationContext()); + System.out.println("translationTable : " + translationTable); return matrix; } @@ -861,7 +860,8 @@ public void loadJSON(JSONObject jsonObj, IScope scope) { } public static HashMap loadTranslationTable(Context context) { - HashMap hm = new HashMap<>(); + + HashMap translationTable = new HashMap<>(); try { //csv file containing data @@ -882,10 +882,10 @@ public static HashMap loadTranslationTable(Context context) { while (st.hasMoreTokens()) { tokenNumber++; - String a = st.nextToken(); + String currentActivity = st.nextToken(); tokenNumber+=2; - String b = st.nextToken(); - hm.put(a, b); + String nextActivity = st.nextToken(); + translationTable.put(currentActivity, nextActivity); } } } catch (FileNotFoundException e) { @@ -894,7 +894,7 @@ public static HashMap loadTranslationTable(Context context) { e.printStackTrace(); } - return hm; + return translationTable; } From c60b3f6777a8c9c6471064ba3b158117dfdcbaa5 Mon Sep 17 00:00:00 2001 From: ssvaditya Date: Tue, 14 Nov 2023 18:43:56 +0530 Subject: [PATCH 02/17] Minor adjustments in loading the Translation Table --- .../robotutor/tutorengine/CTutorEngine.java | 33 ++++++++++++++----- .../util/StudentChooseMatrixActivityMenu.java | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java index a37539983..6ab329dee 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java @@ -871,23 +871,39 @@ public static HashMap loadTranslationTable(Context context) { BufferedReader br = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); String strLine; StringTokenizer st; - int lineNumber = 0, tokenNumber = 0; + int lineNumber = 0; - //read comma-separated file line by line + // Skip the first line + br.readLine(); + + // read comma-separated file line by line while ((strLine = br.readLine()) != null) { lineNumber++; - //break comma-separated line using "," + // break comma-separated line using "," st = new StringTokenizer(strLine, ","); - while (st.hasMoreTokens()) { - tokenNumber++; - String currentActivity = st.nextToken(); - tokenNumber+=2; - String nextActivity = st.nextToken(); + // Make sure there are at least 4 tokens before accessing 0th and 3rd indices + if (st.countTokens() >= 4) { + // Skip the first three tokens + String currentActivity = st.nextToken(); // 1st token + System.out.println(currentActivity); + st.nextToken(); // Skipping 2nd token + st.nextToken(); // Skipping 3rd token + + String nextActivity = st.nextToken(); // 4th token + System.out.println(nextActivity); + + // Skip the next two tokens + st.nextToken(); // Skipping 4th token + st.nextToken(); // Skipping 5th token + translationTable.put(currentActivity, nextActivity); + } else { + System.err.println("Invalid format in line " + lineNumber + ": " + strLine); } } + } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { @@ -903,4 +919,3 @@ public static HashMap loadTranslationTable(Context context) { - diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java index 30363927d..ddd22c3db 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java @@ -164,6 +164,7 @@ public CAt_Data getTutorToLaunch(String buttonBehavior) { return tutorToLaunch; } + @Override public String getDebugMenuSkill() { return _student.getActiveSkill(); From c7ee0b33355ba6e658931cef85e822a776d64ceb Mon Sep 17 00:00:00 2001 From: ssvaditya Date: Tue, 14 Nov 2023 21:36:17 +0530 Subject: [PATCH 03/17] Created function to use translation table and minor fixes --- .../robotutor/tutorengine/CTutorEngine.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java index 6ab329dee..21ef549ad 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java @@ -122,6 +122,8 @@ public enum MenuType {STUDENT_CHOICE, CYCLE_CONTENT}; final static private String TAG = "CTutorEngine"; + static public HashMap translationTable = new HashMap<>(); + /** * TutorEngine is a Singleton @@ -829,11 +831,18 @@ private static TransitionMatrixModel loadTransitionMatrixModel() { System.out.println("dataPath: " + dataPath); System.out.println("Log pointer"); //to locate required data in log - HashMap translationTable = loadTranslationTable(Activity.getApplicationContext()); + loadTranslationTable(Activity.getApplicationContext()); System.out.println("translationTable : " + translationTable); + + String oldActivity = "write.missingLtr:lc.begin.ka.2"; + String nextActivity = getTranslatedActivityID(oldActivity); + + System.out.println("Translated activity: " + nextActivity); return matrix; } + + private static void getArm() { String tutorName = "activity_selector"; String dataPath = TCONST.TUTORROOT + "/" + tutorName; @@ -859,9 +868,13 @@ public void loadJSON(JSONObject jsonObj, IScope scope) { loadJSON(jsonObj, (IScope2) scope); } - public static HashMap loadTranslationTable(Context context) { - HashMap translationTable = new HashMap<>(); + public static String getTranslatedActivityID(String oldActivityID){ + return translationTable.get(oldActivityID); + } + + + static void loadTranslationTable(Context context) { try { //csv file containing data @@ -887,35 +900,31 @@ public static HashMap loadTranslationTable(Context context) { if (st.countTokens() >= 4) { // Skip the first three tokens String currentActivity = st.nextToken(); // 1st token - System.out.println(currentActivity); st.nextToken(); // Skipping 2nd token st.nextToken(); // Skipping 3rd token String nextActivity = st.nextToken(); // 4th token - System.out.println(nextActivity); - // Skip the next two tokens - st.nextToken(); // Skipping 4th token st.nextToken(); // Skipping 5th token + st.nextToken(); // Skipping 6th token translationTable.put(currentActivity, nextActivity); } else { System.err.println("Invalid format in line " + lineNumber + ": " + strLine); } } - } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } - return translationTable; + System.out.println("translationTable : " + translationTable); } - } + From 71b8f877debb7f1df5c0c1c2121fccc323f8e1b1 Mon Sep 17 00:00:00 2001 From: ssvaditya Date: Tue, 14 Nov 2023 22:17:34 +0530 Subject: [PATCH 04/17] Translate tutotId --- .../tutorengine/util/CycleMatrixActivityMenu.java | 10 ++++++++-- .../util/StudentChooseMatrixActivityMenu.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/CycleMatrixActivityMenu.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/CycleMatrixActivityMenu.java index 944cf22ec..7f00c2766 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/CycleMatrixActivityMenu.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/CycleMatrixActivityMenu.java @@ -9,6 +9,7 @@ import cmu.xprize.comp_ask.CAsk_Data; import cmu.xprize.comp_session.AS_CONST; import cmu.xprize.robotutor.RoboTutor; +import cmu.xprize.robotutor.tutorengine.CTutorEngine; import cmu.xprize.util.CAt_Data; import cmu.xprize.util.CPlacementTest_Tutor; @@ -274,10 +275,15 @@ public CAt_Data getTutorToLaunch(String buttonBehavior) { Log.wtf(MENU_BUG_TAG, chosenTutorId + " " + activeSkill); // This is just to make sure we go somewhere if there is a bad link - which - // there shuoldn't be :) + // there shouldn't be :) // if (tutorToLaunch == null) { - tutorToLaunch = (CAt_Data) transitionMap.get(rootTutor); + String nextTutorId = CTutorEngine.getTranslatedActivityID(chosenTutorId); + tutorToLaunch = (CAt_Data) transitionMap.get(nextTutorId); + + if (tutorToLaunch == null) { + tutorToLaunch = (CAt_Data) transitionMap.get(rootTutor); + } } return tutorToLaunch; } diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java index ddd22c3db..89285162b 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/StudentChooseMatrixActivityMenu.java @@ -7,6 +7,7 @@ import cmu.xprize.comp_ask.CAsk_Data; import cmu.xprize.comp_session.AS_CONST; import cmu.xprize.robotutor.RoboTutor; +import cmu.xprize.robotutor.tutorengine.CTutorEngine; import cmu.xprize.util.CAt_Data; import static cmu.xprize.comp_session.AS_CONST.BEHAVIOR_KEYS.SELECT_MATH; @@ -156,10 +157,15 @@ public CAt_Data getTutorToLaunch(String buttonBehavior) { CAt_Data tutorToLaunch = (CAt_Data) transitionMap.get(activeTutorId); // This is just to make sure we go somewhere if there is a bad link - which - // there shuoldn't be :) + // there shouldn't be :) // if (tutorToLaunch == null) { - tutorToLaunch = (CAt_Data) transitionMap.get(rootTutor); + String nextTutorId = CTutorEngine.getTranslatedActivityID(activeTutorId); + tutorToLaunch = (CAt_Data) transitionMap.get(nextTutorId); + + if (tutorToLaunch == null) { + tutorToLaunch = (CAt_Data) transitionMap.get(rootTutor); + } } return tutorToLaunch; } From 26e8b8790e53eb4396f92a3a7dcb30c32788f719 Mon Sep 17 00:00:00 2001 From: ssvaditya Date: Tue, 14 Nov 2023 22:18:24 +0530 Subject: [PATCH 05/17] Translate null id --- .../java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java index 21ef549ad..77b3b5d67 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java @@ -886,6 +886,10 @@ static void loadTranslationTable(Context context) { StringTokenizer st; int lineNumber = 0; + //Sample of csv file + //unfiltered_activity_name,unfiltered_row,unfiltered_column,filtered_activity_name,filtered_row,filtered_column + //write.ltr.uc.dic:vow.asc.A..Z.3,0,49,akira:vow.ltr.uc:A..Z.vow.5.asc.say.11,0,50 + // Skip the first line br.readLine(); From 9ab6b8390691f47e1533d4c3291686073ec2594d Mon Sep 17 00:00:00 2001 From: ssvaditya Date: Tue, 14 Nov 2023 22:18:24 +0530 Subject: [PATCH 06/17] Added example to translation table --- .../java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java index 21ef549ad..77b3b5d67 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java @@ -886,6 +886,10 @@ static void loadTranslationTable(Context context) { StringTokenizer st; int lineNumber = 0; + //Sample of csv file + //unfiltered_activity_name,unfiltered_row,unfiltered_column,filtered_activity_name,filtered_row,filtered_column + //write.ltr.uc.dic:vow.asc.A..Z.3,0,49,akira:vow.ltr.uc:A..Z.vow.5.asc.say.11,0,50 + // Skip the first line br.readLine(); From 5623fb3d81e9dac3213ffea5192bb2dc0a81acd5 Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:43:44 -0500 Subject: [PATCH 07/17] Update MABHandler.java logging --- .../tutorengine/util/MABHandler.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index 12fb0092d..a69acc024 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -67,17 +67,24 @@ private static float getRandom(float min, float max) { private static List getArmWeights(String dataSource, IScope2 scope) { - String jsonData = JSON_Helper.cacheData(dataSource); - List armWeights = new ArrayList<>(); - try { - JSONObject rootObject = new JSONObject(jsonData); - JSONArray rootArray = rootObject.getJSONArray(KEY_ARRAY); - armWeights = parseArray(rootArray, scope); - } catch (Exception e) { - Log.d(TAG, "getArmWeights: "+e); + String jsonData = JSON_Helper.cacheData(dataSource); + List armWeights = new ArrayList<>(); + try { + JSONObject rootObject = new JSONObject(jsonData); + JSONArray rootArray = rootObject.getJSONArray(KEY_ARRAY); + armWeights = parseArray(rootArray, scope); + + // Adding logging to print arm weights + for (ArmWeight armWeight : armWeights) { + Log.d(TAG, "Arm: " + armWeight.name + ", Weight: " + armWeight.weight); } - return armWeights; + + } catch (Exception e) { + Log.e(TAG, "Error in getArmWeights: " + e.getMessage()); } + return armWeights; +} + private static List parseArray(JSONArray array, IScope2 scope) throws JSONException { List armWeights = new ArrayList<>(); From b1a777888ba2ab548bfbb464c8ca14f8ec6b26e9 Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:45:45 -0500 Subject: [PATCH 08/17] Update MABHandler.java --- .../tutorengine/util/MABHandler.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index a69acc024..5baebbfc3 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -67,22 +67,22 @@ private static float getRandom(float min, float max) { private static List getArmWeights(String dataSource, IScope2 scope) { - String jsonData = JSON_Helper.cacheData(dataSource); - List armWeights = new ArrayList<>(); - try { - JSONObject rootObject = new JSONObject(jsonData); - JSONArray rootArray = rootObject.getJSONArray(KEY_ARRAY); - armWeights = parseArray(rootArray, scope); - - // Adding logging to print arm weights - for (ArmWeight armWeight : armWeights) { - Log.d(TAG, "Arm: " + armWeight.name + ", Weight: " + armWeight.weight); + String jsonData = JSON_Helper.cacheData(dataSource); + List armWeights = new ArrayList<>(); + try { + JSONObject rootObject = new JSONObject(jsonData); + JSONArray rootArray = rootObject.getJSONArray(KEY_ARRAY); + armWeights = parseArray(rootArray, scope); + + // Adding logging to print arm weights + for (ArmWeight armWeight : armWeights) { + Log.d(TAG, "Arm: " + armWeight.name + ", Weight: " + armWeight.weight); + } + + } catch (Exception e) { + Log.e(TAG, "Error in getArmWeights: " + e.getMessage()); } - - } catch (Exception e) { - Log.e(TAG, "Error in getArmWeights: " + e.getMessage()); - } - return armWeights; + return armWeights; } From bfc60eac415f861c97e8a1570339c8bb7e12e44e Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:07:05 -0500 Subject: [PATCH 09/17] Update CTutorEngine.java --- .../java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java index 77b3b5d67..011522e22 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/CTutorEngine.java @@ -844,11 +844,16 @@ private static TransitionMatrixModel loadTransitionMatrixModel() { private static void getArm() { + + Log.d("MAB", "Entering getArm() method."); + String tutorName = "activity_selector"; String dataPath = TCONST.TUTORROOT + "/" + tutorName; String dataFile = RoboTutor.ARM_WEIGHTS_FILE; MABHandler.getArm(dataPath + "/" + dataFile, mRootScope); + + Log.d("MAB", "Exiting getArm() method."); } From 20baadf183585b6f79c8007fb034e8da8b2e79fc Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:18:38 -0500 Subject: [PATCH 10/17] Update MABHandler.java --- .../java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index 5baebbfc3..d96509941 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -76,7 +76,7 @@ private static List getArmWeights(String dataSource, IScope2 scope) { // Adding logging to print arm weights for (ArmWeight armWeight : armWeights) { - Log.d(TAG, "Arm: " + armWeight.name + ", Weight: " + armWeight.weight); + Log.d(TAG, "Arm: " + armWeight.armName + ", Weight: " + armWeight.armWeight); } } catch (Exception e) { From 04041471fe535c990f9b3999adc1cf3d81f07be8 Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 18:22:00 -0500 Subject: [PATCH 11/17] Update MABHandler.java --- .../java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index d96509941..dd8b41dba 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -76,7 +76,7 @@ private static List getArmWeights(String dataSource, IScope2 scope) { // Adding logging to print arm weights for (ArmWeight armWeight : armWeights) { - Log.d(TAG, "Arm: " + armWeight.armName + ", Weight: " + armWeight.armWeight); + Log.d(TAG, "Arm: " + armWeight.arm_Name + ", Weight: " + armWeight.arm_Weight); } } catch (Exception e) { From 26704f1afe38e0673ab3595c9d04e75e11d941de Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 18:29:38 -0500 Subject: [PATCH 12/17] Update MABHandler.java --- .../java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index dd8b41dba..9577f74fe 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -76,7 +76,7 @@ private static List getArmWeights(String dataSource, IScope2 scope) { // Adding logging to print arm weights for (ArmWeight armWeight : armWeights) { - Log.d(TAG, "Arm: " + armWeight.arm_Name + ", Weight: " + armWeight.arm_Weight); + Log.d(TAG, "Arm: " + armWeight.arm_name + ", Weight: " + armWeight.arm_weight); } } catch (Exception e) { From 8e15efb95b9da443a95b8b404d30577461d5c480 Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:04:31 -0500 Subject: [PATCH 13/17] Update MABHandler.java --- .../java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index 9577f74fe..1c30470c4 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -76,7 +76,7 @@ private static List getArmWeights(String dataSource, IScope2 scope) { // Adding logging to print arm weights for (ArmWeight armWeight : armWeights) { - Log.d(TAG, "Arm: " + armWeight.arm_name + ", Weight: " + armWeight.arm_weight); + Log.d(TAG, "Arm: " + armWeight; } } catch (Exception e) { From ae6f03d737b23bb70a18b743781ef9973d3d2210 Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:06:24 -0500 Subject: [PATCH 14/17] Update MABHandler.java --- .../cmu/xprize/robotutor/tutorengine/util/MABHandler.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index 1c30470c4..fa125460d 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -73,11 +73,7 @@ private static List getArmWeights(String dataSource, IScope2 scope) { JSONObject rootObject = new JSONObject(jsonData); JSONArray rootArray = rootObject.getJSONArray(KEY_ARRAY); armWeights = parseArray(rootArray, scope); - - // Adding logging to print arm weights - for (ArmWeight armWeight : armWeights) { - Log.d(TAG, "Arm: " + armWeight; - } + } catch (Exception e) { Log.e(TAG, "Error in getArmWeights: " + e.getMessage()); From e361a7b0249e5d287afe017e77ff1425c3af3c3e Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:32:41 -0500 Subject: [PATCH 15/17] Update ArmWeight.java --- .../cmu/xprize/robotutor/tutorengine/util/ArmWeight.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/ArmWeight.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/ArmWeight.java index de7b97b32..4eae01176 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/ArmWeight.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/ArmWeight.java @@ -5,13 +5,13 @@ import cmu.xprize.robotutor.tutorengine.graph.vars.IScope2; -public class ArmWeight { +public class Arm { public String name; public Float weight; public String matrix; - public ArmWeight(JSONObject jsonObject, IScope2 scope) { + public Arm(JSONObject jsonObject, IScope2 scope) { try { loadJSON(jsonObject); } catch (Exception e) { @@ -27,7 +27,7 @@ public void loadJSON(JSONObject jsonObj) throws JSONException { @Override public String toString() { - return "ArmWeight{" + + return "Arm{" + "name='" + name + '\'' + ", weight=" + weight + ", matrix='" + matrix + '\'' + From f0e3dff763ecb05388438811c60bd5848005aa8b Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:41:21 -0500 Subject: [PATCH 16/17] Update MABHandler.java ArmWeight is now Arm armWeights is now arms armWeight is now arm public class Arm { public String name; public Float weight; public String matrix; ... --- .../tutorengine/util/MABHandler.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index fa125460d..c829bd100 100644 --- a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java +++ b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java @@ -31,17 +31,17 @@ public class MABHandler { private static final String TAG = "MABHandler"; public static String getArm(String dataSource, IScope2 scope) { - List armWeights = getArmWeights(dataSource, scope); - ArmWeight selectedArm = selectArm(armWeights); - Log.d(TAG, "getArm: list = "+armWeights); - Log.d(TAG, "getArm: selected = "+selectedArm); + List 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 armWeights) { + private static Arm selectArm(List arms) { float sum = 0; - for (ArmWeight arm : armWeights) { + for (Arm arm : arms) { sum += arm.weight; } @@ -50,7 +50,7 @@ private static ArmWeight selectArm(List 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; @@ -66,30 +66,34 @@ private static float getRandom(float min, float max) { } - private static List getArmWeights(String dataSource, IScope2 scope) { + private static List getarms(String dataSource, IScope2 scope) { String jsonData = JSON_Helper.cacheData(dataSource); - List armWeights = new ArrayList<>(); + List 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 parseArray(JSONArray array, IScope2 scope) throws JSONException { - List armWeights = new ArrayList<>(); + private static List parseArray(JSONArray array, IScope2 scope) throws JSONException { + List 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; } From 029afca812e0c1a4c319c552f12e24f78b1b6c6f Mon Sep 17 00:00:00 2001 From: g-revanth <97725168+g-revanth@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:45:09 -0500 Subject: [PATCH 17/17] Rename ArmWeight.java to Arm.java Filename to match with the class name --- .../robotutor/tutorengine/util/{ArmWeight.java => Arm.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/cmu/xprize/robotutor/tutorengine/util/{ArmWeight.java => Arm.java} (100%) diff --git a/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/ArmWeight.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/Arm.java similarity index 100% rename from app/src/main/java/cmu/xprize/robotutor/tutorengine/util/ArmWeight.java rename to app/src/main/java/cmu/xprize/robotutor/tutorengine/util/Arm.java