Пример #1
0
 /// <summary>
 /// Called when the game session is finished.
 /// e.g. All session trials have been completed.
 /// </summary>
 protected override void FinishedSession()
 {
     GUILog.Log("Score: {0} / {1}", score, trials);
     base.FinishedSession();
     instructionsText.text  = FINISHED;
     instructionsText.text += "\nScore: " + score + "/" + trials;
 }
Пример #2
0
    /// <summary>
    /// Creates a log file of the given session data.
    /// </summary>
    public static void WriteSessionLog(ref SessionData sData)
    {
        XDocument doc         = new XDocument();
        XElement  sessionElem = new XElement(ELEM_SESSION);

        // Session Elem children.
        XElement resultsElem  = new XElement(ELEM_RESULTS);
        XElement settingsElem = new XElement(ELEM_SETTINGS);
        XElement trialsElem   = new XElement(ELEM_TRIALS);

        // Populate the elements with data.
        WriteResultsElement(sData, ref resultsElem);
        WriteSettingsElement(sData, ref settingsElem);
        WriteTrialsElement(sData, ref trialsElem);

        // Add all the Elements to the document in the proper order.
        doc.Add(sessionElem);
        sessionElem.Add(resultsElem, settingsElem, trialsElem);

        // Save the document.
        string fileName = GetOutputFilepath(sData);

        GUILog.Log("Using output file {0} for module {1}", fileName, sData.GameName);
        try
        {
            doc.Save(fileName);
            sData.outputWritten = true;
        }
        catch (Exception e)
        {
            GUILog.Error("XMLUtil::WriteSessionLog:: Failed to Save output document {0} \n{1}", fileName, e.Message.ToString());
        }
    }
Пример #3
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// Stores the accuracy of the marker position when player responded.
    /// </summary>
    protected override void AddResult(Trial t, float xPos)
    {
        TrialResult r = new TrialResult(t);

        r.accuracy = GetAccuracy(xPos);
        int score = GetScore(xPos);

        if (IsHighResponse(score))
        {
            DisplayFeedback(HIGH_RESPONSE, RESPONSE_COLOR_HIGH, score);
            r.success = true;
            GUILog.Log("EXCELLENT! Score = {0}", score);
        }
        else if (IsMediumResponse(score))
        {
            DisplayFeedback(MEDIUM_RESPONSE, RESPONSE_COLOR_MEDIUM, score);
            r.success = true;
            GUILog.Log("Good! Score = {0}", score);
        }
        else if (IsLowResponse(score))
        {
            DisplayFeedback(LOW_RESPONSE, RESPONSE_COLOR_LOW, score);
            r.success = true;
            GUILog.Log("Ok. Score = {0}", score);
        }
        else
        {
            DisplayFeedback(LOWEST_RESPONSE, RESPONSE_COLOR_LOWEST, score);
            r.success = false;
            GUILog.Log("Bad... Score = {0}", score);
        }
        sessionData.results.Add(r);
    }
Пример #4
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TippingPointTrialResult r = new TippingPointTrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            // No response.
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("Fail! No response!");
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                //Check if it was also the wrong key.
                if (IsCorrectKey((TippingPointTrial)t))
                {
                    r.keyCorrect = true;
                }
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                //Check if correct key was pressed
                if (IsCorrectKey((TippingPointTrial)t))
                {
                    // Responded correctly.
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    r.success    = true;
                    r.keyCorrect = true;
                    r.accuracy   = GetAccuracy(t, time);
                    GUILog.Log("Success! responseTime = {0}", time);
                }
                else
                {
                    //With wrong key.
                    DisplayFeedback(RESPONSE_KEY, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Wrong Key Pressed! key pressed = " + keyPressed, time);
                }
            }
            else
            {
                // Responded too slow.
                DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Slow response! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
Пример #5
0
 /// <summary>
 /// Checks that all the folders we define here are accessible, and if not
 /// creates them. If something goes wrong returns False.
 /// </summary>
 public static bool InitializeFolders()
 {
     foreach (string path in FoldersList)
     {
         if (!CheckAndCreateDir(path))
         {
             GUILog.Error("Unable to create folder {0}", path);
             return(false);
         }
     }
     GUILog.Log("Folders initialized for {0}", DashboardPath);
     return(true);
 }
    /// <summary>
    /// Displays the Stimulus for a specified duration.
    /// During that duration the player needs to respond as quickly as possible.
    /// </summary>
    protected virtual IEnumerator DisplayStimulus(Trial t)
    {
        GameObject stim = stimulus;

        stim.SetActive(false);

        yield return(new WaitForSeconds(t.delay));

        StartInput();

        ReactTrialRed RTR = t as ReactTrialRed;

        // Set color of the stimulus as given in the trial
        if (RTR.isRed)
        {
            stim.GetComponent <Image>().color = Color.red;
            currentColorIsRed = true;
        }

        if (!RTR.isRed)
        {
            stim.GetComponent <Image>().color = Color.white;
            currentColorIsRed = false;
        }

        // Set position of the stimulus as given in the trial.
        if (RTR.isRandomPos)
        {
            StimRandomPos.x = GetRandomX(RTR.minX, RTR.maxX);
            StimRandomPos.y = GetRandomY(RTR.minY, RTR.maxY);

            stim.GetComponent <RectTransform>().anchoredPosition = StimRandomPos;
            GUILog.Log("Current stimulus position: " + stim.GetComponent <RectTransform>().position.ToString());
        }
        else
        {
            StimRandomPos.x = RTR.fixedX;
            StimRandomPos.y = RTR.fixedY;
            stim.GetComponent <RectTransform>().anchoredPosition = StimRandomPos;
            GUILog.Log("Current stimulus position: " + stim.GetComponent <RectTransform>().position.ToString());
        }


        stim.SetActive(true);
        yield return(new WaitForSeconds(((ReactTrialRed)t).duration));

        stim.SetActive(false);
        EndInput();

        yield break;
    }
Пример #7
0
 /// <summary>
 /// Called when the game session has started.
 /// </summary>
 public virtual GameBase StartSession(TextAsset sessionFile)
 {
     // Create and load a SessionData object to give to the active game.
     sessionData = new SessionData();
     if (XMLUtil.LoadSessionData(sessionFile, ref sessionData))
     {
         GUILog.Log("Game {0} starting Session {1}", this.gameObject.name, sessionFile.name);
         OnStart();
     }
     else
     {
         GUILog.Error("Game {0} failed to load session file {1}", this.gameObject.name, sessionFile.name);
     }
     return(this);
 }
Пример #8
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0 && !t.isRed)
        {
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("FAIL! No Response");
        }
        else if (time == 0 && t.isRed)
        {
            r.success = true;
            DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
            GUILog.Log("Correct! responseTime = {0}", time);
        }
        else
        {
            if (IsGuessResponse(time))
            {
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time) && !t.isRed)
            {
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! responseTime = {0}", time);
            }
            else if (IsValidResponse(time) && t.isRed)
            {
                DisplayFeedback(RESPONSE_INCORRECT, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Incorrect response! responseTime = {0}", time);
            }
            else
            {
                DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Slow response! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
Пример #9
0
    /// <summary>
    /// Parses all the Trials attributes and Trial elements.
    /// </summary>
    private static void ParseSessionTrials(XmlNode trialsNode, ref SessionData sData)
    {
        if (trialsNode == null)
        {
            GUILog.Error("Session {0}, Trials element not found.", sData.fileName);
            return;
        }

        sData.trials = new List <Trial>();
        foreach (XmlNode n in trialsNode.ChildNodes)
        {
            switch (n.Name)
            {
            case ELEM_TRIAL:
                ParseTrial(n as XmlElement, ref sData);
                break;
            }
        }
        GUILog.Log("Found {0} Trials defined in {1}", sData.trials.Count, sData.fileName);
    }
Пример #10
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        if (!t.isRed)
        {
            //Stimulus is not red. The new implementation is not required.
            base.AddResult(t, time);
            return;
        }
        //Stimulus is red. New implementation is required.
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        r.isRed        = true;
        if (time == 0)
        {
            // No response.
            DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
            r.success  = true;
            r.accuracy = 1;
            GUILog.Log("Success! No response!");
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else
            {
                // Responded too slow.
                DisplayFeedback(RESPONSE_WRONG, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Response detected! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
Пример #11
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            // No response.
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("Fail! No response!");
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                // Responded correctly.
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! responseTime = {0}", time);
            }
            else
            {
                // Responded too slow.
                DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Slow response! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
Пример #12
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            if (((AzzaranoTrial)t).red == "false" && ball == false)
            {
                // No response.
                DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! No response!");
            }
            else if (((AzzaranoTrial)t).red == "false" && ball == true)
            {
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! Didn't respond to BALL.");
                score += 1;
            }
            else
            {
                // Responded correctly.
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! Didn't respond to RED.");
                score += 1;
            }
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                if (((AzzaranoTrial)t).red == "false" && ball == false)
                {
                    // Responded correctly.
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    r.success  = true;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Success! responseTime = {0}", time);
                    score += 1;
                }
                else if (((AzzaranoTrial)t).red == "false" && ball == true)
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITBALL, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to BALL");
                }
                else
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITRED, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to RED");
                }
            }
            else
            {
                if (((AzzaranoTrial)t).red == "false" && ball == false)
                {
                    // Responded too slow.
                    DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Slow response! responseTime = {0}", time);
                }
                else if (((AzzaranoTrial)t).red == "false" && ball == true)
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITBALL, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to BALL");
                }
                else
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITRED, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to RED");
                }
            }
        }
        sessionData.results.Add(r);
    }
Пример #13
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        // stim isRed and times out
        // Result: Correct response
        if (time == 0 && t.isRed)
        {
            DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
            GUILog.Log("Success! Didn't click red! responseTime = {0}", time);
            sessionData.results.Add(r);
            return;
        }
        // If not red and times out
        // Result: Fail. No response
        if (time == 0 && !t.isRed)
        {
            // No response.
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("Fail! No response!");
        }
        else
        {
            // Player Guesses
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }

            // Player responds in time and it is not red
            else if (IsValidResponse(time) && !t.isRed)
            {
                // Responded correctly.
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! responseTime = {0}", time);
            }

            // player responds and it is red
            else if (IsValidResponse(time) && t.isRed)
            {
                // Responded correctly but wrong color
                DisplayFeedback(RESPONSE_INCORRECT, RESPONSE_COLOR_BAD);
                r.success  = false;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Fail! responseTime = {0}", time);
            }

            // No responce
            else
            {
                // Catch in case it is red and gets to here
                if (t.isRed)
                {
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    GUILog.Log("Success! Didn't click red! responseTime = {0}", time);
                }
                // No response and fail
                else
                {
                    DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Slow response! responseTime = {0}", time);
                }
            }
        }
        sessionData.results.Add(r);
    }
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            // If no response, check if stimulus has valid color or not (Valid color = white, not valid color = red).
            if (IsValidStimulusColor(t))
            {
                GUILog.Log("Fail! No response!");
                DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            }
            else
            {
                GUILog.Log("Success! Ignored the red square!");
                DisplayFeedback(RESPONSE_RED_IGNORED, RESPONSE_COLOR_GOOD);
                r.success = true;
            }
        }
        else
        {
            if (IsGuessResponse(time) && IsValidStimulusColor(t))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                if (IsValidStimulusColor(t))
                {
                    // Responded correctly.
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    r.success  = true;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Success! responseTime = {0}", time);
                }
                else
                {
                    DisplayFeedback(RESPONSE_RED, RESPONSE_COLOR_BAD);
                    r.success  = false;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Fail! Responded to wrong color");
                }
            }
            else
            {
                // Responded too slow.
                if (IsValidStimulusColor(t))
                {
                    DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Slow response! responseTime = {0}", time);
                }
                else
                {
                    DisplayFeedback(RESPONSE_RED, RESPONSE_COLOR_BAD);
                    r.success  = false;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Fail! Responded to wrong color");
                }
            }
        }

        // Preparing and writing data in result
        if (currentColorIsRed)
        {
            r.isRed = true;
        }
        else
        {
            r.isRed = false;
        }
        r.positionX = (int)StimRandomPos.x;
        r.positionY = (int)StimRandomPos.y;
        sessionData.results.Add(r);
    }