// send remote data if we can
    private bool SaveRemotely(string dataString)
    {
        bool saved = false;

        if (webClientValid == WebClientState.FAILED)
        {
            return(false);
        }
        try
        {
            if (!loggedin)
            {
                Login();
            }

            long participant = ParticipantStatus.GetInstance().GetParticipant();

            if (loggedin && participant >= 0)
            {
                // check if we succeeded and retry a limited number of times with backoff if we don't
                int tries = SAVE_RETRIES;
                do
                {
                    saved = false;
                    string uri    = string.Format("{0}/save/{1}", REMOTE_URI, participant);
                    string result = PostRequest(uri, dataString);
                    if (result == null)
                    {
                        break;
                    }
                    Debug.Log("save result: " + result);
                    if (result.StartsWith("OK"))
                    {
                        Debug.Log("confirmed save");
                        saved = true;
                    }
                    else
                    {
                        tries--;
                        if (tries <= 0)
                        {
                            break;
                        }
                        Debug.Log("failed trying to log in again " + tries + " tries left");
                        Thread.Sleep(SAVE_RETRIES - tries * 500); // ms to wait before trying again
                        Login();
                    }
                } while (loggedin && !saved);
                if (!saved)
                {
                    Debug.Log("ERROR: NOT ABLE TO SAVE DATA REMOTELY!");
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
        return(saved);
    }
    private void OnTriggerStay(Collider other)
    {
        if (leftController.controller.GetHairTriggerUp() || rightController.controller.GetHairTriggerUp())
        {
            //reset selection state
            TestState.SetSelectedFalse();

            //reset all buttons back to grey (no choice)
            for (int i = 0; i < 4; i++)
            {
                TestButtons[i].GetComponent <Renderer>().material = material;
            }

            if (trials > 0)
            {
                //Despawn current box
                bool any = true;
                this.GetComponent <DespawnObject>().buttonDespawn(any);

                ps.GetNextStimulus();
                trials--;
                Debug.Log("test trials left " + trials);
                //Spawn new box
                bool always = true;
                this.GetComponent <SpawnRandomBox>().spawn(always);
            }
            else
            {
                this.GetComponent <DespawnObject>().buttonDespawn();
                Debug.Log("showing instructions");
                ParticipantStatus.GetInstance().ResetCubes();
                SceneManager.LoadScene("ParticipantInstructions", LoadSceneMode.Single);
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     ps     = ParticipantStatus.GetInstance();
     player = GameObject.FindGameObjectWithTag("MainCamera"); // this responds to head movements, Player doesn't
     Debug.Log("Player", player);
     previousSide = -1;
     trial        = -1;
 }
Exemple #4
0
 public DataFarmerObject(string tag)
 {
     this.tag         = tag;
     this.timestamp   = Time.time;
     ps               = ParticipantStatus.GetInstance();
     this.participant = ps.GetParticipant();
     this.trial       = ps.GetTrial();
     this.condition   = ps.GetCondition();
     this.category    = ps.GetCategory();
     this.cube        = ps.GetCube();
 }
    // makes a cube from a description of the 3 axes
    // for a description of this see ColorShapeRotation.cs
    // a CubeTuple describes a cube
    // mapping of cubes to categories is stored externally
    // as json data
    // for any participant we pick one set of mappings
    // and go through them somewhat randomly

    // I guess this is the current version of the "nice function"
    // this pulls the materials based on what we get for
    // the externally generated counterbalancing conditions
    // and maps the materials to the raw cube
    Material[] createSet()
    {
        CubeTuple c = ParticipantStatus.GetInstance().GetCube();

        Material[] matlist = rend.materials;
        matlist[0] = material[0];
        foreach (ColorShapeRotation csr in c.cube)
        {
            foreach (int face in csr.GetFaces())
            {
                matlist[face] = material[csr.GetMaterial()];
            }
        }
        return(matlist);
    }
    // makes a cube from a description of the 3 axes
    // for a description of this see ColorShapeRotation.cs
    // a CubeTuple describes a cube
    // mapping of cubes to categories is stored externally
    // as json data
    // for any participant we pick one set of mappings
    // and go through them somewhat randomly
    // this pulls the materials based on what we get for
    // the externally generated counterbalancing conditions
    // and maps the materials to the raw cube
    Material[] createSet()
    {
        // a CubeTuple is the 3 axes of the cube
        CubeTuple c = ParticipantStatus.GetInstance().GetCube();

        Material[] matlist = rend.materials;

        // this is the basic background material for the cube
        matlist[0] = material[0];

        // ColorShapeRotation describes one of the axes of the cube
        foreach (ColorShapeRotation csr in c.cube)
        {
            // we dress the two faces for the axis with the appropriate material
            foreach (int face in csr.GetFaces())
            {
                matlist[face] = material[csr.GetMaterial()];
            }
        }
        return(matlist);
    }
Exemple #7
0
 private void Start()
 {
     ps = ParticipantStatus.GetInstance();
 }
Exemple #8
0
    public void OnTriggerStay(Collider other)
    {
        if (leftController.controller.GetHairTriggerUp() || rightController.controller.GetHairTriggerUp())
        {
            if (cTag != "NEXT")
            {
                if (firstChoice == true)
                {
                    this.GetComponent <CustomTag>().buttonTagBehaviour(cTag); // Call custom tag top set correct/incorrect

                    // string chosenTag = cube.GetComponent<CustomTag>().getTag(0);
                    string correctTag = ParticipantStatus.GetInstance().GetCategory();
                    // this gets repeated alot: Debug.Log("cTag " + cTag + " chosenTag " + correctTag);

                    GameObject[] currentObjs = GameObject.FindGameObjectsWithTag("Interactable Object");
                    foreach (GameObject cube in currentObjs)
                    {
                        if (correctTag == cTag)
                        {
                            //Correct Choice == change this to green, others to grey, next to blue
                            this.GetComponent <Renderer>().material = correctMat;

                            for (int i = 0; i < choices.Count; i++)
                            {
                                if (choices[i] != gameObject)
                                {
                                    if (choices[i].GetComponent <CustomTag>().getTag(0) != "NEXT") //Set all other buttons to grey.
                                    {
                                        choices[i].GetComponent <Renderer>().material = neutralMat;
                                        choices[i].GetComponent <ChoiceBehaviour>().setFirstChoice(false);
                                    }
                                    else //next button to blue
                                    {
                                        choices[i].GetComponent <Renderer>().material = nextMat;
                                        choices[i].GetComponent <ChoiceBehaviour>().setFirstChoice(false);
                                    }
                                }
                            }
                        }
                        else
                        {
                            //Incorrect choice == change this to red, correct to green, others to grey, next to blue
                            this.GetComponent <Renderer>().material = wrongMat;
                            for (int i = 0; i < choices.Count; i++)
                            {
                                if (choices[i] != gameObject)
                                {
                                    if (choices[i].GetComponent <CustomTag>().getTag(0) != "NEXT")
                                    {
                                        // if (choices[i].GetComponent<CustomTag>().getTag(0) != cube.GetComponent<CustomTag>().getTag(0))
                                        if (choices[i].GetComponent <CustomTag>().getTag(0) != correctTag)
                                        { //if not next AND not correct choice
                                            choices[i].GetComponent <Renderer>().material = neutralMat;
                                            choices[i].GetComponent <ChoiceBehaviour>().setFirstChoice(false);
                                        }
                                        else //Not next AND correct choice
                                        {
                                            choices[i].GetComponent <Renderer>().material = correctMat;
                                            choices[i].GetComponent <ChoiceBehaviour>().setFirstChoice(false);
                                        }
                                    }
                                    else //next button
                                    {
                                        choices[i].GetComponent <Renderer>().material = nextMat;
                                        choices[i].GetComponent <ChoiceBehaviour>().setFirstChoice(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else //Player clicked next button
            {
                ResetButtons();
            }
        }
    }
Exemple #9
0
 public void Start()
 {
     ps = ParticipantStatus.GetInstance();
     ps.IncTrial();
 }
Exemple #10
0
 // Use this for initialization
 // for the ui to work properly the canvas must use Render Mode "Screen Space - Overlay"
 // this is causing a warning to show up in unity's editor but this has no effect as
 // we don't want the participant to see the UI
 void Start()
 {
     ps = ParticipantStatus.GetInstance();
     apply.onClick.AddListener(StartExperimentListener);
 }
Exemple #11
0
 // Update is called once per frame
 // keeping the cumulative displacement as this vs time might be useful later
 // i.e. calculating velocity and acceleration over the entire run
 void Update()
 {
     distanceTravelled += Vector3.Distance(transform.position, previousPosition);
     previousPosition   = transform.position;
     ParticipantStatus.GetInstance().UpdateDisplacement(thing, distanceTravelled);
 }
 // Use this for initialization
 // for the ui to work properly the canvas must use Render Mode "Screen Space - Overlay"
 // this is causing a warning to show up in unity's editor but this has no effect as
 // we don't want the participant to see the UI
 void Start()
 {
     ps = ParticipantStatus.GetInstance();
     apply.onClick.AddListener(SetParticipantCondition);
 }
Exemple #13
0
 // Use this for initialization
 void Start()
 {
     ps = ParticipantStatus.GetInstance();
     button.onClick.AddListener(PreviousParticipantListener);
 }
Exemple #14
0
    //called by buttons' OnClickButton 
    public void Clicked(string clickedTag)
    {
        if (clickedTag == "NEXT")
        {
            if (ps.GetTrial() > 0 && !ps.ChoiceMade()) return;

            //Debug.Log("nex~~~~~");
            //collect data
            if (ps.IsFinished())
            {
                SceneManager.LoadScene("FinalScene", LoadSceneMode.Single);
            }
            Debug.Log("Incrementing Trial");
            ps.IncTrial();

            //Debug.Log(string.Format("Starting trial {0} at {1}", ps.GetTrial(), Time.time));
            //Despawn current box
            this.GetComponent<DespawnObject>().buttonDespawn();
            for (int i = 0; i < choices.Count; i++)
            {
                if (choices[i].GetComponent<CustomTag>().getTag(0) != "NEXT")
                {
                    choices[i].GetComponent<Renderer>().material = noChoiceMat;
                }
                else
                {
                    choices[i].GetComponent<Renderer>().material = neutralMat;
                }
            }
            //Spawn in new box
            this.GetComponent<SpawnRandomBox>().spawn();
            firstChoice = true;
        }
        else
        {
            if (firstChoice == true)
            {
                //collect data
                if (ps.SetChoice(clickedTag))
                {
                    ps.GetDataFarmer().Save(new DFAnswerSelection());
                    //Debug.Log(string.Format("Answer selected: {0}", ps.GetLastChoice()));
                }

                firstChoice = false;
                GameObject[] currentObjs = GameObject.FindGameObjectsWithTag("Interactable Object");
                foreach (GameObject cube in currentObjs)
                {
                    string chosenTag = ParticipantStatus.GetInstance().GetCategory();
                    ParticipantStatus.GetInstance().SetChoice(chosenTag);

                    if (chosenTag == clickedTag)
                    {
                        for (int i = 0; i < choices.Count; i++)
                        {
                            if (choices[i].GetComponent<CustomTag>().getTag(0) != "NEXT")
                            {
                                if (choices[i].GetComponent<CustomTag>().getTag(0) != chosenTag)
                                {
                                    choices[i].GetComponent<Renderer>().material = neutralMat;
                                }
                                else
                                {
                                    choices[i].GetComponent<Renderer>().material = correctMat;
                                }
                            }
                            else
                            {
                                choices[i].GetComponent<Renderer>().material = nextMat;
                            }
                        }
                    }
                    else
                    {

                        for (int i = 0; i < choices.Count; i++)
                        {
                            if (choices[i].GetComponent<CustomTag>().getTag(0) != "NEXT")
                            {
                                if (choices[i].GetComponent<CustomTag>().getTag(0) != chosenTag)
                                {
                                    choices[i].GetComponent<Renderer>().material = neutralMat;
                                }
                                else
                                {
                                    choices[i].GetComponent<Renderer>().material = correctMat;
                                }
                                if (choices[i].GetComponent<CustomTag>().getTag(0) == clickedTag)
                                {
                                    choices[i].GetComponent<Renderer>().material = wrongMat;
                                }
                            }
                            else
                            {
                                choices[i].GetComponent<Renderer>().material = nextMat;
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #15
0
 // Use this for initialization
 void Start()
 {
     gameObject.GetComponent <InputField>().text = ParticipantStatus.GetInstance().GetParticipantAsString();
 }
 void Start()
 {
     ps = ParticipantStatus.GetInstance();
     ps.ResetCubes();
 }