/// <summary> /// Loads the user's progress of each case (UserCaseProgress objects) back in from file. /// </summary> public static void LoadCaseProgress() { // create list of UserCaseProgress objects List <UserCaseProgress> myList = new List <UserCaseProgress>(); string jsonText; try // attempt to read in previously saved JSON data { // find application data path unique to the device platform string path = Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData); string filename = Path.Combine(path, JSON_CASE_PROGRESS_FILENAME); using (var reader = new StreamReader(filename)) { // read json data jsonText = reader.ReadToEnd(); } // parse JSON into a list of UserCaseProgress objects myList = JsonConvert.DeserializeObject <List <UserCaseProgress> >(jsonText); } catch // no JSON data was saved previously, generate defaults { // generate defaults for the 57 OLL cases for (int i = 1; i <= 57; i++) { // create UserCaseProgress object UserCaseProgress caseProgress = new UserCaseProgress(); // default values caseProgress.CaseNumber = i; caseProgress.CaseCompetence = 0; caseProgress.IsTraining = false; caseProgress.IsLearned = false; myList.Add(caseProgress); } // save the list immediately to file SaveCaseProgress(myList); } // load the list into a global variable for use across multiple pages GlobalVariables.CaseProgress = myList; }
/// <summary> /// Update the case competence value for the currently trained case after the user /// has specified how good their reaction time was. /// </summary> /// <param name="reactionBracket">The user's reaction time, corresponding to the target values in GlobalVariables.ProgressCalcVars.TARGETS</param> private void ApplyCaseProgress(int reactionBracket) { // find the UserCaseProgres object for the case that is currently being trained UserCaseProgress caseProgress = GlobalVariables.CaseProgress[currentCase.CaseNumber - 1]; // find the corresponding target value based on the reaction time button the user clicked double target = GlobalVariables.ProgressCalcVars.TARGETS[reactionBracket]; // move the current competence value towards the target value, based on the PROGRESS_RATE double currentComp = caseProgress.CaseCompetence; double compIncrease = (target - currentComp) * GlobalVariables.ProgressCalcVars.PROGRESS_RATE; double newComp = currentComp + compIncrease; // update the case's competence with the new value caseProgress.CaseCompetence = newComp; // save all case progress to a JSON file MyUtils.SaveCaseProgress(GlobalVariables.CaseProgress); }