/// <summary> /// Start a review stage by generating review tasks. /// The tasks that can be automatically filled out by the TaskManager will be validated by the TaskManager. /// Remove the excluded items from the study. If then no tasks are left, we finish the conflict phase to go directly to the next stage. /// </summary> /// <param name="study">study to begin review stage on</param> /// <returns></returns> private IEnumerable<StudyTask> StartReviewPhase(Study study) { //Find the current stage var stage = study.CurrentStage(); stage.CurrentTaskType = StudyTask.Type.Review; //Find the reviewers var reviewers = stage.Users.Where(u => u.StudyRole == UserStudies.Role.Reviewer).Select(u => u.User); //Generate the tasks var reviewTasks = _taskManager.GenerateReviewTasks(study.Items, stage.Criteria).ToList(); //Autoexlcuded items that have been filled out var excludedItems = _taskManager.GetExcludedItems(reviewTasks, stage.Criteria).ToList(); //Remove the excluded items from the study, and move to next stage study.Items.RemoveAll(i => excludedItems.Contains(i)); //Distribute the tasks var tasks = _taskManager.Distribute(reviewers, stage.DistributionRule, _taskManager.GenerateReviewTasks(study.Items, stage.Criteria)).ToList(); //Set the tasks in the stage to the reviewTasks stage.Tasks = tasks.ToList(); if (!tasks.Any()) { FinishConflictPhase(study); } return tasks; }
/// <summary> /// Start a conflict stage. Validation tasks based on the existing conflicting tasks. /// </summary> /// <param name="study">Study to start conflict stage on</param> /// <returns></returns> private IEnumerable<StudyTask> StartConflictPhase(Study study) { var stage = study.CurrentStage(); var tasks = stage.Tasks.Where(t => t.ContainsConflictingData()); var validators = stage.Users.Where(u => u.StudyRole == UserStudies.Role.Validator).Select(u => u.User); //Update stage to start the validations and generate the validation tasks stage.CurrentTaskType = StudyTask.Type.Conflict; var validationTasks = _taskManager.GenerateValidationTasks(tasks); //Always distribute validation tasks with no overlap var distributedTasks = _taskManager.Distribute(validators, Stage.Distribution.NoOverlap, validationTasks).ToList(); stage.Tasks.AddRange(distributedTasks); return distributedTasks; }
/// <summary> /// Conclude a review stage. If no more validation tasks, finish the conflictStage /// </summary> /// <param name="study"></param> private void FinishReviewPhase(Study study) { var currentStage = study.CurrentStage(); //Start the validation phase and check if any tasks have been generated var validationTasks = StartConflictPhase(study).ToList(); if (!validationTasks.Any()) { //Finish the phase if no validation tasks FinishConflictPhase(study); } }
/// <summary> /// Make a stage transition, based on the current task.Type /// </summary> /// <param name="study">Study to switch stage in</param> private void MoveToNextPhase(Study study) { var currentStage = study.CurrentStage(); switch (currentStage.CurrentTaskType) { case StudyTask.Type.Review: FinishReviewPhase(study); break; case StudyTask.Type.Conflict: FinishConflictPhase(study); break; default: throw new ArgumentOutOfRangeException(); } _studyStorageManager.Update(study); }
/// <summary> /// Finish a conflict stage. By validating the tasks and remove the excluded items from the study. /// Start a new review stage if the study is not finished /// </summary> /// <param name="study"></param> private void FinishConflictPhase(Study study) { var currentStage = study.CurrentStage(); var tasks = currentStage.Tasks; var criteria = currentStage.Criteria; //If there's any validation tasks we validate them if (tasks.Any()) { var excludedItems = _taskManager.GetExcludedItems(tasks, criteria); //Remove the excluded items from the study study.Items.RemoveAll(i => excludedItems.Contains(i)); } //move to the next stage study.MoveToNextStage(); if (!study.IsFinished) { StartReviewPhase(study); } }