Esempio n. 1
0
    /// <summary>
    /// Instantiate ExperimentConfig if it doesn't already exist.
    /// Parse all Configuration files while you're at it.
    /// </summary>
    void Awake()
    {
        if (instance != null)
        {
            if (instance != this)
            {
                Debug.Log("Instance of of ExperimentConfig already exists. Destroying this object.");
                Destroy(this);
            }
        }
        else         // there is no instance. Setup time!
        {
            assetBundle = AssetBundle.LoadFromFile(Application.persistentDataPath + "/images");
            if (assetBundle == null)
            {
                // rip. no asset bundle = no experiment
                Debug.Log("No Asset Bundle found.");
            }
            else
            {
                Debug.Log("Asset bundle is loaded.");
            }

            Debug.Log("Parsing config file...");
            // parse the file
            parseConfig();
            Debug.Log("Parse complete. Saving as singleton instance...");
            instance = this;
            DontDestroyOnLoad(this);
            Debug.Log("ExperimentConfig instantiated.");
        }
    }
        private void newExperimentButton_Click(object sender, EventArgs e)
        {
            bool screenTranslationAllowed = true;

            try
            {
                if (Global.GlobalFormMain._contentPanel.Controls.Count > 0)
                {
                    screenTranslationAllowed = checkSave();
                }
                if (screenTranslationAllowed)
                {
                    if (newExperimentButton.Checked)
                    {
                        ExperimentConfig newExperiment = new ExperimentConfig("false");
                        Global.GlobalFormMain._contentPanel.Controls.Add(newExperiment);
                        newExperimentButton.Checked = false;
                    }
                    else
                    {
                        /*do nothing*/
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void editExperimentButton_Click(object sender, EventArgs e)
        {
            bool screenTranslationAllowed = true;

            if (Global.GlobalFormMain._contentPanel.Controls.Count > 0)
            {
                screenTranslationAllowed = checkSave();
            }
            if (screenTranslationAllowed)
            {
                FormDefine   defineProgram;
                DialogResult result;
                string       editProgramName = "error";


                defineProgram = new FormDefine(LocRM.GetString("editProgram", currentCulture), Global.experimentTestFilesPath + Global.programFolderName, "prg", "program", false, false);
                result        = defineProgram.ShowDialog();
                if (result == DialogResult.OK)
                {
                    editProgramName = defineProgram.ReturnValue;
                    ExperimentConfig editExperiment = new ExperimentConfig(editProgramName);
                    Global.GlobalFormMain._contentPanel.Controls.Add(editExperiment);
                    editExperimentButton.Checked = false;
                }
                else
                {
                    /*do nothing, user cancelled selection of program*/
                }
            }
        }
        private bool checkSave()
        {
            bool result = false;

            if (Global.GlobalFormMain._contentPanel.Controls[0] is ExperimentConfig)
            {
                DialogResult dialogResult = MessageBox.Show(LocRM.GetString("savePending", currentCulture), LocRM.GetString("savePendingTitle", currentCulture), MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    ExperimentConfig programToSave = (ExperimentConfig)(Global.GlobalFormMain._contentPanel.Controls[0]);
                    result = programToSave.save();
                }
                else
                {
                    Global.GlobalFormMain._contentPanel.Controls.Clear();
                    return(true);
                }
            }
            if (result == false)
            {
                Global.GlobalFormMain._contentPanel.Controls.Clear();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        public void InitializeStepScenario(ExperimentConfig cnfg)
        {
            _scenarioConfig = cnfg;
            currentTime     = cnfg.StartTime;
            int groupCount = agentGroups.Count;

            for (int i = 0; i < ServicesList.Count; i++)
            {
                if (ServicesList[i] is StopService)
                {
                    if ((ServicesList[i] as StopService).PassengersGroup != null)
                    {
                        groupCount++;
                    }
                }
                if (ServicesList[i] is TurnstileService)
                {
                    if ((ServicesList[i] as TurnstileService).TurnstileGeometry != null)
                    {
                        PaintObject obj = new PaintObject(ServicesList[i].Name);
                    }
                }
                ServicesList[i].Initialize();
            }
            _analisisViewModel = new AnalisisViewModel();

            _analisis = new AnalisisCollector(map.GetMap().GetLength(0), map.GetMap().GetLength(1), groupCount);

            if (GroupListeners != null)
            {
                foreach (var listener in GroupListeners.Values)
                {
                    listener.Stop();
                }
            }
            GroupListeners     = new Dictionary <int, TcpListener>();
            ServersSocketList  = new Dictionary <int, Socket>();
            agentsList         = new List <AgentBase>();
            AgentByStepCounter = new Dictionary <int, double>();
            for (int i = 0; i < agentGroups.Count; i++)
            {
                if (agentGroups[i].IsNetworkGroup)
                {
                    TcpListener tcpListener = new TcpListener(System.Net.IPAddress.Parse(agentGroups[i].Address), agentGroups[i].Port);
                    tcpListener.Start();
                    GroupListeners.Add(agentGroups[i].ID, tcpListener);
                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork += new DoWorkEventHandler(AcceptAgent_DoWork);
                    worker.RunWorkerAsync(agentGroups[i]);
                }
                else
                {
                    AgentByStepCounter.Add(agentGroups[i].ID, 0);
                }
            }
        }
Esempio n. 6
0
 void Awake()
 {
     StimulusObjects  = new List <GameObject>();
     experimentConfig = FindObjectOfType <ExperimentConfig>();
     if (experimentConfig == null)
     {
         Debug.Log("No experiment configuration object found.");
     }
     SetupStimulus();
     AbstractPresenter.ToBePresented.Add(this);
 }
Esempio n. 7
0
    // ********************************************************************** //

    public void LoadTrialSequence()
    {
        // Load in the trial sequence to the data controller and save it
        config      = new ExperimentConfig();
        totalTrials = config.GetTotalTrials();

        // Create the gameData object where we will store all the data
        gameData = new GameData(totalTrials);

        // Specify the number of presents/gifts per room for tracking their state in the GameController
        numberPresentsPerRoom = config.numberPresentsPerRoom;

        // Data that is consistent across trials
        gameData.confirmationCode    = confirmationCode;
        gameData.experimentVersion   = config.experimentVersion;
        gameData.totalTrials         = totalTrials;
        gameData.dataRecordFrequency = config.GetDataFrequency();
        gameData.restbreakDuration   = config.restbreakDuration;
        gameData.getReadyDuration    = config.getReadyDuration;

        Debug.Log("Total number of trials to load: " + totalTrials);

        // Add each required trial data to gameData in turn
        for (int trial = 0; trial < totalTrials; trial++)
        {
            trialList.Add(trial);
            gameData.allTrialData[trial].mapName = config.GetTrialMaze(trial);

            // Positions and orientations
            gameData.allTrialData[trial].playerSpawnLocation    = config.GetPlayerStartPosition(trial);
            gameData.allTrialData[trial].playerSpawnOrientation = config.GetPlayerStartOrientation(trial);

            gameData.allTrialData[trial].star1Location    = config.GetStar1StartPosition(trial);
            gameData.allTrialData[trial].star2Location    = config.GetStar2StartPosition(trial);
            gameData.allTrialData[trial].presentPositions = config.presentPositions[trial];

            // Rewards
            gameData.allTrialData[trial].rewardType       = config.GetRewardType(trial);
            gameData.allTrialData[trial].doubleRewardTask = config.GetIsDoubleReward(trial);

            // Timer variables (can change these for each trial later e.g. with jitter)
            gameData.allTrialData[trial].maxMovementTime       = config.maxMovementTime;
            gameData.allTrialData[trial].goalHitPauseTime      = config.goalHitPauseTime;
            gameData.allTrialData[trial].finalGoalHitPauseTime = config.finalGoalHitPauseTime;
            gameData.allTrialData[trial].preDisplayCueTime     = config.preDisplayCueTime;
            gameData.allTrialData[trial].displayCueTime        = config.displayCueTime;
            gameData.allTrialData[trial].goCueDelay            = config.goCueDelay;
            gameData.allTrialData[trial].minDwellAtReward      = config.minDwellAtReward;
            gameData.allTrialData[trial].displayMessageTime    = config.displayMessageTime;
            gameData.allTrialData[trial].errorDwellTime        = config.errorDwellTime;
            gameData.allTrialData[trial].hallwayFreezeTime     = config.hallwayFreezeTime;
        }
        SaveData();   // Note: Important to keep this here. It seems unimportant, but without it the timing of object initialisation changes somehow(?) and errors emerge. Make sure this isn't too sensitive or figure out a better way to resolve this issue
    }
Esempio n. 8
0
        public void InitializeScenario(ExperimentConfig cnfg)
        {
            currentTime       = cnfg.StartTime;
            _analisis         = new AnalisisCollector(map.GetMap().GetLength(0), map.GetMap().GetLength(1), agentGroups.Count);
            SocketWritersList = new Dictionary <int, StreamWriter>();
            IsStoped          = false;

            _workersList.Clear();
            agentsList.Clear();

            foreach (var group in agentGroups.FindAll(delegate(AgentsGroup ag) { return(!ag.IsServiceGroup); }))
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.WorkerSupportsCancellation = true;
                worker.DoWork += new DoWorkEventHandler(worker_DoWork);
                worker.RunWorkerAsync(group);
                _workersList.Add(worker);
                //if (group.ID == 1)
                //{
                //    try
                //    {
                //        TcpClient tcpClient;
                //        tcpClient = new TcpClient();
                //        tcpClient.NoDelay = true;
                //        tcpClient.Connect(System.Net.IPAddress.Loopback, 5554);
                //        Console.WriteLine("Соединение с 127.0.0.1:5554 установлено");
                //        NetworkStream networkStream = tcpClient.GetStream();
                //        StreamWriter streamWriter = new StreamWriter(networkStream);
                //        SocketWritersList.Add(1, streamWriter);
                //    }
                //    catch (SocketException ex)
                //    {
                //        Console.WriteLine(ex);
                //    }
                //}
            }
            _mainTimer.Interval = TimeSpan.FromMilliseconds(300);
            _mainTimer.Tick    += new EventHandler(mainTimer_Tick);
            _mainTimer.Start();
            DispatcherTimer analisisTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(500)
            };

            analisisTimer.Tick += analisisTimer_Tick;
            analisisTimer.Start();
        }
Esempio n. 9
0
        private void NewScenario()
        {
            scenario              = new Scenario();
            scenario.agentGroups  = new List <AgentsGroup>();
            scenario.agentsList   = new List <AgentBase>();
            scenario.ServicesList = new List <ServiceBase>();
            //scenario.RoadGraph = new Graph<WayPoint, PathFigure>();
            scenario.paintObjectList = new List <PaintObject>();
            scenario.map             = new MapOld(600, 400);

            Properties.Settings.Default.ScenarioPath = null;

            SpeedRatio     = 1.0D;
            experimentCnfg = null;
            PaintMap();
            menuEnableVariator.IsEnabled = true;
        }
Esempio n. 10
0
    // ********************************************************************** //

    public void LoadTrialSequence()
    {
        // Load in the trial sequence to the data controller and save it
        config      = new ExperimentConfig();
        totalTrials = config.GetTotalTrials();

        // Create the gameData object where we will store all the data
        gameData = new GameData(totalTrials);

        // Data that is consistent across trials
        gameData.confirmationCode    = confirmationCode;
        gameData.experimentVersion   = config.experimentVersion;
        gameData.totalTrials         = totalTrials;
        gameData.dataRecordFrequency = config.GetDataFrequency();
        gameData.restbreakDuration   = config.restbreakDuration;
        gameData.getReadyDuration    = config.getReadyDuration;

        Debug.Log("Total number of trials to load: " + totalTrials);

        // Add each required trial data to gameData in turn
        for (int trial = 0; trial < totalTrials; trial++)
        {
            trialList.Add(trial);
            gameData.allTrialData[trial].mapName = config.GetTrialMaze(trial);

            // Questions and Answers
            gameData.allTrialData[trial].trialQuestion        = config.GetQuestion(trial);
            gameData.allTrialData[trial].trialAnswer          = config.GetAnswer(trial);
            gameData.allTrialData[trial].trialStimulus        = config.GetStimulus(trial);
            gameData.allTrialData[trial].trialPossibleAnswers = config.GetPossibleAnswers(trial);

            // Timer variables (can change these for each trial later e.g. with jitter)
            gameData.allTrialData[trial].maxResponseTime        = config.maxResponseTime;
            gameData.allTrialData[trial].finalGoalHitPauseTime  = config.finalGoalHitPauseTime;
            gameData.allTrialData[trial].preDisplayCueTime      = config.preDisplayCueTime;
            gameData.allTrialData[trial].displayCueTime         = config.displayCueTime;
            gameData.allTrialData[trial].goCueDelay             = config.goCueDelay;
            gameData.allTrialData[trial].displayMessageTime     = config.displayMessageTime;
            gameData.allTrialData[trial].errorDwellTime         = config.errorDwellTime;
            gameData.allTrialData[trial].pausePriorFeedbackTime = config.pausePriorFeedbackTime;
            gameData.allTrialData[trial].feedbackFlashDuration  = config.feedbackFlashDuration;
        }
        SaveData();   // Note: Important to keep this here. It seems unimportant, but without it the timing of object initialisation changes somehow(?) and errors emerge. ***HRS to make sure this isn't too sensitive or figure out a better way to resolve this issue later
    }
Esempio n. 11
0
 private void checkSave()
 {
     if (Global.GlobalFormMain.contentPanel.Controls[0] is FormTRConfig)
     {
         DialogResult dialogResult = MessageBox.Show(LocRM.GetString("savePending", currentCulture), LocRM.GetString("savePendingTitle", currentCulture), MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             FormTRConfig toSave = (FormTRConfig)(Global.GlobalFormMain.contentPanel.Controls[0]);
             toSave.save();
         }
         else
         {
             /*do nothing*/
         }
     }
     else if (Global.GlobalFormMain.contentPanel.Controls[0] is ExperimentConfig)
     {
         DialogResult dialogResult = MessageBox.Show(LocRM.GetString("savePending", currentCulture), LocRM.GetString("savePendingTitle", currentCulture), MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             ExperimentConfig toSave = (ExperimentConfig)(Global.GlobalFormMain.contentPanel.Controls[0]);
             toSave.save();
         }
         else
         {
             /*do nothing*/
         }
     }
     else if (Global.GlobalFormMain.contentPanel.Controls[0] is FormPrgConfig)
     {
         DialogResult dialogResult = MessageBox.Show(LocRM.GetString("savePending", currentCulture), LocRM.GetString("savePendingTitle", currentCulture), MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             FormPrgConfig toSave = (FormPrgConfig)(Global.GlobalFormMain.contentPanel.Controls[0]);
             toSave.save();
         }
         else
         {
             /*do nothing*/
         }
     }
 }
 private void newExperimentButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (newExperimentButton.Checked)
         {
             ExperimentConfig newExperiment = new ExperimentConfig("false");
             Global.GlobalFormMain._contentPanel.Controls.Add(newExperiment);
             newExperimentButton.Checked = false;
         }
         else
         {
             /*do nothing*/
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void editExperimentButton_Click(object sender, EventArgs e)
        {
            FormDefine   defineProgram;
            DialogResult result;
            string       editProgramName = "error";


            defineProgram = new FormDefine("Editar Programa: ", Global.experimentTestFilesPath + Global.programFolderName, "prg", "program", false);
            result        = defineProgram.ShowDialog();
            if (result == DialogResult.OK)
            {
                editProgramName = defineProgram.ReturnValue;
                ExperimentConfig editExperiment = new ExperimentConfig(editProgramName);
                Global.GlobalFormMain._contentPanel.Controls.Add(editExperiment);
                editExperimentButton.Checked = false;
            }
            else
            {
                /*do nothing, user cancelled selection of program*/
            }
        }
Esempio n. 14
0
        private void OpenScenario(string path)
        {
            ScenarioReader reader = null;

            try
            {
                reader = new ScenarioReader(path);
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Путь не задан");
                return;
            }
            catch (DirectoryNotFoundException)
            {
                MessageBox.Show("Пути " + path + " не существует");
                return;
            }
            Scenario sc = reader.ReadScenario();

            if (sc == null)
            {
                return;
            }
            scenario       = sc;
            experimentCnfg = null;
            SpeedRatio     = 1.0D;
            if (FirstGrid.Visibility == System.Windows.Visibility.Visible)
            {
                FirstGrid.Visibility = System.Windows.Visibility.Hidden;
            }
            PaintMap();
            menuEnableVariator.IsEnabled             = true;
            Properties.Settings.Default.ScenarioPath = path;
            Properties.Settings.Default.Save();
        }