Exemplo n.º 1
0
    public void AddDataPiece(float time, string currentLevel, string buttonPressed, bool correct, int inputsCount)
    {
        UserDataPiece dataPiece = new UserDataPiece();

        dataPiece.inputTime     = time;
        dataPiece.level         = currentLevel;
        dataPiece.buttonPressed = buttonPressed;
        string systemtime = System.DateTime.Now.ToString();

        dataPiece.date     = systemtime;
        dataPiece.correct  = (correct ? 1 : 0);
        dataPiece.n        = inputsCount;
        dataPiece.userName = GameManager.instance.userName;
        dataPiece.SetEpisode(GameManager.instance.episode);
        userDataPieces.Add(dataPiece);
        GameSaveManager.instance.SaveGame();
        UserDataExport datos = new UserDataExport();

        datos.Extime          = time;
        datos.Exlevel         = currentLevel;
        datos.ExbuttonPressed = buttonPressed;
        datos.Excorrect       = (correct ? 1 : 0);
        datos.Excount         = inputsCount;
        datos.Exusername      = GameManager.instance.userName;
        datos.Exepisode       = "One";
        datos.Exdate          = systemtime;
        //crear key unico
        System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
        int             cur_time   = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;

        datos.Key = cur_time.ToString();
        CSVManager.AppendToReport(ConvertDataPieceToStringArray(dataPiece));
        CSVManager.SubmitDatabase(datos);//modificado por mi
    }
Exemplo n.º 2
0
    private void SetOneBlock()
    {
        //혹시모르니 세팅시작할때 한번 비워주고 새로
        nearRandomValue.Clear();
        farRandomValue.Clear();
        rotationRandomValue.Clear();
        instructionPanel.SetActive(false);
        for (int i = 0; i < expRandomValue.NearPositionOffsetValues.Count; i++)
        {
            //랜덤한 index를 pop하는 식으로 랜덤값을 쓸거기때문에 한블럭을 시작할때마다 새로 복사해서 시작해야함, 원본을 지워버리면 이후에 못하기때문
            nearRandomValue.Add(expRandomValue.NearPositionOffsetValues[i]);
            farRandomValue.Add(expRandomValue.FarPositionOffsetValues[i]);
            rotationRandomValue.Add(expRandomValue.RotationOffsetValues[i]);
        }

        //한블럭 시작 초기화
        curExpCase = curExpFlow[ExperimentState.curBlockNum - 1];
        ExperimentState.curBlockDistance  = curExpCase.distance;
        ExperimentState.curBlockTechnique = curExpCase.technique;

        CSVManager.AppendToReport(CSVManager.GetReportLine("Block Start"));

        practiceCounter = 0;
        isPractice      = true;
        SetOnePractice();
    }
Exemplo n.º 3
0
 private void ReportPointerDown()
 {
     // 스마트폰에 가림막을 누르는 터치에대해서는 파일에 기록하지않기위해 if 문을 추가했음
     if (ExperimentState.curTrialPhase != TrialPhase.Null && guideChair.activeSelf)
     {
         CSVManager.AppendToReport(CSVManager.GetReportLine("press"));
     }
 }
Exemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     if (Time.time >= nextTime)
     {
         getposition();
         CSVManager.AppendToReport(GetReportLine());
         Debug.Log("<color=green>Report updated successfully!</color>");
         nextTime += interval;
     }
 }
Exemplo n.º 5
0
 static void DEV_AppendDefaultsToReport()
 {
     CSVManager.AppendToReport(new string[3]
     {
         Time.time.ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString()
     }
                               );
     EditorApplication.Beep();
 }
Exemplo n.º 6
0
    public void StartExperiment()
    {
        ExperimentState.participantNum = expCtrPanel.participantNumber;
        ExperimentState.curBlockNum    = expCtrPanel.blockNumber;
        turnOffDuringExperiment.SetActive(false);
        curExpFlow = expAllFlow[ExperimentState.participantNum - 1];

        CSVManager.AppendToReport(CSVManager.GetReportLine("Experiment Start"));

        SetOneBlock();
    }
Exemplo n.º 7
0
 static void AppendDefaultsToReport()
 {
     CSVManager.AppendToReport(
         new string[3]
     {
         "0",
         "200",
         "4"
     });
     EditorApplication.Beep();
     Debug.Log("<color=green>Report updated succesfully!</color>");
 }
Exemplo n.º 8
0
 static void DEV_AppendToReport()
 {
     CSVManager.AppendToReport(
         new string[5] {
         "Patient", Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
     }
         );
     EditorApplication.Beep();
 }
Exemplo n.º 9
0
    static void DEV_AppendDefaultsToReport()
    {
        CSVManager.AppendToReport(

            new string[3]
        {
            "john",
            Random.Range(0, 11).ToString(),
            Random.Range(0, 11).ToString()
        }
            );
        EditorApplication.Beep();
        Debug.Log("<color=green>Report updated successfully!</color>");
    }
Exemplo n.º 10
0
    public void AddDataPiece(float time, string currentLevel, string buttonPressed, bool correct, int inputsCount)
    {
        UserDataPiece dataPiece = new UserDataPiece();

        dataPiece.inputTime     = time;
        dataPiece.level         = currentLevel;
        dataPiece.buttonPressed = buttonPressed;
        dataPiece.date          = System.DateTime.Now.ToString();
        dataPiece.correct       = (correct ? 1 : 0);
        dataPiece.n             = inputsCount;
        dataPiece.userName      = GameManager.instance.userName;
        dataPiece.SetEpisode(GameManager.instance.episode);
        userDataPieces.Add(dataPiece);
        GameSaveManager.instance.SaveGame();
        CSVManager.AppendToReport(ConvertDataPieceToStringArray(dataPiece));
    }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        switch (gameState)
        {
        case GameState.StartSimulation:
        {
            currentSimulation = numSimulations;
            battle.StartBattle(GetSelectedCharA(), GetSelectedCharB());
            gameState = GameState.WaitSimulation;
            break;
        }

        case GameState.WaitSimulation:
        {
            battle.UpdateBattle();
            break;
        }

        case GameState.EndSimulation:
        {
            CSVManager.AppendToReport(battle.characterA, battle.characterB, numSimulations, winBattles);
            gameState = GameState.WaitResetSimulation;
            break;
        }

        case GameState.WaitResetSimulation:
        {
            // TODO: Button to reset simulation
            gameState = GameState.ResetSimulation;
            break;
        }

        case GameState.ResetSimulation:
        {
            ResetSimulation();
            break;
        }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
Exemplo n.º 12
0
 static void DEV_AppendDefaultsToReport()
 {
     CSVManager.AppendToReport(
         new string[11] {
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString(),
         Random.Range(0, 11).ToString()
     }
         );
     EditorApplication.Beep();
     Debug.Log("Report updated successfully!");
 }
Exemplo n.º 13
0
    // Update is called once per frame
    void FixedUpdate()

    {
        Wii.WakeUp();


        Wii.StartSearch();


        if (Measurement.WhetherStart == true)
        {
            CSVManager.reportFileName = PlayerPrefs.GetString("UserName") + "COPreport.csv";
            CSVManager.AppendToReport(
                new string[6] {
                PlayerPrefs.GetString("UserName"),
                Measurement.GlobalTotalForce.ToString(),
                Measurement.GlobalCOP.x.ToString(),
                Measurement.GlobalCOP.y.ToString(),
                Measurement.GlobalVelocity.x.ToString(),
                Measurement.GlobalVelocity.y.ToString()
            });
        }
    }
Exemplo n.º 14
0
    //연습모드
    private void SetOnePractice()
    {
        // SetOneTrial과 다른점은 랜덤값을 사용해도 리스트에서 삭제하지 않는다는점, 블럭종료까지 진행되는게 아니라 3회 후 바로 SetOneTrial실행으로 바로 이어진다는점, 끝내는 조건관련 변수들에 손대지않는다는점
        practiceCounter++;
        PV.RPC("RPC_OneTrialStart", RpcTarget.All); // trial 시작시마다 가림막 설치, 랜덤한 위치에 버튼생성을 위해 시작할때 신호를 보내줌
        manipChair.transform.localPosition = defaultManipChairPosition;
        manipChair.transform.localRotation = Quaternion.identity;

        ExperimentState.curTrialPhase = TrialPhase.RoughPlacement;

        // 랜덤 값 리스트에서 이번 Trial에 사용될 랜덤값 선정 실전과 다른점은 리스트에서 뽑아서 써도 삭제시키지 않는다는점
        System.Random random = new System.Random();
        int           index;

        if (ExperimentState.curBlockDistance == Distance.Near)
        {
            index = random.Next(nearRandomValue.Count);
            ExperimentState.curPositionOffset = nearRandomValue[index];
        }
        else
        {
            index = random.Next(farRandomValue.Count);
            ExperimentState.curPositionOffset = farRandomValue[index];
        }
        index = random.Next(rotationRandomValue.Count);
        ExperimentState.curRotationOffset = rotationRandomValue[index];

        // 배치와 돌리는 과정을 나눠서하기때문에 Que도 나눠서 두단계에 걸쳐서 줘야함, 여기서는 포지션 큐만, 로테이션은 상세배치 끝난후에
        guideChair.transform.localPosition = Vector3.zero;
        guideChair.transform.localRotation = Quaternion.identity;
        guideChair.transform.Translate(new Vector3(ExperimentState.curPositionOffset, 0, 0));

        // 테스트 할때는 주석처리하자
        guideChair.SetActive(false); // 스마트폰의 가림막을 1초 누르면 다시 킬거임

        CSVManager.AppendToReport(CSVManager.GetReportLine("Practice Trial Start"));
    }
Exemplo n.º 15
0
 public static void DEV_AppendSpecificsToReport(string[] strings)
 {
     CSVManager.AppendToReport(strings);
     EditorApplication.Beep();
 }
Exemplo n.º 16
0
 public static void DEV_AppendSpecificsToReport(string[] strings)
 {
     CSVManager.AppendToReport(strings);
     //EditorApplication.Beep();
     Debug.Log("<color=green>Specific data added succesfully!</color>");
 }
Exemplo n.º 17
0
    public void get_avg()
    {
        CSVManager.CreateReport1();
        //var dataset = Resources.Load<TextAsset>("W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv");
        var dataset   = File.ReadAllText(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv");
        var dataLines = dataset.Split(','); // Split also works with simple arguments, no need to pass char[]

        using (StreamWriter sw = File.AppendText(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report2.csv"))
        {
            for (int i = 0; i < dataLines.Length; i++)
            {
                var data = dataLines[i].Split(',');
                //string data1 = data;

                for (int d = 0; d < data.Length; d++)
                {
                    print(data[d]); // what you get is split sequential data that is column-first, then row
                                    //CSVManager.AppendToReport2(new string[]{
                                    //   data[i]

                    //data[d] += reportSeparator;

                    sw.WriteLine(data[d]);


                    //for(int k = 0; k < data.Length; k++)
                    //{
                    //  sw.WriteLine("," + data[d]);
                    //}
                    //sw.WriteLine(data[1]);
                    //sw.WriteLine(data[2]);
                    //sw.WriteLine(data[3]);
                }
            }
        }


        Avg_hips_x = "=AVERAGE(A2:A" + count + ")";
        Avg_hips_y = "=AVERAGE(B2:B" + count + ")";
        Avg_hips_z = "=AVERAGE(C2:C" + count + ")";

        Avg_Spine_x = "=AVERAGE(D2:D" + count + ")";
        Avg_Spine_y = "=AVERAGE(E2:E" + count + ")";
        Avg_Spine_z = "=AVERAGE(F2:F" + count + ")";

        Avg_Neck_x = "=AVERAGE(G2:G" + count + ")";
        Avg_Neck_y = "=AVERAGE(H2:H" + count + ")";
        Avg_Neck_z = "=AVERAGE(I2:I" + count + ")";

        Avg_Head_x = "=AVERAGE(J2:J" + count + ")";
        Avg_Head_y = "=AVERAGE(K2:K" + count + ")";
        Avg_Head_z = "=AVERAGE(L2:L" + count + ")";

        Avg_leftShoulder_x = "=AVERAGE(M2:M" + count + ")";
        Avg_leftShoulder_y = "=AVERAGE(N2:N" + count + ")";
        Avg_leftShoulder_z = "=AVERAGE(O2:O" + count + ")";

        Avg_RightShoulder_x = "=AVERAGE(P2:P" + count + ")";
        Avg_RightShoulder_y = "=AVERAGE(Q2:Q" + count + ")";
        Avg_RightShoulder_z = "=AVERAGE(R2:R" + count + ")";

        Avg_leftArm_x = "=AVERAGE(S2:S" + count + ")";
        Avg_leftArm_y = "=AVERAGE(T2:T" + count + ")";
        Avg_leftArm_z = "=AVERAGE(U2:U" + count + ")";

        Avg_leftForeArm_x = "=AVERAGE(V2:V" + count + ")";
        Avg_leftForeArm_y = "=AVERAGE(W2:W" + count + ")";
        Avg_leftForeArm_z = "=AVERAGE(X2:X" + count + ")";

        Avg_leftHand_x = "=AVERAGE(Y2:Y" + count + ")";
        Avg_leftHand_y = "=AVERAGE(Z2:Z" + count + ")";
        Avg_leftHand_z = "=AVERAGE(AA2:AA" + count + ")";

        Avg_RightArm_x = "=AVERAGE(AB2:AB" + count + ")";
        Avg_RightArm_y = "=AVERAGE(AC2:AC" + count + ")";
        Avg_RightArm_z = "=AVERAGE(AD2:AD" + count + ")";

        Avg_RightForeArm_x = "=AVERAGE(AE2:AE" + count + ")";
        Avg_RightForeArm_y = "=AVERAGE(AF2:AF" + count + ")";
        Avg_RightForeArm_z = "=AVERAGE(AG2:AG" + count + ")";

        Avg_RightHand_x = "=AVERAGE(AH2:AH" + count + ")";
        Avg_RightHand_y = "=AVERAGE(AI2:AI" + count + ")";
        Avg_RightHand_z = "=AVERAGE(AJ2:AJ" + count + ")";

        Avg_leftUpLeg_x = "=AVERAGE(AK2:AK" + count + ")";
        Avg_leftUpLeg_y = "=AVERAGE(AL2:AL" + count + ")";
        Avg_leftUpLeg_z = "=AVERAGE(AM2:AM" + count + ")";

        Avg_leftLeg_x = "=AVERAGE(AN2:AN" + count + ")";
        Avg_leftLeg_y = "=AVERAGE(AO2:AO" + count + ")";
        Avg_leftLeg_z = "=AVERAGE(AP2:AP" + count + ")";

        Avg_leftFoot_x = "=AVERAGE(AQ2:AQ" + count + ")";
        Avg_leftFoot_y = "=AVERAGE(AR2:AR" + count + ")";
        Avg_leftFoot_z = "=AVERAGE(AS2:AS" + count + ")";

        Avg_rightUpLeg_x = "=AVERAGE(AT2:AT" + count + ")";
        Avg_rightUpLeg_y = "=AVERAGE(AU2:AU" + count + ")";
        Avg_rightUpLeg_z = "=AVERAGE(AV2:AV" + count + ")";

        Avg_rightLeg_x = "=AVERAGE(AW2:AW" + count + ")";
        Avg_rightLeg_y = "=AVERAGE(AX2:AX" + count + ")";
        Avg_rightLeg_z = "=AVERAGE(AY2:AY" + count + ")";

        Avg_rightFoot_x = "=AVERAGE(AZ2:AZ" + count + ")";
        Avg_rightFoot_y = "=AVERAGE(BA2:BA" + count + ")";
        Avg_rightFoot_z = "=AVERAGE(BB2:BB" + count + ")";
        CSVManager.AppendToReport(
            new string[54] {
            Avg_hips_x,
            Avg_hips_y,
            Avg_hips_z,

            Avg_Spine_x,
            Avg_Spine_y,
            Avg_Spine_z,

            Avg_Neck_x,
            Avg_Neck_y,
            Avg_Neck_z,

            Avg_Head_x,
            Avg_Head_y,
            Avg_Head_z,

            Avg_leftShoulder_x,
            Avg_leftShoulder_y,
            Avg_leftShoulder_z,

            Avg_RightShoulder_x,
            Avg_RightShoulder_y,
            Avg_RightShoulder_z,

            Avg_leftArm_x,
            Avg_leftArm_y,
            Avg_leftArm_z,

            Avg_leftForeArm_x,
            Avg_leftForeArm_y,
            Avg_leftForeArm_z,

            Avg_leftHand_x,
            Avg_leftHand_y,
            Avg_leftHand_z,

            Avg_RightArm_x,
            Avg_RightArm_y,
            Avg_RightArm_z,

            Avg_RightForeArm_x,
            Avg_RightForeArm_y,
            Avg_RightForeArm_z,

            Avg_RightHand_x,
            Avg_RightHand_y,
            Avg_RightHand_z,

            Avg_leftUpLeg_x,
            Avg_leftUpLeg_y,
            Avg_leftUpLeg_z,

            Avg_leftLeg_x,
            Avg_leftLeg_y,
            Avg_leftLeg_z,

            Avg_leftFoot_x,
            Avg_leftFoot_y,
            Avg_leftFoot_z,

            Avg_rightUpLeg_x,
            Avg_rightUpLeg_y,
            Avg_rightUpLeg_z,

            Avg_rightLeg_x,
            Avg_rightLeg_y,
            Avg_rightLeg_z,

            Avg_rightFoot_x,
            Avg_rightFoot_y,
            Avg_rightFoot_z,
        }
            );
        //Debug.Log("<color=green>Average updated successfully!</color>");
        //var textReader = new StreamReader("W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv");
        //var csv = new CsvReader(textReader, System.Globalization.CultureInfo.CreateSpecificCulture("enUS"));
        //var records = csv.GetRecords<report>();
        // var average = records.Average(_ => _.hips_x);
        // print("avs is: " + average);

        /* var reader = new StreamReader(File.OpenRead(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv"));
         * List<string> listA = new List<string>();
         * List<string> listB = new List<string>();
         * while (!reader.EndOfStream)
         * {
         * var line = reader.ReadLine();
         * var values = line.Split(';');
         *
         *   listA.Add(values[0]);
         *   //listB.Add(values[1]);
         *
         * }
         * int headerRow = 1;
         * foreach (var values in listA.Skip(headerRow))
         * {
         *   Debug.Log(values);
         * }*/

        /*var contents = File.ReadAllText(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv").Split('\n');
         * var csv = from line in contents
         *        select line.Split(',').ToArray();
         *
         * int headerRows = 1;
         * foreach (var row in csv.Skip(headerRows)
         *  .TakeWhile(r => r.Length > 1 && r.Last().Trim().Length > 0))
         * {
         *  string zerothColumnValue = row[0]; // leftmost column
         *  var firstColumnValue = row[1];
         * }*/



        //}
    }
Exemplo n.º 18
0
    void DEV_AppendDefaultsToReport()
    {
        print(eulerAngrightFoot_x.ToString());

        CSVManager.AppendToReport(
            new string[54] {
            eulerAnghips_x.ToString(),
            eulerAnghips_y.ToString(),
            eulerAnghips_z.ToString(),

            eulerAngSpine_x.ToString(),
            eulerAngSpine_y.ToString(),
            eulerAngSpine_z.ToString(),

            eulerAngNeck_x.ToString(),
            eulerAngNeck_y.ToString(),
            eulerAngNeck_z.ToString(),

            eulerAngHead_x.ToString(),
            eulerAngHead_y.ToString(),
            eulerAngHead_z.ToString(),

            eulerAngleftShoulder_x.ToString(),
            eulerAngleftShoulder_y.ToString(),
            eulerAngleftShoulder_z.ToString(),

            eulerAngRightShoulder_x.ToString(),
            eulerAngRightShoulder_y.ToString(),
            eulerAngRightShoulder_z.ToString(),

            eulerAngleftArm_x.ToString(),
            eulerAngleftArm_y.ToString(),
            eulerAngleftArm_z.ToString(),

            eulerAngleftForeArm_x.ToString(),
            eulerAngleftForeArm_y.ToString(),
            eulerAngleftForeArm_z.ToString(),

            eulerAngleftHand_x.ToString(),
            eulerAngleftHand_y.ToString(),
            eulerAngleftHand_z.ToString(),

            eulerAngRightArm_x.ToString(),
            eulerAngRightArm_y.ToString(),
            eulerAngRightArm_z.ToString(),

            eulerAngRightArm_x.ToString(),
            eulerAngRightArm_y.ToString(),
            eulerAngRightArm_z.ToString(),

            eulerAngRightHand_x.ToString(),
            eulerAngRightHand_y.ToString(),
            eulerAngRightHand_z.ToString(),

            eulerAngleftUpLeg_x.ToString(),
            eulerAngleftUpLeg_y.ToString(),
            eulerAngleftUpLeg_z.ToString(),

            eulerAngleftLeg_x.ToString(),
            eulerAngleftLeg_y.ToString(),
            eulerAngleftLeg_z.ToString(),

            eulerAngleftFoot_x.ToString(),
            eulerAngleftFoot_y.ToString(),
            eulerAngleftFoot_z.ToString(),

            eulerAngrightUpLeg_x.ToString(),
            eulerAngrightUpLeg_y.ToString(),
            eulerAngrightUpLeg_z.ToString(),

            eulerAngrightLeg_x.ToString(),
            eulerAngrightLeg_y.ToString(),
            eulerAngrightLeg_z.ToString(),

            eulerAngrightFoot_x.ToString(),
            eulerAngrightFoot_y.ToString(),
            eulerAngrightFoot_z.ToString()
        }
            );
        Debug.Log("<color=green>Report updated successfully!</color>");
    }
Exemplo n.º 19
0
    //한블럭 10회 수행
    private void SetOneTrial()
    {
        ExperimentState.curTrialNum = 11 - rotationRandomValue.Count;
        PV.RPC("RPC_OneTrialStart", RpcTarget.All); // trial 시작시마다 가림막 설치, 랜덤한 위치에 버튼생성을 위해 시작할때 신호를 보내줌
        manipChair.transform.localPosition = defaultManipChairPosition;
        manipChair.transform.localRotation = Quaternion.identity;

        // Trial 10번하면 새로운 의자 생성을 멈춤, 설문시간을 가진후 다시 시작을 누르면 다음 Block을 실행 : 어느경우에느 사용되는 rotation random 갯수로, 거리는 near, far 경우가 갈림
        if (ExperimentState.curTrialNum > 10)
        {
            ExperimentState.curBlockDistance  = Distance.Null;
            ExperimentState.curBlockTechnique = Technique.Null;
            ExperimentState.curTrialNum       = -1;
            ExperimentState.curTrialPhase     = TrialPhase.Null;
            ExperimentState.curPositionOffset = -1;
            ExperimentState.curRotationOffset = -1;

            if (ExperimentState.curBlockNum == 6)
            {
                // 실험 종료
                ExperimentState.curBlockDistance  = Distance.Null;
                ExperimentState.curBlockTechnique = Technique.Null;
                ExperimentState.curTrialNum       = -1;
                ExperimentState.curTrialPhase     = TrialPhase.Null;
                ExperimentState.curPositionOffset = -1;
                ExperimentState.curRotationOffset = -1;
                CSVManager.AppendToReport(CSVManager.GetReportLine("Block End"));
                CSVManager.AppendToReport(CSVManager.GetReportLine("Experiment End"));
                instruction.SetText($"<size=35><b>All trials are over</b></size>\n\nPlease call coordinator and fill out the questionnaire.");
                nextBlockBtn.SetActive(false);
            }
            else if (ExperimentState.curBlockNum < 6)
            {
                // Block블록 종료
                ExperimentState.curBlockDistance  = Distance.Null;
                ExperimentState.curBlockTechnique = Technique.Null;
                ExperimentState.curTrialNum       = -1;
                ExperimentState.curTrialPhase     = TrialPhase.Null;
                ExperimentState.curPositionOffset = -1;
                ExperimentState.curRotationOffset = -1;
                CSVManager.AppendToReport(CSVManager.GetReportLine("Block End"));
                instruction.SetText($"<size=35><b>Block{ExperimentState.curBlockNum} is over</b></size>\n\nPlease call coordinator and fill out the questionnaire.");
                ExperimentState.curBlockNum++;
            }
            instructionPanel.SetActive(true);
            return;
        }

        // 한 trial의 첫 모드는 항상 시선으로 배치로 시작
        ExperimentState.curTrialPhase = TrialPhase.RoughPlacement;

        // 랜덤 값 리스트에서 이번 Trial에 사용될 랜덤값 선정
        System.Random random = new System.Random();
        int           index;

        if (ExperimentState.curBlockDistance == Distance.Near)
        {
            index = random.Next(nearRandomValue.Count);
            ExperimentState.curPositionOffset = nearRandomValue[index];
            nearRandomValue.RemoveAt(index);
        }
        else
        {
            index = random.Next(farRandomValue.Count);
            ExperimentState.curPositionOffset = farRandomValue[index];
            farRandomValue.RemoveAt(index);
        }
        index = random.Next(rotationRandomValue.Count);
        ExperimentState.curRotationOffset = rotationRandomValue[index];
        rotationRandomValue.RemoveAt(index);

        // 배치와 돌리는 과정을 나눠서하기때문에 Que도 나눠서 두단계에 걸쳐서 줘야함, 여기서는 포지션 큐만, 로테이션은 상세배치 끝난후에
        guideChair.transform.localPosition = Vector3.zero;
        guideChair.transform.localRotation = Quaternion.identity;
        guideChair.transform.Translate(new Vector3(ExperimentState.curPositionOffset, 0, 0));

        // 테스트 할때는 주석처리하자
        guideChair.SetActive(false); // 스마트폰의 가림막을 1초 누르면 다시 킬거임

        CSVManager.AppendToReport(CSVManager.GetReportLine("Trial Start"));
    }
    // All input byte data cleaning, escape sequence addition, etc.
    public void GetThePacket(byte[] dataPacket)
    {
        packet = dataPacket;
        timer  = Mathf.Round(Time.time * 1000f) / 1000f;
        //Debug.Log(timer);

        // According to relevant bytes as ordered in the incoming packet
        // If no escape sequence involved, byte number 2,3,4,5 are required to be extracted in my case, could be different per device/byte sequence
        if (!(packet[2] == 125 | packet[3] == 125 | packet[4] == 125 | packet[5] == 125))
        {
            abdHighByte   = packet[2];
            abdLowByte    = packet[3];
            chestHighByte = packet[4];
            chestLowByte  = packet[5];
        }

        // Next 4 if conditions are for escape sequence handling. Comments in the first if loop are relevant to all others.
        if (packet[2] == 125)
        {
            temp        = packet[3].ToString("X"); // Hex value of the byte from which the required data needs to be retrieved
            abdHighByte = packet[3] ^ 32;          // To get back the value that caused the escape sequence to occur. Byte 2 is replaced by an escape value, which shifts the corresponding values one place ahead.

            /* Debug.Log("TEMP: " + temp);
             * Debug.Log("ABD HIGH BYTE:" + abdHighByte);*/
            abdLowByte    = packet[4];      // Abd low byte then becomes packet[4] and so on..
            chestHighByte = packet[5];
            chestLowByte  = packet[6];
        }

        if (packet[3] == 125)
        {
            abdHighByte = packet[2];
            temp        = packet[4].ToString("X");
            abdLowByte  = packet[4] ^ 32;

            /*Debug.Log("TEMP: " + temp);
             * Debug.Log("ABD LOW BYTE:" + abdLowByte);*/
            chestHighByte = packet[5];
            chestLowByte  = packet[6];
        }

        if (packet[4] == 125)
        {
            abdHighByte   = packet[2];
            abdLowByte    = packet[3];
            chestHighByte = packet[5] ^ 32;
            temp          = packet[5].ToString("X");

            /*Debug.Log("TEMP: " + temp);
             * Debug.Log("CHEST HIGH BYTE:" + chestHighByte);*/
            chestLowByte = packet[6];
        }

        if (packet[5] == 125)
        {
            abdHighByte   = packet[2];
            abdLowByte    = packet[3];
            chestHighByte = packet[4];
            chestLowByte  = packet[6] ^ 32;
            temp          = packet[6].ToString("X");

            /*Debug.Log("TEMP: " + temp);
             * Debug.Log("CHEST LOW BYTE:" + chestLowByte);*/
        }

        // Once escape sequence handling is done, set the integer values by combining the bytes:
        if (abdHighByte > 0 & chestHighByte > 0)
        {
            abdBreathValue = abdLowByte + (abdHighByte * 256);
            chBreathValue  = chestLowByte + (chestHighByte * 256);
        }

        // Send relevant data to csv file handler
        CSVManager.AppendToReport(GetReportLine());
    }
    /// <summary>Tulis hasil pertandingan pada file .csv</summary>
    private void WriteReport(bool whiteWin, bool blackWin)
    {
        // write for white
        string color  = "White";
        string versus = GetAIName(false) + " " + GameState.blackSearchDepth.ToString();
        string status = "";

        if (whiteWin && !blackWin)
        {
            status = "Win";
        }
        else if (!whiteWin && blackWin)
        {
            status = "Lose";
        }
        else
        {
            status = "Draw";
        }

        string notes = "-";

        if (status == "Draw")
        {
            if (GameState.drawVariance == GameState.DrawVariance.StaleMate)
            {
                notes = "Stalemate";
            }
            else if (GameState.drawVariance == GameState.DrawVariance.PerpetualCheck)
            {
                notes = "Perpetual Check";
            }
            else if (GameState.drawVariance == GameState.DrawVariance.ThreefoldRepetition)
            {
                notes = "Threefold Repetition";
            }
            else if (GameState.drawVariance == GameState.DrawVariance.NotEnoughMaterials)
            {
                notes = "Not Enough Materials";
            }
        }

        CSVManager.AppendToReport(
            true,
            new string[9] {
            color,
            versus,
            GameState.whiteAvgTime.ToString(),
            GameState.whiteAvgNodes.ToString(),
            GameState.whiteTotalTime.ToString(),
            GameState.whiteTotalNodes.ToString(),
            GameState.totalTurn.ToString(),
            status,
            notes
        }
            );


        // write for black
        color  = "Black";
        versus = GetAIName(true) + " " + GameState.whiteSearchDepth.ToString();
        if (whiteWin && !blackWin)
        {
            status = "Lose";
        }
        else if (!whiteWin && blackWin)
        {
            status = "Win";
        }
        else
        {
            status = "Draw";
        }

        CSVManager.AppendToReport(
            false,
            new string[9] {
            color,
            versus,
            GameState.blackAvgTime.ToString(),
            GameState.blackAvgNodes.ToString(),
            GameState.blackTotalTime.ToString(),
            GameState.blackTotalNodes.ToString(),
            GameState.totalTurn.ToString(),
            status,
            notes
        }
            );
    }
Exemplo n.º 22
0
 // pointer up 마다 호출
 // 한번의 trial에는 3가지의 페이즈가 있음, 사용자 입력때마다 상태체크 or 정답체크하는 파트, 특정상태 or 정답이면 상호작용모드만 바꿔주면 된다.
 public void PhaseCheck()
 {
     if (ExperimentState.curTrialPhase == TrialPhase.RoughPlacement)
     {
         // 그냥 시선배치니까 어느정도 근처에 배치되면 ok
         float distance = Vector3.Distance(guideChair.transform.position, manipChair.transform.position);
         if (distance < 2f)
         {
             CSVManager.AppendToReport(CSVManager.GetReportLine("correct", distance));
             ExperimentState.curTrialPhase = TrialPhase.FinePlacement;
         }
     }
     else if (ExperimentState.curTrialPhase == TrialPhase.FinePlacement)
     {
         // 정답체크해서 맞으면 각도모드로 바꿔주고 아니면 말고
         float distance = Vector3.Distance(guideChair.transform.position, manipChair.transform.position);
         // 정답일때
         if (distance < 0.15f)
         {
             CSVManager.AppendToReport(CSVManager.GetReportLine("correct", distance));
             System.Random random = new System.Random();
             guideChair.transform.localRotation = Quaternion.identity;
             if (random.Next(2) == 0)
             {
                 guideChair.transform.Rotate(new Vector3(0, ExperimentState.curRotationOffset, 0));
             }
             else
             {
                 guideChair.transform.Rotate(new Vector3(0, -ExperimentState.curRotationOffset, 0));
             }
             ExperimentState.curTrialPhase = TrialPhase.Rotation;
         }
         else
         {
             //정답은 아닌데 화면에서 손 땟을때
             CSVManager.AppendToReport(CSVManager.GetReportLine("release", distance));
         }
     }
     else if (ExperimentState.curTrialPhase == TrialPhase.Rotation)
     {
         float angleGap = Vector3.Angle(guideChair.transform.forward, manipChair.transform.forward);
         // 정답체크해서 맞으면 다음 trial 호출 (세번째 페이즈까지 완료하면 다음 trial 호출)
         if (angleGap < 8f)
         {
             // 정답
             CSVManager.AppendToReport(CSVManager.GetReportLine("correct", angleGap));
             if (practiceCounter < practiceTimes)
             {
                 CSVManager.AppendToReport(CSVManager.GetReportLine("Practice Trial End"));
                 SetOnePractice();
             }
             else
             {
                 //연습 3회 한 후에는 정상모드로 돌입 (practiceCounter가 3일때 부터), isPractice는 Practice 끝남을 기록하는 동시에 SetOneTrial실행으로 바꿔줘야하기때문에 필요
                 if (isPractice)
                 {
                     CSVManager.AppendToReport(CSVManager.GetReportLine("Practice Trial End"));
                     isPractice = false;
                 }
                 else
                 {
                     CSVManager.AppendToReport(CSVManager.GetReportLine("Trial End"));
                 }
                 SetOneTrial();
             }
         }
         else
         {
             // 정답아닌데 손땟을때
             CSVManager.AppendToReport(CSVManager.GetReportLine("release", angleGap));
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        #region ObjectLocations
        //update locations of all objects
        Target.transform.position   = new Vector3(TX, CoM.transform.position.y, TZ) + Push_up;
        StartBox.transform.position = new Vector3(SX, CoM.transform.position.y, SZ) + Push_up;
        Cursorloc         = CoM.transform.position + Push_Forward + Push_up;
        Cursorloc_w_shift = Cursorloc + Tru_shift;
        //Calculate distances and radii that assist with when visual feedback is given
        Rad_Dist = Mathf.Abs(Vector3.Distance(StartBox.transform.position, Target.transform.position));
        Vector3 Rad_Vec = Target.transform.position - StartBox.transform.position;

        //Shift_Dist = Mathf.Abs(Vector3.Distance(Cursor.transform.position, StartBox.transform.position));

        Rad_Min = Rad_Dist * .20f;
        Rad_Max = Rad_Dist * .70f;
        //Create a noise vector that is added to the position of the cursor
        Noise_vec = new Vector3(CurrentDist[Random.Range(0, 1999)], 0, CurrentDist[Random.Range(0, 1999)]);
        Cursor.transform.position = Cursorloc;
        Vector3 Curs_Vec = Cursor.transform.position - StartBox.transform.position;
        //Theta = Vector3.Angle(Cursor.transform.position - StartBox.transform.position, Target.transform.position - StartBox.transform.position);
        //Debug.Log("Theta is "  + Theta + " Rad_Min is " + Rad_Min + " Rad_Max is " + Rad_Max + "Shift_Dist is " + Shift_Dist + "Rad_Dist is " + Rad_Dist + StartBox.transform.position + Target.transform.position + Cursor.transform.position);


        //StartDist is the distance from the cursor to the startbox.  this is used when determining when participants can see the cursor
        StartDist = Mathf.Abs(Vector3.Distance(Cursor.transform.position, StartBox.transform.position));
        #endregion

        #region Visibility Shift and Noise
        //The startbox is set to be located where the CoM cursor is located before a trial begins.Once the cursor leaves the startbox,
        //it is occluded from vision and the shift is added to the cursor location

        if (StartDist > SB_RangeX)
        {
            rend.enabled = false;
            Cursor.transform.position = Cursorloc + Tru_shift + Noise_vec;
            Theta      = Vector3.Angle(Cursor.transform.position - StartBox.transform.position, Target.transform.position - StartBox.transform.position);
            Shift_Dist = Mathf.Abs(Vector3.Distance(Cursor.transform.position, StartBox.transform.position));
            //This if statement allows visual feedback while the cursor is in the middle % 10 of the movement between start and target
            if ((Shift_Dist > Rad_Min) && (Shift_Dist < Rad_Max) && Theta < 45f)
            {
                Cursor.transform.position = Cursorloc + Tru_shift + Noise_vec;

                rend.enabled = true;
            }
        }
        #endregion



        //This statement exports the study data at the moment that the button is clicked to a csv with the title report
        if (SteamVR_Actions._default.Select.GetStateUp(SteamVR_Input_Sources.Any))
        {
            CSVManager.AppendToReport(GetReportLine());
            Debug.Log("Report updated successfully!");
        }
        if (SteamVR_Actions._default.Select.GetStateUp(SteamVR_Input_Sources.Any) && Noise == 0)
        {
            //Transform CursorTransform = Cursor_FB.transform;
            Cursor_FB.transform.position = Cursorloc_w_shift;
            Feedback = true;
        }

        if (Feedback == true)
        {
            FB_rend.enabled = true;
        }
        if (Feedback == false)
        {
            FB_rend.enabled = false;
        }
    }