Пример #1
0
    //checks if Task done and runs set order of blocks
    IEnumerator RunTask()
    {
        while (CurrentTaskState == TaskState.WaitForTrigger)
        {
            _scannerIn.WaitForTrigger();
            yield return(new WaitForSeconds(.005f));
        }

        _logger.Init();

        //condition for ending the game
        while (_taskOver == false)
        {
            if (CurrentTaskState == TaskState.RunTask)
            {
                long start = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);

                yield return(StartCoroutine(Fixation()));

                yield return(StartCoroutine(TrialBlock()));

                yield return(StartCoroutine(Fixation()));

                yield return(StartCoroutine(LastTrialBlock()));

                yield return(StartCoroutine(LastFixation()));

                long end      = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                long duration = end - start;

                Debug.Log(duration / 1000);
            }
        }
        SceneManager.LoadScene("GameEndScreen");
    }
Пример #2
0
    //checks if Task is running within Time/Span Limits
    //TODO: will need external clock if we need task to end at predictable point (scanner)
    IEnumerator RunTask()
    {
        if (CurrentTaskType == TaskType.Scanner)
        {
            while (CurrentTaskState == TaskState.WaitForTrigger)
            {
                Choices.SetActive(false);

                _scannerIn.WaitForTrigger();
                yield return(new WaitForSeconds(.005f));
            }

            _logger.Init();

            while ((Time.timeSinceLevelLoad < _taskTimeLimit))
            {
                yield return(StartCoroutine(ShowSpan()));

                yield return(StartCoroutine(CollectResponses()));
            }
        }

        if (CurrentTaskType == TaskType.Standard)
        {
            _logger.Init();

            while ((_currentSpanLength < _maxSpanLimit) && (Time.timeSinceLevelLoad < _taskTimeLimit))
            {
                yield return(StartCoroutine(ShowSpan()));

                yield return(StartCoroutine(CollectResponses()));
            }
        }

        _logger.Term();
        SceneManager.LoadScene("GameEndScreen");
    }
Пример #3
0
    void Update()
    {
        //Asking TimeManger if we are at end of trial...
        if (_timer.EndTrial == true)
        {
            _currentTaskState = TaskState.EndTrial;
        }

        //asking TimeManager if we are at end of a block...
        if (_trialType == TrialType.Both)
        {
            if (_timer.SwitchBlock == true)
            {
                if (CurrentBlockType == BlockType.Baseline)
                {
                    CurrentBlockType  = BlockType.Reversal;
                    _currentTaskState = TaskState.StartBlock;
                }
                else if (CurrentBlockType == BlockType.Reversal)
                {
                    CurrentBlockType  = BlockType.Baseline;
                    _currentTaskState = TaskState.StartBlock;
                }
            }
        }


        // MAIN STATE MACHINE
        switch (_currentTaskState)
        {
        case TaskState.WaitForTrigger:

            if (!Hourglass.activeInHierarchy)
            {
                Hourglass.SetActive(true);
            }

            break;

        case TaskState.StartTrial:

            ClearFeedback();
            _logger.Init();

            switch (_trialType)
            {
            case TrialType.Both:
                CurrentBlockType = BlockType.Baseline;
                break;

            case TrialType.Baseline:
                CurrentBlockType = BlockType.Baseline;
                break;

            case TrialType.Reversal:
                CurrentBlockType = BlockType.Reversal;
                break;
            }

            _currentTaskState = TaskState.StartBlock;

            break;

        case TaskState.StartBlock:

            switch (CurrentBlockType)
            {
            case BlockType.Baseline:
                StartBaseline();
                _blockLengthLimit = _baselineBlockLength;
                break;

            case BlockType.Reversal:
                StartReversal();
                _blockLengthLimit = _reversalBlockLength;
                break;
            }

            //start the block timer here, check end in Timer script
            BlockTimerStart   = DateTime.Now;
            _currentTaskState = TaskState.StartIteration;

            break;

        case TaskState.StartIteration:

            if (CurrentBlockType == BlockType.Baseline)
            {
                ClearFeedback();
                StartBaseline();
            }

            if (CurrentBlockType == BlockType.Reversal)
            {
                ClearFeedback();
                StartReversal();
            }


            _previousChoices = new List <ItemChoice>();

            if (CurrentBlockType == BlockType.Baseline || _previousCorrectChoice == ItemChoice.None)
            {
                SetCorrectAnswerRandomly();
            }
            else
            {
                SetCorrectAnswerToPrevious();
            }

            if (CurrentBlockType == BlockType.Baseline)
            {
                DisplayHint();
            }

            _iterationStartTime = Time.time;                     //start time of the iteration
            _currentTaskState   = TaskState.ProcessChoice;

            break;


        case TaskState.ProcessChoice:

            // Filter out no choice or repeated choices
            if (_currentChoice != ItemChoice.None && !_previousChoices.Contains(_currentChoice))
            {
                _previousChoices.Add(_currentChoice);

                if (_previousCorrectChoice == ItemChoice.None)
                {
                }

                if (CurrentBlockType == BlockType.Reversal && _interReversalIterationCount > _interReversalIterationNumber)                        // **RANDOMIZED # OF ITERATIONS BETWEEN REVERSAL BLOCKS**
                {
                    SetCorrectAnswerBasedOnChoiceProb(_currentChoice);
                    _reversalFlag = 1;     //marks occurance of reversals
                }

                if (_currentChoice == _correctChoice)
                {
                    UpdateDisplayForChoice(_currentChoice, ChoiceResult.Correct);

                    if (CurrentBlockType == BlockType.Reversal)
                    {
                        _attemptCount++;                                 //tally for total number of responses
                        _correctAttemptCount++;                          //tally for totaly number of CORRECT responses
                    }

                    if (CurrentBlockType == BlockType.Baseline)
                    {
                        _baselineAttemptCount++;
                        baselineCorrectAttemptCount++;
                    }
                    _iterationEndTime = Time.time;
                    _currentTaskState = TaskState.ReinforceIteration;
                }

                else
                {
                    UpdateDisplayForChoice(_currentChoice, ChoiceResult.Incorrect);

                    if (CurrentBlockType == BlockType.Reversal)
                    {
                        _attemptCount++;                                 //tally for total number of responses
                        _incorrectAttemptCount++;                        //tally for totaly number of INCORRECT responses

                        if (_reversalFlag == 1)
                        {
                            _incorrectAttemptOnReversalCount++;                                     // tally for the number of INCORRECT responses in a REVERSAL condition
                        }
                    }

                    if (CurrentBlockType == BlockType.Baseline)
                    {
                        _baselineAttemptCount++;
                        baselineIncorrectAttemptCount++;
                    }

                    _currentTaskState = TaskState.ProcessChoice;
                }

                _currentChoice = ItemChoice.None;
            }
            break;

        case TaskState.ReinforceIteration:

            var tmpTime = Time.time;
            _currentTaskState = tmpTime - _iterationEndTime >= 1.5 ? TaskState.EndIteration : TaskState.ReinforceIteration;                     //FIX THIS : MAKE THE DELAY CONFIGURABLE

            break;

        case TaskState.EndIteration:

            //blockTimerEnd = DateTime.Now;
            _currentTrialLength = Time.timeSinceLevelLoad - ScannerDelay;

            _previousCorrectChoice = _correctChoice;
            _interReversalIterationCount++;

            _logger.LogRaw(_reversalIterationCount + " , " + _attemptCount + " , " + _correctAttemptCount + " , " + _incorrectAttemptCount + " , " + _incorrectAttemptOnReversalCount + " , " + _responseTime +
                           " , " + _reversalCount + " , " + _reversalResponseTime + " , " + baselineIterationCount + " , " + baselineResponseTime + " , " + _baselineAttemptCount + " , " + baselineCorrectAttemptCount + " , "
                           + baselineIncorrectAttemptCount);

            if (CurrentBlockType == BlockType.Reversal)
            {
                _reversalIterationCount++;                                    //tally of the number of iterations presented
                _responseTime      = _iterationEndTime - _iterationStartTime; //calculating time in between CORRECT responses (response time)
                _totalResponseTime = _totalResponseTime + _responseTime;      //total response time compiler. compiles the time it takes to get the correct answer (the time taken to complete iteration) --> used to calculate average

                if (_reversalFlag == 1)                                       // checking if reversal has occured and pulling that time frame from _responseTime
                {
                    _interReversalIterationNumber = Random.Range(4, 7);
                    _reversalResponseTime         = _responseTime;
                    _totalReversalResponseTime    = _totalReversalResponseTime + _reversalResponseTime; //compiling total response time in reversal situation
                    _reversalCount++;                                                                   //compiles number of reversals as they occur
                    _reversalFlag = 0;                                                                  //resets reversal marker
                }
            }

            if (CurrentBlockType == BlockType.Baseline)                     //baseline block metrics
            {
                baselineIterationCount++;
                baselineResponseTime       = _iterationEndTime - _iterationStartTime;
                _totalBaselineResponseTime = _totalBaselineResponseTime + baselineResponseTime;
            }

            if (_trialType != TrialType.Both)
            {
                _currentTaskState = TaskState.StartIteration;
            }

            //if (_trialType == TrialType.All && ((blockTimerEnd - blockTimerStart).Seconds > blockLengthLimit))
            //{
            //	_currentTaskState = TaskState.EndBlock;
            //}

            else
            {
                _currentTaskState = TaskState.StartIteration;
            }

            //            if (_trialLength > _trialLengthLimit) //**SET THIS TO A GIVEN TIME PERIOD (9 MIN WAS DISCUSSED - 540 sec)**
            //{
            //	_currentTaskState = TaskState.EndTrial;
            //}

            break;

        case TaskState.EndBlock:

            if (CurrentBlockType == BlockType.Baseline)
            {
                CurrentBlockType = BlockType.Reversal;
            }

            else if (CurrentBlockType == BlockType.Reversal)
            {
                CurrentBlockType = BlockType.Baseline;
            }

            _currentTaskState = TaskState.StartBlock;
            break;

        case TaskState.EndTrial:

            _averageResponseTime         = _totalResponseTime / _reversalIterationCount;                                                                                                                                                                                                                                                 // average response time to get correct answer over course of the whole trial
            _averageReversalResponseTime = _totalReversalResponseTime / _reversalCount;                                                                                                                                                                                                                                                  // average response time to reversal condition
            averageBaselineResponseTime  = _totalBaselineResponseTime / baselineIterationCount;                                                                                                                                                                                                                                          // baseline block metrics

            _logger.LogReversalSummary("ReversalIterationCount , trialDuration , averageResponseTime , reversalCount , averageReversalResponseTime" + Environment.NewLine + _reversalIterationCount + " , " + _timer.CurrentTrialLength + " , " + _averageResponseTime + " , " + _reversalCount + " , " + _averageReversalResponseTime); // summery metrics for whole trial
            _logger.LogBaselineSummary("BaselineIterationCount , trialDuration , baselineCorrectCount , baselineIncorrectCount , averageBaselineResponseTime" + Environment.NewLine + baselineIterationCount + " , " + _timer.CurrentTrialLength + " , " + baselineCorrectAttemptCount + " , " + baselineIncorrectAttemptCount + " , " + averageBaselineResponseTime);
            _logger.Term();

            SceneManager.LoadScene("GameEndScreen_Stimulation");

            break;
        }
    }