private RewardParameters XMLReadRewardParameters(XmlElement xmlRewardParameters) { RewardParameters rp = new RewardParameters(); string rewardType = xmlRewardParameters.GetAttribute("type"); switch (rewardType) { case "velocity": rp.rewardType = RewardType.Velocity; rp.velocityDuration = Convert.ToInt32(((XmlElement)xmlRewardParameters.GetElementsByTagName("duration")[0]).InnerText); rp.velocityThreshold = Convert.ToDouble(((XmlElement)xmlRewardParameters.GetElementsByTagName("threshold")[0]).InnerText); if (((XmlElement)xmlRewardParameters.GetElementsByTagName("thresholdComparison")[0]).InnerText == "lower") { rp.lowerThan = true; } else { rp.lowerThan = false; } break; case "none": rp.rewardType = RewardType.None; break; case "random": rp.rewardType = RewardType.Random; rp.rewardCount = Convert.ToInt32(((XmlElement)xmlRewardParameters.GetElementsByTagName("count")[0]).InnerText); rp.rewardTotal = Convert.ToInt32(((XmlElement)xmlRewardParameters.GetElementsByTagName("total")[0]).InnerText); break; } return(rp); }
// 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); }
private void SetRewardParameters(RewardParameters rp) { if (rp.rewardType == RewardType.None) { reward_none.Checked = true; } else if (rp.rewardType == RewardType.Random) { reward_random.Checked = true; reward_random_count.Value = rp.rewardCount; reward_random_total.Value = rp.rewardTotal; } else { reward_velocity.Checked = true; reward_velocity_comparison.SelectedIndex = Convert.ToInt32(rp.lowerThan); reward_velocity_duration.Value = rp.velocityDuration; reward_velocity_threshold.Value = Convert.ToDecimal(rp.velocityThreshold); } }
public void XMLWriteRewardParameters(XmlWriter xmlWriter, RewardParameters rp) { xmlWriter.WriteStartElement("reward"); switch (rp.rewardType) { case RewardType.None: xmlWriter.WriteAttributeString("type", "none"); break; case RewardType.Random: xmlWriter.WriteAttributeString("type", "random"); xmlWriter.WriteStartElement("count"); xmlWriter.WriteString(rp.rewardCount.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("total"); xmlWriter.WriteString(rp.rewardTotal.ToString()); xmlWriter.WriteEndElement(); break; case RewardType.Velocity: xmlWriter.WriteAttributeString("type", "velocity"); xmlWriter.WriteStartElement("threshold"); xmlWriter.WriteString(rp.velocityThreshold.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("duration"); xmlWriter.WriteString(rp.velocityDuration.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("thresholdComparison"); if (rp.lowerThan) { xmlWriter.WriteString("lower"); } else { xmlWriter.WriteString("higher"); } xmlWriter.WriteEndElement(); break; } xmlWriter.WriteEndElement(); }
private RewardParameters GetRewardParameters() { RewardParameters rp = new RewardParameters(); if (reward_none.Checked) { rp.rewardType = RewardType.None; } else if (reward_random.Checked) { rp.rewardType = RewardType.Random; rp.rewardCount = System.Convert.ToInt32(reward_random_count.Value); rp.rewardTotal = System.Convert.ToInt32(reward_random_total.Value); } else { rp.rewardType = RewardType.Velocity; rp.lowerThan = (reward_velocity_comparison.SelectedIndex == 1); rp.velocityThreshold = Convert.ToDouble(reward_velocity_threshold.Value); rp.velocityDuration = Convert.ToInt32(reward_velocity_duration.Value); } return(rp); }
public void SetRewardParameters(RewardParameters r) { this.rp = r; }
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; }
private RewardParameters GetRewardParameters() { RewardParameters rp = new RewardParameters(); if (reward_none.Checked) { rp.rewardType = RewardType.None; } else if (reward_random.Checked) { rp.rewardType = RewardType.Random; rp.rewardCount = System.Convert.ToInt32(reward_random_count.Value); rp.rewardTotal = System.Convert.ToInt32(reward_random_total.Value); } else { rp.rewardType = RewardType.Velocity; rp.lowerThan = (reward_velocity_comparison.SelectedIndex == 1); rp.velocityThreshold = Convert.ToDouble(reward_velocity_threshold.Value); rp.velocityDuration = Convert.ToInt32(reward_velocity_duration.Value); } return rp; }
private RewardParameters XMLReadRewardParameters(XmlElement xmlRewardParameters) { RewardParameters rp = new RewardParameters(); string rewardType = xmlRewardParameters.GetAttribute("type"); switch (rewardType) { case "velocity": rp.rewardType = RewardType.Velocity; rp.velocityDuration = Convert.ToInt32(((XmlElement)xmlRewardParameters.GetElementsByTagName("duration")[0]).InnerText); rp.velocityThreshold = Convert.ToDouble(((XmlElement)xmlRewardParameters.GetElementsByTagName("threshold")[0]).InnerText); if (((XmlElement)xmlRewardParameters.GetElementsByTagName("thresholdComparison")[0]).InnerText == "lower") rp.lowerThan = true; else rp.lowerThan = false; break; case "none": rp.rewardType = RewardType.None; break; case "random": rp.rewardType = RewardType.Random; rp.rewardCount = Convert.ToInt32(((XmlElement)xmlRewardParameters.GetElementsByTagName("count")[0]).InnerText); rp.rewardTotal = Convert.ToInt32(((XmlElement)xmlRewardParameters.GetElementsByTagName("total")[0]).InnerText); break; } return rp; }
public void XMLWriteRewardParameters(XmlWriter xmlWriter, RewardParameters rp) { xmlWriter.WriteStartElement("reward"); switch (rp.rewardType) { case RewardType.None: xmlWriter.WriteAttributeString("type", "none"); break; case RewardType.Random: xmlWriter.WriteAttributeString("type", "random"); xmlWriter.WriteStartElement("count"); xmlWriter.WriteString(rp.rewardCount.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("total"); xmlWriter.WriteString(rp.rewardTotal.ToString()); xmlWriter.WriteEndElement(); break; case RewardType.Velocity: xmlWriter.WriteAttributeString("type", "velocity"); xmlWriter.WriteStartElement("threshold"); xmlWriter.WriteString(rp.velocityThreshold.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("duration"); xmlWriter.WriteString(rp.velocityDuration.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("thresholdComparison"); if (rp.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; }