Exemplo n.º 1
0
    IEnumerator RunExperiment()
    {
        while (!isDone)
        {
            SetText("Querying for next trial");
            yield return(StartCoroutine(client.Ask()));

            Debug.Log(trialNum);
            config = client.GetConfig();

            SetText("Now presenting stimulus.");

            yield return(StartCoroutine(PresentStimulus(config)));

            SetText("Was it visible? (Y/N)");

            yield return(StartCoroutine(LogUserInput()));


            if (trialNum == (totalTrials - 1))
            {
                SetText("Experiment complete");
                isDone = true;
                break;
            }

            trialNum++;
        }
        yield return(0);
    }
Exemplo n.º 2
0
    public IEnumerator SpawnSliders()
    {
        QueryEnabled(false);
        //Get the current config with n parameters
        yield return(StartCoroutine(client.Params()));

        //initParams = new TrialConfig();
        //initParams.Add("Dimension 1", new List<float>() { 0.0f });
        initParams = client.GetConfig(version: "0.0");
        if (!initialized)
        {
            foreach (KeyValuePair <string, List <float> > entry in initParams)
            {
                string     name      = entry.Key;
                float      min       = entry.Value[0];
                float      max       = entry.Value[1];
                GameObject sliderObj = Instantiate(sliderPrefab, canvasGroup.transform.position, Quaternion.identity, canvasGroup.transform);
                sliderObj.transform.parent = xslidergroup.transform;
                ModelSlider slider = sliderObj.GetComponent <ModelSlider>();
                slider.InitSlider(min, max, name, false);
                slider.SetQueryModel(this);
                xSliders.Add(slider);
            }
        }
        //Spawn final slider and query twice for its limits

        yield return(StartCoroutine(client.Query(QueryType.max)));

        QueryMessage m = client.GetQueryResponse();

        maxY = m.y;
        yield return(StartCoroutine(client.Query(QueryType.min)));

        m    = client.GetQueryResponse();
        minY = m.y;

        string nameY = yAxisName;

        //Spawn + initialize slider, if necessary.
        GameObject ySliderObj;

        if (!initialized)
        {
            ySliderObj = Instantiate(sliderPrefab, canvasGroup.transform.position + new Vector3(-1.0f, 0.5f), Quaternion.identity, canvasGroup.transform);
            RectTransform rt = ySliderObj.GetComponent <RectTransform>();
            rt.localScale *= 1.25f;
            rt.anchorMax   = new Vector2(.9f, 0.55f);
            rt.anchorMin   = new Vector2(.9f, 0.55f);
            rt.pivot       = new Vector2(1f, 0.5f);
            ySlider        = ySliderObj.GetComponent <ModelSlider>();
            ySlider.SetQueryModel(this);
            ySlider.DisableLockToggle();
        }

        //ySlider.InitSlider(0, 3.4567f, nameY, true);
        ySlider.InitSlider(minY, maxY, nameY, true);
        StartCoroutine(ComputeYFromModel());
        initialized = true;
    }
    IEnumerator RunExperiment()
    {
        while (!isDone)
        {
            Debug.Log("trial# " + trialNum + " strat " + currentStrat + " strat's trial# " + AEPsychStrats[currentStrat].currentTrial);

            SetText("Querying for next trial");
            yield return(StartCoroutine(client.Ask()));

            config = client.GetConfig();

            SetText("Now presenting stimulus.");

            yield return(StartCoroutine(PresentStimulus(config)));

            SetText("Was it visible? (Y/N)");

            yield return(StartCoroutine(LogUserInput()));

            //check if strat or experiment is done
            if (AEPsychStrats[currentStrat].currentTrial == (totalTrials - 1))
            {
                SetText("Strat is complete.");
                AEPsychStrats[currentStrat].isDone = true;
                if (checkFinished())
                {
                    SetText("Experiment complete");
                    isDone = true;
                    break;
                }
            }

            AEPsychStrats[currentStrat].currentTrial++;
            trialNum++;

            //in this example, switch every 5 trials
            if (AEPsychStrats[currentStrat].currentTrial % 5 == 4)
            {
                currentStrat = (currentStrat + 1) % numStrats;
                while (AEPsychStrats[currentStrat].isDone)
                {
                    currentStrat = (currentStrat + 1) % numStrats;
                }
                Debug.Log("switched to strat " + currentStrat);
                yield return(StartCoroutine(client.Resume(AEPsychStrats[currentStrat].stratId)));
            }
        }
        yield return(0);
    }