Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        /// <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();
        }
Ejemplo n.º 3
0
        public override void InitializePhaseFromParameters(List <Tuple <string, string> > parameters, int loop_counter = 0)
        {
            for (int i = 0; i < parameters.Count; i++)
            {
                var pname = parameters[i].Item1;
                var pval  = parameters[i].Item2;
                var pval_is_loop_param = pval.Equals("n");
                var pval_parse_success = Int32.TryParse(pval, out int pval_parse_result);

                if (pname.Equals("text"))
                {
                    TextSourceFileName = pval;
                    var full_path_to_file = HumanAcceleratedLearningConfiguration.GetInstance().ResourcesFolder +
                                            HumanAcceleratedLearningConfiguration.GetInstance().InstructionsPath + @"\" + TextSourceFileName;
                    if (File.Exists(full_path_to_file))
                    {
                        Text = File.ReadAllText(full_path_to_file);
                    }
                }
                else if (pname.Equals("duration"))
                {
                    Duration = (pval_is_loop_param) ? loop_counter : (pval_parse_success) ? pval_parse_result : 0;
                }
            }
        }
Ejemplo n.º 4
0
        public static bool CheckIfObjectLocationFileExists(string username)
        {
            string        fully_qualified_path = HumanAcceleratedLearningConfiguration.GetInstance().PrimarySavePath + username + @"\";
            DirectoryInfo dir_info             = new DirectoryInfo(fully_qualified_path);

            if (dir_info.Exists)
            {
                var files = dir_info.EnumerateFiles();
                var f     = files.Where(x => x.Name.Contains("objectlocation")).FirstOrDefault();
                return(f != null);
            }

            return(false);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks to see if a patient already exists with a certain username
        /// </summary>
        public static bool DoesSubjectExist(string username)
        {
            bool does_exist = false;

            //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);

            does_exist = info.Exists;

            return(does_exist);
        }
        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;
                }
            }
        }
Ejemplo n.º 8
0
        private void UpdateSegmentNames()
        {
            Stage s            = HumanAcceleratedLearningConfiguration.GetInstance().Stages[_model.SelectedStageIndex];
            var   segment_list = s.StageSegments.Select(x => x.SegmentName).ToList();

            //Remove the "collection changed" event handler temporarily
            _segment_list.CollectionChanged -= HandleDragDrop_CollectionChanged;

            //Clear the list and add items for the new stage
            _segment_list.Clear();
            foreach (var seg in segment_list)
            {
                _segment_list.Add(seg);
            }

            //Re-add the event handler
            _segment_list.CollectionChanged += HandleDragDrop_CollectionChanged;
        }
Ejemplo n.º 9
0
        public static StreamReader OpenObjectLocationFileForReading(string username)
        {
            string        fully_qualified_path = HumanAcceleratedLearningConfiguration.GetInstance().PrimarySavePath + username + @"\";
            DirectoryInfo dir_info             = new DirectoryInfo(fully_qualified_path);

            if (dir_info.Exists)
            {
                var files = dir_info.EnumerateFiles();
                var f     = files.Where(x => x.Name.Contains("objectlocation")).FirstOrDefault();
                if (f != null)
                {
                    StreamReader fid = new StreamReader(f.FullName);
                    return(fid);
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a study block file for the specified username
        /// </summary>
        public static StreamWriter CreateObjectLocationFileForWriting(string username)
        {
            string date_for_filename = DateTime.Now.ToString("yyyyMMdd_HHmmss");
            string file_name         = username + "_objectlocation_" + date_for_filename + ".txt";

            string        fully_qualified_path = HumanAcceleratedLearningConfiguration.GetInstance().PrimarySavePath + username + @"\";
            DirectoryInfo dir_info             = new DirectoryInfo(fully_qualified_path);

            if (!dir_info.Exists)
            {
                dir_info.Create();
            }

            string fully_qualified_file = fully_qualified_path + file_name;

            StreamWriter writer = new StreamWriter(fully_qualified_file);

            return(writer);
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        private void HandleDragDrop_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            //Get the ordered list of segment names according to how the user wants to order them
            var seg_names = _segment_list.ToList();

            //Get the current stage
            Stage s = HumanAcceleratedLearningConfiguration.GetInstance().Stages[_model.SelectedStageIndex];

            if (seg_names.Count == s.StageSegments.Count)
            {
                List <StageSegment> new_stage_segment_list = new List <StageSegment>();
                foreach (var this_seg_name in seg_names)
                {
                    var this_seg = s.StageSegments.Where(x => x.SegmentName.Equals(this_seg_name)).FirstOrDefault();
                    if (this_seg != null)
                    {
                        new_stage_segment_list.Add(this_seg);
                    }
                }

                s.StageSegments = new_stage_segment_list;
            }
        }