/// <summary> /// This method returns a <see cref="TrialCollection"/> of all trials contained /// in this slideshow. /// </summary> /// <returns>A <see cref="TrialCollection"/> of all trials contained /// in this slideshow.</returns> private TrialCollection GetTrials() { TrialCollection trials = new TrialCollection(); this.ParseNodeForTrials(ref trials, this); return(trials); }
/// <summary> /// Initializes a new instance of the TrialCollection class. /// Clone constructor /// </summary> /// <param name="cloneCollection">A <see cref="TrialCollection"/> to be cloned</param> public TrialCollection(TrialCollection cloneCollection) { foreach (Trial trial in cloneCollection) { this.Add((Trial)trial.Clone()); } }
/// <summary> /// Returns the current <see cref="TrialCollection"/> that was randomized /// according to the shuffling settings defined. /// </summary> /// <returns>The current <see cref="TrialCollection"/> that was randomized /// according to the shuffling settings defined.</returns> public TrialCollection GetRandomizedTrials() { List <object> nodeCollection = this.ParseNodeForRandomizedTrials(this); var trials = new TrialCollection(); this.GetTrialsFromObjectCollection(nodeCollection, ref trials); this.InsertPreSlideTrials(ref trials); return(trials); }
/// <summary> /// This method iterates the given shuffled object collection recursively /// to return the one dimensional <see cref="TrialCollection"/> that is used /// during presentation. /// </summary> /// <param name="collection">A <see cref="List{Object}"/> with the shuffled trials separated in /// shuffle groups.</param> /// <param name="trials">Ref. The output <see cref="TrialCollection"/>.</param> private void GetTrialsFromObjectCollection(List <object> collection, ref TrialCollection trials) { foreach (object item in collection) { if (item is Trial) { Trial trial = item as Trial; trials.Add(trial); } else if (item is List <object> ) { this.GetTrialsFromObjectCollection((List <object>)item, ref trials); } } }
/// <summary> /// This method iterates recursively through the tree to return only the trials /// contained in the tree. /// </summary> /// <param name="trials">Ref. The output <see cref="TrialCollection"/> of trials.</param> /// <param name="node">The <see cref="TreeNode"/> to parse.</param> private void ParseNodeForTrials(ref TrialCollection trials, TreeNode node) { Trial trial = null; // Add trial if this node is marked to be a trial if (node.Tag != null && node.Tag.ToString() == "Trial") { trial = new Trial(node.Text, GetIdOfNode(node)); trials.Add(trial); } foreach (TreeNode subNode in node.Nodes) { SlideshowTreeNode subSlideNode = subNode as SlideshowTreeNode; Slide slide = subSlideNode.Slide; if (slide != null) { // By default use a new trial for each slide trial = new Trial(subNode.Text, GetIdOfNode(subNode)); // If parent is already marked as trial use this // instead. if (subNode.Parent != null && subNode.Parent.Tag != null && subNode.Parent.Tag.ToString() == "Trial") { trial = trials[trials.Count - 1]; } // Add slide to correct trial trial.Add(slide); } // Iterate through the tree. this.ParseNodeForTrials(ref trials, subNode); // If a trial was found, add it to the list. if (trial != null && !trials.Contains(trial)) { trials.Add(trial); } } }
/// <summary> /// Inserts the pre slide trials. /// </summary> /// <param name="trials">The trials.</param> private void InsertPreSlideTrials(ref TrialCollection trials) { var trialsWithPreSlideTrials = new TrialCollection(); foreach (var trial in trials) { foreach (var slideobject in trial) { // if we have a preslide fixation trial add this trial before var preSlideTrialID = slideobject.IdOfPreSlideFixationTrial; if (preSlideTrialID != -1) { var preSlideNode = this.GetNodeByID(preSlideTrialID); var preTrial = new Trial(preSlideNode.Text, preSlideTrialID); preTrial.AddRange(this.GetPreSlideTrialSlides(preSlideNode)); trialsWithPreSlideTrials.Add(preTrial); } } trialsWithPreSlideTrials.Add(trial); } trials = trialsWithPreSlideTrials; }
/// <summary> /// This method iterates recursively through the tree to return a /// shuffled trial collection using the <see cref="CustomShuffling"/>. /// </summary> /// <param name="node">The <see cref="TreeNode"/> to parse.</param> /// <returns>A <see cref="List{Object}"/> with the shuffled trials separated in /// shuffle groups.</returns> private List <object> ParseNodeForCustomShuffledTrials(TreeNode node) { // Get sections var sections = new List <object>(); foreach (TreeNode subNode in node.Nodes) { var nodeCollection = this.ParseNodeForRandomizedTrials(subNode); var trials = new TrialCollection(); this.GetTrialsFromObjectCollection(nodeCollection, ref trials); this.InsertPreSlideTrials(ref trials); // Convert to List<object> var trialsObjectCollection = new List <object>(); trialsObjectCollection.AddRange(trials.ToArray()); // Shuffle sections if applicable if (this.shuffling.ShuffleSectionItems) { trialsObjectCollection = (List <object>) CollectionUtils <object> .Shuffle(trialsObjectCollection); } sections.Add(trialsObjectCollection); } // Create groups var groups = new List <object>(); int index = 0; var finish = false; do { var group = new List <object>(); for (int i = 0; i < sections.Count; i++) { var coll = (List <object>)sections[i]; if (coll.Count == index) { finish = true; break; } for (int j = 0; j < this.shuffling.NumItemsOfSectionInGroup; j++) { group.Add(coll[index + j]); } } if (this.shuffling.ShuffleGroupItems) { group = (List <object>) CollectionUtils <object> .Shuffle(group); } if (!finish) { groups.Add(group); } index += this.shuffling.NumItemsOfSectionInGroup; }while (!finish); // Shuffle groups if (this.shuffling.ShuffleGroups) { groups = (List <object>) CollectionUtils <object> .Shuffle(groups); } return(groups); }