public override void Start(HumanSubject current_subject = null) { if (current_subject != null) { //Get the list of words to use for this study block var hal_config = HumanAcceleratedLearningConfiguration.GetInstance(); var available_dictionaries = hal_config.LanguageDictionaries; source_language_dictionary = available_dictionaries.Where(x => x.ForeignLanguageName.Equals(ForeignLanguage) && x.NativeLanguageName.Equals(NativeLanguage) ).FirstOrDefault(); //Shuffle the words if (source_language_dictionary != null) { var word_list = source_language_dictionary.DictionaryWordPairs.ToList(); shuffled_word_list = MathHelperMethods.ShuffleList(word_list); last_word_display_time = DateTime.MinValue; current_wordpair_index = 0; //Create a file for this study session fid = StudyBlock.CreateStudyBlockFile(current_subject.UserName); HasPhaseStarted = true; } } }
/// <summary> /// Saves a human subject to a data file /// </summary> /// <param name="s"></param> public static void SaveHumanSubject(HumanSubject s) { //Construct a file name for the patient data file string file_name = s.UserName + ".txt"; //Construct a path for the save location string path_name = HumanAcceleratedLearningConfiguration.GetInstance().PrimarySavePath; //Create the directory if it doesn't exist DirectoryInfo info = new DirectoryInfo(path_name); if (!info.Exists) { info.Create(); } //Open the file for writing string full_path_and_file = path_name + file_name; StreamWriter writer = new StreamWriter(full_path_and_file); writer.WriteLine(s.UserName); writer.WriteLine(MathHelperMethods.ConvertDateTimeToMatlabDatenum(s.StartDate).ToString()); //Write out the names of each segment in the order that they were performed in the participant's first visit foreach (var seg in s.FirstVisitStage.StageSegments) { writer.WriteLine(seg.SegmentName); } //Close the file writer.Close(); }
public static void ReadObjectLocationFile(HumanSubject s) { if (CheckIfObjectLocationFileExists(s.UserName)) { var file_name = GetNameOfObjectLocationFile(s.UserName); if (!string.IsNullOrEmpty(file_name)) { var file_lines = Helpers.ConfigurationFileLoader.LoadFileLines(file_name); foreach (var l in file_lines) { string [] line_parts = l.Split(new char[] { ',' }); if (line_parts.Length == 3) { string img_name = line_parts[0].Trim(); bool xpos_success = Int32.TryParse(line_parts[1], out int xpos); bool ypos_success = Int32.TryParse(line_parts[2], out int ypos); if (xpos_success && ypos_success) { s.AllObjectImages.Add(img_name); s.AllObjectImageLocations.Add(new Tuple <int, int>(xpos, ypos)); } } } } } }
public static void WriteAllObjectLocationsToFile(HumanSubject s) { var fid = CreateObjectLocationFileForWriting(s.UserName); for (int i = 0; i < s.AllObjectImages.Count; i++) { WriteObjectLocationTrial(fid, s.AllObjectImages[i], s.AllObjectImageLocations[i].Item1, s.AllObjectImageLocations[i].Item2); } fid.Close(); }
/// <summary> /// Creates an object for a new human subject /// </summary> public static HumanSubject CreateNewSubjectData(string username, Stage first_visit_stage) { HumanSubject result = new HumanSubject(); var configuration_data = HumanAcceleratedLearningConfiguration.GetInstance(); result.UserName = username; result.StartDate = DateTime.Now; result.FirstVisitStage = first_visit_stage; foreach (var seg in first_visit_stage.StageSegments) { result.SegmentOrder.Add(seg.SegmentName); } return(result); }
public override void Start(HumanSubject current_subject = null) { if (current_subject != null) { current_subject_obj = current_subject; //Get the list of words to use for this test block var hal_config = HumanAcceleratedLearningConfiguration.GetInstance(); source_language_dictionary = hal_config.LanguageDictionaries.Where(x => (x.ForeignLanguageName.Equals(ForeignLanguage) && x.NativeLanguageName.Equals(NativeLanguage)) ).FirstOrDefault(); //Get the list of words that this participant has already gotten correct in previous test blocks current_subject.MakeSureCorrectlyAnsweredWordListExistsForSubject(ForeignLanguage); if (source_language_dictionary != null) { var correct_word_list = current_subject.CorrectlyAnsweredWordList[ForeignLanguage]; var all_word_pairs = source_language_dictionary.DictionaryWordPairs.ToList(); var ordered_foreign_language_Words = all_word_pairs.Select(x => x.Item1).ToList(); //Remove the words from the list of word pairs that have already been answered correctly for (int i = 0; i < correct_word_list.Count; i++) { int index = ordered_foreign_language_Words.IndexOf(correct_word_list[i]); if (index > -1) { ordered_foreign_language_Words.RemoveAt(index); all_word_pairs.RemoveAt(index); } } //Shuffle the remaining words shuffled_word_list = MathHelperMethods.ShuffleList(all_word_pairs); last_word_display_time = DateTime.MinValue; test_start_time = DateTime.Now; current_wordpair_index = 0; //Create a file for this test session fid = TestBlock.CreateTestBlockFile(current_subject.UserName); HasPhaseStarted = true; } } }
private void RunSession(object sender, DoWorkEventArgs e) { //Select the stage we want to run Stage selected_stage = HumanAcceleratedLearningConfiguration.GetInstance().Stages[SelectedStageIndex]; //Create a new human subject with this username, or load in the subject's data. if (!HumanSubject.DoesSubjectExist(UserName)) { //If this is a new subject... //Create an object holding the data for this human subject CurrentSubject = HumanSubject.CreateNewSubjectData(_username, selected_stage); //Save the data to a file HumanSubject.SaveHumanSubject(CurrentSubject); } else { //If this is an existing subject, load the subject's data from a file CurrentSubject = HumanSubject.LoadHumanSubject(UserName); } //Set a flag indicating we are not done yet bool done = false; //Loop until the program is either cancelled or we are done while (!done) { //Handle the current state of the session done = HandleSessionState(selected_stage); //If the user wants to close down the program or cancel the session, set the flag indicating we are done if (_background_thread.CancellationPending) { done = true; } //Report progress of the background thread _background_thread.ReportProgress(0); //Sleep the background thread a little bit so we don't consume the entire CPU Thread.Sleep(33); } }
/// <summary> /// Loads data from a previously created human subject. /// </summary> public static HumanSubject LoadHumanSubject(string username) { HumanSubject s = new HumanSubject(); //Construct a file name to load string file_name = username + ".txt"; //Construct a full path and file string fully_qualified_path = HumanAcceleratedLearningConfiguration.GetInstance().PrimarySavePath + file_name; //Check to see if the patient data file exists FileInfo info = new FileInfo(fully_qualified_path); //If the patient data file exists... if (info.Exists) { //Read the contents of the file List <string> lines = ConfigurationFileLoader.LoadFileLines(fully_qualified_path); //Read the user name s.UserName = lines[0].Trim(); //Read the participant's start date double matlab_datenum = 0; bool success = Double.TryParse(lines[1], out matlab_datenum); if (success) { s.StartDate = MathHelperMethods.ConvertMatlabDatenumToDateTime(matlab_datenum); } //Now read the order of the participant's segments for (int i = 2; i < lines.Count; i++) { s.SegmentOrder.Add(lines[i].Trim()); } } return(s); }
public override void Start(HumanSubject current_subject = null) { if (current_subject != null) { _current_subject = current_subject; if (current_subject.AllObjectImages.Count == 0 && current_subject.AllObjectImageLocations.Count == 0) { var res_folder = HumanAcceleratedLearningConfiguration.GetInstance().ResourcesFolder; var img_path = HumanAcceleratedLearningConfiguration.GetInstance().ObjectLocationImagesPath; var all_images = Directory.GetFiles(res_folder + img_path).ToList(); current_subject.AllObjectImages = all_images; last_picture_display_time = DateTime.MinValue; current_image_index = 0; for (int i = 0; i < all_images.Count; i++) { var loc_x = MathHelperMethods.RandomNumbers.Next(1, Convert.ToInt32(grid_columns) - 1); var loc_y = MathHelperMethods.RandomNumbers.Next(1, Convert.ToInt32(grid_rows) - 1); current_subject.AllObjectImageLocations.Add(new Tuple <int, int>(loc_x, loc_y)); } //Save all of the object locations to a file ObjectLocation_FileHandler.WriteAllObjectLocationsToFile(current_subject); } //Create a shuffled list of image indices for this study session var all_indices = Enumerable.Range(0, current_subject.AllObjectImages.Count).ToList(); shuffled_list_of_image_indices = MathHelperMethods.ShuffleList(all_indices); //Create a file for this study session fid = StudyBlock.CreateStudyBlockFile(current_subject.UserName); HasPhaseStarted = true; StartTime = DateTime.Now; } }
public override void Start(HumanSubject current_subject = null) { if (current_subject != null) { _current_subject = current_subject; last_picture_display_time = DateTime.MinValue; current_image_index = 0; if (current_subject.AllObjectImages.Count == 0) { ObjectLocation_FileHandler.ReadObjectLocationFile(current_subject); /*var res_folder = HumanAcceleratedLearningConfiguration.GetInstance().ResourcesFolder; * var img_path = HumanAcceleratedLearningConfiguration.GetInstance().ObjectLocationImagesPath; * var all_images = Directory.GetFiles(res_folder + img_path).ToList(); * * current_subject.AllObjectImages = all_images;*/ } if (current_subject.AllObjectImages.Count > 0) { //Remove images that have already been correctly answered usable_images = current_subject.AllObjectImages.Where((y, x) => !current_subject.CorrectlyAnsweredImageList.Contains(x)).ToList(); usable_image_positions = current_subject.AllObjectImageLocations.Where((y, x) => !current_subject.CorrectlyAnsweredImageList.Contains(x)).ToList(); //Create a shuffled list of image indices for this study session var all_indices = Enumerable.Range(0, usable_images.Count).ToList(); shuffled_list_of_image_indices = MathHelperMethods.ShuffleList(all_indices); //Create a file for this study session fid = TestBlock.CreateTestBlockFile(current_subject.UserName); HasPhaseStarted = true; StartTime = DateTime.Now; } } }
public virtual void Start(HumanSubject current_subject = null) { StartTime = DateTime.Now; HasPhaseStarted = true; }