Example #1
0
        private TransitionParameters XMLReadTransitionParameters(XmlElement xmlTransitionParameters)
        {
            TransitionParameters tp = new TransitionParameters();
            string transitionType   = xmlTransitionParameters.GetAttribute("type");

            switch (transitionType)
            {
            case "velocity":
                tp.transitionType    = TransitionType.Velocity;
                tp.velocityDuration  = Convert.ToInt32(((XmlElement)xmlTransitionParameters.GetElementsByTagName("duration")[0]).InnerText);
                tp.velocityThreshold = Convert.ToDouble(((XmlElement)xmlTransitionParameters.GetElementsByTagName("threshold")[0]).InnerText);
                if (((XmlElement)xmlTransitionParameters.GetElementsByTagName("thresholdComparison")[0]).InnerText == "lower")
                {
                    tp.lowerThan = true;
                }
                else
                {
                    tp.lowerThan = false;
                }
                break;

            case "duration":
                tp.transitionType = TransitionType.Frame;
                tp.frameDuration  = Convert.ToInt32(((XmlElement)xmlTransitionParameters.GetElementsByTagName("duration")[0]).InnerText);
                break;
            }

            return(tp);
        }
Example #2
0
        // Helper functions for getting information from GUI elements
        private Trial GetGUITrial()
        {
            Trial trial             = new Trial(trial_name.Text);
            TransitionParameters tp = GetTransitionParameters();
            RewardParameters     rp = GetRewardParameters();

            Stimulus leftStimulus  = GetLeftStimulus();
            Stimulus rightStimulus = GetRightStimulus();

            trial.SetBlockPresentations(Convert.ToInt32(block_presentations.Value));
            trial.SetRewardParameters(rp);
            trial.SetTransitionParameters(tp);
            trial.SetStimulus(leftStimulus, rightStimulus);
            return(trial);
        }
Example #3
0
 private void SetTransitionParameters(TransitionParameters tp)
 {
     if (tp.transitionType == TransitionType.Frame)
     {
         transition_frame.Checked        = true;
         transition_frame_duration.Value = tp.frameDuration;
     }
     else
     {
         transition_velocity.Checked = true;
         transition_velocity_comparison.SelectedIndex = Convert.ToInt32(tp.lowerThan);
         transition_velocity_duration.Value           = tp.velocityDuration;
         transition_velocity_threshold.Value          = Convert.ToDecimal(tp.velocityThreshold);
     }
 }
Example #4
0
        private TransitionParameters GetTransitionParameters()
        {
            TransitionParameters tp = new TransitionParameters();

            if (transition_frame.Checked)
            {
                tp.transitionType = TransitionType.Frame;
                tp.frameDuration  = Convert.ToInt32(transition_frame_duration.Value);
            }
            else
            {
                tp.transitionType    = TransitionType.Velocity;
                tp.lowerThan         = (transition_velocity_comparison.SelectedIndex == 1);
                tp.velocityThreshold = Convert.ToDouble(transition_velocity_threshold.Value);
                tp.velocityDuration  = Convert.ToInt32(transition_velocity_duration.Value);
            }
            return(tp);
        }
Example #5
0
        public void XMLWriteTransitionParameters(XmlWriter xmlWriter, TransitionParameters tp)
        {
            xmlWriter.WriteStartElement("transition");
            switch (tp.transitionType)
            {
            case TransitionType.Frame:
                xmlWriter.WriteAttributeString("type", "duration");
                xmlWriter.WriteStartElement("duration");
                xmlWriter.WriteString(tp.frameDuration.ToString());
                xmlWriter.WriteEndElement();
                break;

            case TransitionType.Velocity:
                xmlWriter.WriteAttributeString("type", "velocity");
                xmlWriter.WriteStartElement("threshold");
                xmlWriter.WriteString(tp.velocityThreshold.ToString());
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("duration");
                xmlWriter.WriteString(tp.velocityDuration.ToString());
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("thresholdComparison");
                if (tp.lowerThan)
                {
                    xmlWriter.WriteString("lower");
                }
                else
                {
                    xmlWriter.WriteString("higher");
                }
                xmlWriter.WriteEndElement();
                break;
            }
            xmlWriter.WriteEndElement();
        }
Example #6
0
 public void SetTransitionParameters(TransitionParameters t)
 {
     this.tp = t;
 }
Example #7
0
        public void LoadConfiguration(string filename)
        {
            Trial  trial;
            string isiTrialName = "";
            Dictionary <string, Trial> newDictionary = new Dictionary <string, Trial>();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);
            XmlNodeList trialList = xmlDoc.GetElementsByTagName("trial");

            foreach (XmlNode xmlNode in trialList)
            {
                bool                 isi;
                string               trialName;
                int                  blockPresentations;
                RewardParameters     rp    = new RewardParameters();
                TransitionParameters tp    = new TransitionParameters();
                Stimulus             left  = new Stimulus();
                Stimulus             right = new Stimulus();


                // General trial info
                XmlElement trialElement = xmlNode as XmlElement;
                XmlElement xTrialName   = (XmlElement)trialElement.GetElementsByTagName("name")[0];
                trialName = ((XmlElement)trialElement.GetElementsByTagName("name")[0]).InnerText;
                if (((XmlElement)trialElement.GetElementsByTagName("isi")[0]).InnerText == "true")
                {
                    isi          = true;
                    isiTrialName = trialName;
                }
                else
                {
                    isi = false;
                }
                blockPresentations = Convert.ToInt32(((XmlElement)trialElement.GetElementsByTagName("blockPresentations")[0]).InnerText);

                // Reward parameters
                XmlElement xRewardParameters = (XmlElement)trialElement.GetElementsByTagName("reward")[0];
                rp = XMLReadRewardParameters(xRewardParameters);

                // Transition parameters
                XmlElement xTransitionParameters = (XmlElement)trialElement.GetElementsByTagName("transition")[0];
                tp = XMLReadTransitionParameters(xTransitionParameters);

                // Stimulus parameters
                XmlNodeList xNodes   = trialElement.GetElementsByTagName("stimulus");
                XmlElement  stimulus = (XmlElement)(trialElement.GetElementsByTagName("stimulus")[0]);
                if (stimulus.GetAttribute("screen") == "left")
                {
                    left = XMLReadStimulusParameters(stimulus);
                }
                else
                {
                    right = XMLReadStimulusParameters(stimulus);
                }

                stimulus = (XmlElement)(trialElement.GetElementsByTagName("stimulus")[1]);
                if (stimulus.GetAttribute("screen") == "right")
                {
                    right = XMLReadStimulusParameters(stimulus);
                }
                else
                {
                    left = XMLReadStimulusParameters(stimulus);
                }

                trial = new Trial(trialName);
                trial.SetISI(isi);
                trial.SetRewardParameters(rp);
                trial.SetTransitionParameters(tp);
                trial.SetStimulus(left, right);
                trial.SetBlockPresentations(blockPresentations);
                newDictionary.Add(trialName, trial);
            }
            int blockCount = Convert.ToInt32(xmlDoc.GetElementsByTagName("blocks")[0].FirstChild.InnerText);

            this.trialDictionary = new Dictionary <string, Trial>(newDictionary);
            this.blockCount      = blockCount;
            this.isiTrialName    = isiTrialName;
            currentFileName      = filename;
        }
Example #8
0
 private TransitionParameters GetTransitionParameters()
 {
     TransitionParameters tp = new TransitionParameters();
     if (transition_frame.Checked)
     {
         tp.transitionType = TransitionType.Frame;
         tp.frameDuration = Convert.ToInt32(transition_frame_duration.Value);
     }
     else
     {
         tp.transitionType = TransitionType.Velocity;
         tp.lowerThan = (transition_velocity_comparison.SelectedIndex == 1);
         tp.velocityThreshold = Convert.ToDouble(transition_velocity_threshold.Value);
         tp.velocityDuration = Convert.ToInt32(transition_velocity_duration.Value);
     }
     return tp;
 }
Example #9
0
 private void SetTransitionParameters(TransitionParameters tp)
 {
     if (tp.transitionType == TransitionType.Frame)
     {
         transition_frame.Checked = true;
         transition_frame_duration.Value = tp.frameDuration;
     }
     else
     {
         transition_velocity.Checked = true;
         transition_velocity_comparison.SelectedIndex = Convert.ToInt32(tp.lowerThan);
         transition_velocity_duration.Value = tp.velocityDuration;
         transition_velocity_threshold.Value = Convert.ToDecimal(tp.velocityThreshold);
     }
 }
Example #10
0
 public void SetTransitionParameters(TransitionParameters t)
 { this.tp = t; }
        private TransitionParameters XMLReadTransitionParameters(XmlElement xmlTransitionParameters)
        {
            TransitionParameters tp = new TransitionParameters();
            string transitionType = xmlTransitionParameters.GetAttribute("type");

            switch (transitionType)
            {
                case "velocity":
                    tp.transitionType = TransitionType.Velocity;
                    tp.velocityDuration = Convert.ToInt32(((XmlElement)xmlTransitionParameters.GetElementsByTagName("duration")[0]).InnerText);
                    tp.velocityThreshold = Convert.ToDouble(((XmlElement)xmlTransitionParameters.GetElementsByTagName("threshold")[0]).InnerText);
                    if (((XmlElement)xmlTransitionParameters.GetElementsByTagName("thresholdComparison")[0]).InnerText == "lower")
                        tp.lowerThan = true;
                    else
                        tp.lowerThan = false;
                    break;
                case "duration":
                    tp.transitionType = TransitionType.Frame;
                    tp.frameDuration = Convert.ToInt32(((XmlElement)xmlTransitionParameters.GetElementsByTagName("duration")[0]).InnerText);
                    break;
            }

            return tp;
        }
        public void XMLWriteTransitionParameters(XmlWriter xmlWriter, TransitionParameters tp)
        {
            xmlWriter.WriteStartElement("transition");
            switch (tp.transitionType)
            {
                case TransitionType.Frame:
                    xmlWriter.WriteAttributeString("type", "duration");
                    xmlWriter.WriteStartElement("duration");
                    xmlWriter.WriteString(tp.frameDuration.ToString());
                    xmlWriter.WriteEndElement();
                    break;
                case TransitionType.Velocity:
                    xmlWriter.WriteAttributeString("type", "velocity");
                    xmlWriter.WriteStartElement("threshold");
                    xmlWriter.WriteString(tp.velocityThreshold.ToString());
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("duration");
                    xmlWriter.WriteString(tp.velocityDuration.ToString());
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("thresholdComparison");
                    if (tp.lowerThan)
                        xmlWriter.WriteString("lower");
                    else
                        xmlWriter.WriteString("higher");
                    xmlWriter.WriteEndElement();
                    break;
            }
            xmlWriter.WriteEndElement();
        }
        public void LoadConfiguration(string filename)
        {
            Trial trial;
            string isiTrialName = "";
            Dictionary<string, Trial> newDictionary = new Dictionary<string, Trial>();

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(filename);
            XmlNodeList trialList = xmlDoc.GetElementsByTagName("trial");
            foreach (XmlNode xmlNode in trialList)
            {
                bool isi;
                string trialName;
                int blockPresentations;
                RewardParameters rp = new RewardParameters();
                TransitionParameters tp = new TransitionParameters();
                Stimulus left = new Stimulus();
                Stimulus right = new Stimulus();


                // General trial info
                XmlElement trialElement = xmlNode as XmlElement;
                XmlElement xTrialName = (XmlElement)trialElement.GetElementsByTagName("name")[0];
                trialName = ((XmlElement)trialElement.GetElementsByTagName("name")[0]).InnerText;
                if (((XmlElement)trialElement.GetElementsByTagName("isi")[0]).InnerText == "true")
                {
                    isi = true;
                    isiTrialName = trialName;
                }
                else
                    isi = false;
                blockPresentations = Convert.ToInt32(((XmlElement)trialElement.GetElementsByTagName("blockPresentations")[0]).InnerText);

                // Reward parameters
                XmlElement xRewardParameters = (XmlElement)trialElement.GetElementsByTagName("reward")[0];
                rp = XMLReadRewardParameters(xRewardParameters);

                // Transition parameters
                XmlElement xTransitionParameters = (XmlElement)trialElement.GetElementsByTagName("transition")[0];
                tp = XMLReadTransitionParameters(xTransitionParameters);

                // Stimulus parameters
                XmlNodeList xNodes = trialElement.GetElementsByTagName("stimulus");
                XmlElement stimulus = (XmlElement)(trialElement.GetElementsByTagName("stimulus")[0]);
                if (stimulus.GetAttribute("screen") == "left")
                    left = XMLReadStimulusParameters(stimulus);
                else
                    right = XMLReadStimulusParameters(stimulus);

                stimulus = (XmlElement)(trialElement.GetElementsByTagName("stimulus")[1]);
                if (stimulus.GetAttribute("screen") == "right")
                    right = XMLReadStimulusParameters(stimulus);
                else
                    left = XMLReadStimulusParameters(stimulus);

                trial = new Trial(trialName);
                trial.SetISI(isi);
                trial.SetRewardParameters(rp);
                trial.SetTransitionParameters(tp);
                trial.SetStimulus(left, right);
                trial.SetBlockPresentations(blockPresentations);
                newDictionary.Add(trialName, trial);
            }
            int blockCount = Convert.ToInt32(xmlDoc.GetElementsByTagName("blocks")[0].FirstChild.InnerText);

            this.trialDictionary = new Dictionary<string, Trial>(newDictionary);
            this.blockCount = blockCount;
            this.isiTrialName = isiTrialName;
            currentFileName = filename;
        }