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..011522e22 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 @@ -815,7 +817,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,24 +825,35 @@ 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 + + loadTranslationTable(Activity.getApplicationContext()); + System.out.println("translationTable : " + translationTable); + + String oldActivity = "write.missingLtr:lc.begin.ka.2"; + String nextActivity = getTranslatedActivityID(oldActivity); - HashMap h2 = loadTranslationTable(Activity.getApplicationContext()); - System.out.println("h2 : " + h2); + System.out.println("Translated activity: " + nextActivity); return matrix; } + + 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."); } @@ -860,8 +873,13 @@ public void loadJSON(JSONObject jsonObj, IScope scope) { loadJSON(jsonObj, (IScope2) scope); } - public static HashMap loadTranslationTable(Context context) { - HashMap hm = new HashMap<>(); + + public static String getTranslatedActivityID(String oldActivityID){ + return translationTable.get(oldActivityID); + } + + + static void loadTranslationTable(Context context) { try { //csv file containing data @@ -871,21 +889,37 @@ 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; + + //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(); - //read comma-separated file line by line + // 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 a = st.nextToken(); - tokenNumber+=2; - String b = st.nextToken(); - hm.put(a, b); + // 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 + st.nextToken(); // Skipping 2nd token + st.nextToken(); // Skipping 3rd token + + String nextActivity = st.nextToken(); // 4th token + // Skip the next two tokens + 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) { @@ -894,10 +928,9 @@ public static HashMap loadTranslationTable(Context context) { e.printStackTrace(); } - return hm; + System.out.println("translationTable : " + translationTable); } - } 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 87% 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 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/Arm.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 + '\'' + 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/MABHandler.java b/app/src/main/java/cmu/xprize/robotutor/tutorengine/util/MABHandler.java index 12fb0092d..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,27 +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.d(TAG, "getArmWeights: "+e); + 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; } 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..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,14 +157,20 @@ 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; } + @Override public String getDebugMenuSkill() { return _student.getActiveSkill();