public async void ArrowKeyPressed(bool rightArrowPressed)
    {
        if (!isRunning && isInRailsFoundQuestion)
        {
            isInRailsFoundQuestion = false;
            StudyTask t = tasks[currentChunkId][currentTaskInChunk];
            t.foundTargtDeliberately = rightArrowPressed; // right arrow: found target, left arrow: bumped into target
            targetAudioSource.Play();
            currentTaskId++;
            currentTaskInChunk++;

            if (currentTaskId % taskChunkSize != 0)
            {
                // next task of sequence
                NextTask();
            }
            else
            {
                // next chunk

                // after training phase don't show questionnaire
                if (currentChunkId == -1)
                {
                    speech.Speak("Training completed.", 1);
                    studyUIManager.ShowStartMenu();
                }
                else
                {
                    speech.Speak("Sequence completed. Please rate the statements on the screen.", 1);
                    studyUIManager.ShowQuestionnaire();
                }
            }
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// This method is invoked when the client selects a task
        /// </summary>
        /// <param name="data">A string array with the taskId at index 0</param>
        /// <returns>a string of the task name, task total length and task estimate in seconds, separated by commas</returns>
        public string Select(string taskId, string taskWasOpen)
        {
            int  id;
            bool taskOpen;

            if (int.TryParse(taskId, out id) && bool.TryParse(taskWasOpen, out taskOpen))
            {
                StudyTask task;
                var       service = CreateTasksWCFService();
                if (!taskOpen)
                {
                    task = new StudyTask(service, id);
                    task.TimeSpans.Add(new TaskTimeSpan(service, task, DateTime.Now));
                }
                else
                {
                    task = new StudyTask(service, id);
                    var openTimeSpan = task.OpenTimeSpan;
                    if (openTimeSpan != null)
                    {
                        openTimeSpan.End = DateTime.Now;
                    }
                }

                return(string.Join(",", task.Name, task.GetLength().ToStringInSeconds(), task.Estimate.ToStringInSeconds()));
            }
            return(0.ToString());
        }
Exemplo n.º 3
0
 public static StudyTaskService ToService(this StudyTask task)
 {
     return(new StudyTaskService()
     {
         Name = task.Name,
         Id = task.Id,
         UserId = task.UserId,
         Estimate = TimeSpan.FromTicks(task.Estimate)
     });
 }
        public void TaskRetrievalTest()
        {
            const string expected = "taskName";
            var          task     = CreateStudyTaskWithName(expected);

            StudyTaskCollection.Create(base.client).Add(task);

            task = new StudyTask(base.client, task.MessageObject.Id);
            Assert.AreEqual(expected, task.Name);
        }
        public void TaskRetrievalWithTimeSpansTest()
        {
            var task = CreateStudyTaskWithName("taskName");

            StudyTaskCollection.Create(base.client).Add(task);
            task.TimeSpans.Add(new TaskTimeSpan(base.client, task, DateTime.Now));

            int expectedTimeSpanCount = 1;

            task = new StudyTask(base.client, task.MessageObject.Id);
            Assert.AreEqual(expectedTimeSpanCount, task.TimeSpans.Count);
        }
    async public void NextTask()
    {
        Debug.Log("Task id " + currentTaskId);
        Debug.Log("Chunk id " + currentChunkId);

        // need to subtract taskChunkSize for the training block
        if (currentTaskId == taskCount - taskChunkSize)
        {
            Debug.Log("Finished study");
            Debug.Log(taskCount);
            speech.Speak("Well done, you've completed the user study. Thanks for participating!", 1);
            studyUIManager.FinishStudy();
        }
        else
        {
            StudyTask t = tasks[currentChunkId][currentTaskInChunk];
            Debug.Log("New task " + t.ToString());
            obstacleManager.DisableAll();
            PantoHandle handle = GameObject.Find("Panto").GetComponent <UpperHandle>();
            await Task.Delay(1000);

            await handle.MoveToPosition(t.startPos, 0.0005f, false);

            await speech.Speak("3, 2, 1, Go", 1);

            handle.Free();
            if (firstTrial)
            {
                // enable the walls of the scene after moving the handle for the first time
                //to make sure the handle is within the bounds of the room
                await obstacleManager.EnableWalls();

                firstTrial = false;
            }
            obstacleManager.ReEnableTarget(t.targetPos, new Vector3(t.targetSize, t.targetSize, t.targetSize));
            Debug.Log("Condition " + t.condition);
            if (t.guidesEnabled)
            {
                obstacleManager.ReEnableRails(t.targetPos, t.guideWidth, t.condition);
            }
            else
            {
                if (t.condition == "forcefield")
                {
                    obstacleManager.EnableForceField();
                }
            }

            startTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            isRunning = true;
        }
    }
 public void LogTimeToRail()
 {
     if (isRunning)
     {
         StudyTask t          = tasks[currentChunkId][currentTaskInChunk];
         long      timeToRail = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - startTime;
         // make sure to have a min time for the time to rail, otherwise the collision might be detected right when the rail is spawned
         if (t.timeToRail == -1 && timeToRail > minTimeToRail)
         {
             t.timeToRail = timeToRail;
         }
     }
 }
Exemplo n.º 8
0
        public void GetSubArrayWithMaxSumOfElements_SmokeTestWithAnotherParameters_ReturnsCorrectArray()
        {
            // Arrange
            var studyTask   = new StudyTask();
            var sourceArray = new int[] { -5, 20, -4, -10, -18 };

            // Act
            var resultArray = studyTask.GetSubArrayWithMaxSumOfElements(sourceArray);

            // Assert
            Assert.IsTrue(resultArray[0] == 20);
            Assert.IsTrue(resultArray[1] == -4);
        }
Exemplo n.º 9
0
        public TaskRequestDto(StudyTask task, ICollection<FieldType> visibleFieldTypes, int? userId = null)
        {
            var editableFields = new List<DataFieldDto>();

            foreach (var dataField in task.DataFields)
            {
                editableFields.Add(new DataFieldDto(dataField, userId));
            }

            var visibleFields = new List<DataFieldDto>();

            foreach (var dataType in visibleFieldTypes)
            {
                visibleFields.Add(new DataFieldDto(dataType, task.Paper));
            }

            IsDeliverable = task.IsEditable;
            TaskType = (Type) Enum.Parse(typeof (Type), task.TaskType.ToString());
            Id = task.ID;
            RequestedFields = editableFields.ToArray();
            VisibleFields = visibleFields.ToArray();

            if (task.TaskType == StudyTask.Type.Conflict)
            {
                //Creating the conflicting Data
                var conflictingData = new ConflictingDataDto[task.DataFields.Count][];

                //For each dataField
                    for (var d = 0; d < task.DataFields.Count; d++)
                    {
                        //Create new conflicting data
                        conflictingData[d] = new ConflictingDataDto[task.Users.Count];

                        //Add each users data and id to the conflicting data
                        for (var u = 0; u < task.DataFields[d].UserData.Count; u++)
                        {
                            var userData = task.DataFields[d].ConflictingData[u];
                            conflictingData[d][u] = new ConflictingDataDto
                            {
                                Data = userData.Data.Select(s => s.Value).ToArray(),
                                UserId = userData.UserId
                            };
                        }

                }

                ConflictingData = conflictingData;
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            StudyTask = await _context.StudyTask.FirstOrDefaultAsync(m => m.Id == id);

            if (StudyTask == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            StudyTask = await _context.StudyTask.FindAsync(id);

            if (StudyTask != null)
            {
                _context.StudyTask.Remove(StudyTask);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
 async public void StopTask()
 {
     //if Target detected collision ->
     if (isRunning)
     {
         targetAudioSource.Play();
         isRunning = false;
         StudyTask t = tasks[currentChunkId][currentTaskInChunk];
         t.time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - startTime;
         obstacleManager.DisableForceField();
         if (currentTaskId < numTrialsWithExplanation)
         {
             // only say this for the first two trials of the tutorial
             await speech.Speak("Did you find the target by intentionally approaching it or did you randomly bump into it? Press the right arrow key if you found it intentionally or the left arrow key if you bumped into it.", 1);
         }
         isInRailsFoundQuestion = true;
         Debug.Log("Task finished in " + t.time);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// This method is invoked when the client adds a task
        /// </summary>
        /// <param name="taskName">The name of the task</param>
        /// <param name="estimateString">String representation of the estimated for the new task</param>
        /// <returns>a string of the task id and task total length in seconds, separated by commas</returns>
        public string Add(string taskName, string estimateString)
        {
            int estimate;

            // Check the string for a valid task name
            if (int.TryParse(estimateString, out estimate))
            {
                string userId             = User.Identity.GetUserId();
                var    client             = CreateTasksWCFService();
                var    databaseConnection = StudyTaskCollection.FromDatabase(client, userId);
                var    task = new StudyTask(client, taskName, userId, TimeSpan.FromSeconds(estimate));
                databaseConnection.Add(task);


                var totalLength = task.GetLength();
                return(string.Join(",", task.Id, totalLength.ToStringInSeconds()));
            }
            return(0.ToString());
        }
 void ReadProtocol()
 {
     string[] records = csvFile.text.Split('\n');
     for (int i = 1; i < records.Length; i++)
     {
         string   record = records[i];
         string[] fields = record.Split(',');
         if (fields.Length <= 1)
         {
             continue;
         }
         if (userId == -1)
         {
             userId = int.Parse(fields[0]);
         }
         int     blockId   = int.Parse(fields[1]);
         int     taskId    = int.Parse(fields[2]);
         Vector3 targetPos = new Vector3(
             float.Parse(fields[5], System.Globalization.CultureInfo.InvariantCulture),
             0,
             float.Parse(fields[6], System.Globalization.CultureInfo.InvariantCulture));
         Vector3 startPos = new Vector3(
             float.Parse(fields[3], System.Globalization.CultureInfo.InvariantCulture),
             0,
             float.Parse(fields[4], System.Globalization.CultureInfo.InvariantCulture));
         string    condition     = fields[9];
         bool      guidesEnabled = condition == "8" || condition == "through";
         StudyTask t             = new StudyTask(userId, taskId, blockId, targetPos, startPos, 0.4f, guidesEnabled, condition, 1);
         if (tasks.ContainsKey(blockId))
         {
             tasks[blockId].Add(t);
         }
         else
         {
             tasks.Add(blockId, new List <StudyTask> {
                 t
             });
         }
         taskCount++;
     }
 }