Пример #1
0
 /// <summary>
 /// Retrieve all userIds working on the study
 /// </summary>
 /// <param name="study"></param>
 /// <returns></returns>
 private int[] GetUserIDs(Study study)
 {
     return study.Team.Users.Select(u => u.ID).ToArray();
 }
Пример #2
0
        /// <summary>
        /// Retrieve the current stage of the study
        /// </summary>
        /// <param name="study"></param>
        /// <returns></returns>
        private Stage GetCurrentStage(Study study)
        {
            Stage currentStage = null;

            foreach (var stage in study.Stages)
            {
                if (stage.IsCurrentStage)
                {
                    currentStage = stage;
                    break;
                }
            }
            return currentStage;
        }
Пример #3
0
        /// <summary>
        /// Update a study
        /// </summary>
        /// <param name="study"></param>
        /// <returns></returns>
        public bool Update(Study study)
        {
            var returnValue = _studyRepo.Update(study);

            return returnValue;
        }
Пример #4
0
        /// <summary>
        /// Retrieve an array of stageOverviews
        /// </summary>
        /// <param name="study"></param>
        /// <returns></returns>
        private StageOverviewDto[] GetStages(Study study)
        {
            var numbOfStages = study.Stages.Count();
            var stageOverview = new StageOverviewDto[numbOfStages];

            for (var i = 0; i < numbOfStages; i++)
            {
                stageOverview[i] = new StageOverviewDto();
                stageOverview[i].Name = study.Stages.ToArray()[i].Name;
                stageOverview[i].CompletedTasks = GetCompletedTasks(study.Stages.ToArray()[i]);
                stageOverview[i].IncompleteTasks = GetIncompleteTasks(study.Stages.ToArray()[i]);
            }
            return stageOverview;
        }
 /// <summary>
 /// Start the study by starting a review stage
 /// </summary>
 /// <param name="study">Study to start</param>
 public void ExecuteStudy(Study study)
 {
     StartReviewPhase(study);
 }
Пример #6
0
        /// <summary>
        /// Store a study in the repository
        /// </summary>
        /// <param name="study"></param>
        /// <returns></returns>
        public int Save(Study study)
        {
            var returnValue = _studyRepo.Create(study);

            return returnValue;
        }
        /// <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>
        /// 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>
        /// 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);
        }
Пример #10
0
        /// <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);
            }
        }
Пример #11
0
        /// <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);
            }
        }
Пример #12
0
        /// <summary>
        /// Convert a studyDTO to a study object
        /// </summary>
        /// <param name="studyDto">DTO to be converted</param>
        /// <returns></returns>
        private Study ConvertStudy(StudyDto studyDto)
        {
            var study = new Study
            {
                IsFinished = false,
                Name = studyDto.Name,
                Team = _teamStorage.GetTeam(studyDto.Team.Id),
                Items = new List<Item>(),
                Stages = new List<Stage>()
            };
            //Parse items
            var parser = new BibTexParser(new ItemValidator());
            var fileString = Encoding.Default.GetString(studyDto.Items);
            study.Items = parser.Parse(fileString);

            var firstStage = true;

            foreach (var stageDto in studyDto.Stages)
            {
                var stage = CreateStage(stageDto);

                study.Stages.Add(stage);

                if (firstStage)
                {
                    stage.IsCurrentStage = true;
                }

                firstStage = false;
            }
            return study;
        }
Пример #13
0
        public void InitializeTests()
        {
            var user1 = new User {ID = 1};
            var user2 = new User {ID = 2};

            var team1 = new Team {Users = new List<User> {user1, user2}};

            var dataString1 = new StoredString {Value = "someData"};
            var datastring2 = new StoredString {Value = "someOtherData"};
            var nullString = new StoredString {Value = null};

            var userData1 = new UserData {UserId = 1, Data = new List<StoredString> {dataString1, datastring2}};
            var userData2 = new UserData {UserId = 2, Data = new List<StoredString> {nullString, nullString}};
            var userData3 = new UserData {UserId = 2, Data = new List<StoredString> {dataString1, datastring2}};
            var userData4 = new UserData {UserId = 1, Data = new List<StoredString> {nullString, nullString}};

            var dataField = new DataField {UserData = new List<UserData> {userData1, userData3}};
            var dataField2 = new DataField {UserData = new List<UserData> {userData2, userData4}};

            var task1 = new StudyTask
            {
                DataFields = new List<DataField> {dataField},
                Users = new List<User> {user1, user2}
            };
            var task2 = new StudyTask
            {
                DataFields = new List<DataField> {dataField2},
                Users = new List<User> {user1, user2}
            };

            var userstudy1 = new UserStudies {User = user1};
            var userstudy2 = new UserStudies {User = user2};

            var stage1 = new Stage
            {
                Name = "stage1",
                IsCurrentStage = true,
                ID = 1,
                Users = new List<UserStudies> {userstudy1, userstudy2},
                Tasks = new List<StudyTask> {task1, task2}
            };
            var stage2 = new Stage
            {
                Name = "stage2",
                IsCurrentStage = false,
                ID = 2,
                Users = new List<UserStudies> {userstudy1, userstudy2},
                Tasks = new List<StudyTask> {task1, task2}
            };

            _id = 1;
            _mockStudyRepo = new Mock<IGenericRepository>();

            _testStudy = new Study
            {
                ID = 1,
                IsFinished = false,
                Items = new List<Item>(),
                Stages = new List<Stage> {stage1, stage2},
                Team = team1
            };

            _studies = new Dictionary<int, Study> {{1, _testStudy}};

            _testStudyStorageManager = new StudyStorageManager(_mockStudyRepo.Object);

            _testController = new StudyOverview(_testStudyStorageManager, _testTaskStorageManager);

            // Read item
            _mockStudyRepo.Setup(r => r.Read<Study>(It.IsAny<int>()))
                .Returns<int>(id => _studies.First(e => e.Key == id).Value);

            // Read items
            _mockStudyRepo.Setup(r => r.Read<Study>()).Returns(_studies.Values.AsQueryable());

            // Create
            _mockStudyRepo.Setup(r => r.Create(It.IsAny<Study>())).Callback<Study>(study =>
            {
                var nextId = _id++;
                study.ID = nextId;
                _studies.Add(nextId, study);
            });

            // Update
            _mockStudyRepo.Setup(r => r.Update(It.IsAny<Study>())).Callback<Study>(study =>
            {
                if (_studies.ContainsKey(study.ID))
                {
                    _studies[study.ID] = study;
                }
            });

            // Delete
            _mockStudyRepo.Setup(r => r.Delete(It.IsAny<Study>()))
                .Callback<Study>(study => { _studies.Remove(study.ID); });
        }