Пример #1
0
 /// <summary>
 /// Distribute using the matched distributor. 
 /// </summary>
 /// <param name="distributionRule">The rule for distribution.</param>
 /// <param name="users">The users to distribute to</param>
 /// <param name="tasks">The tasks to distribute</param>
 /// <returns></returns>
 public IEnumerable<StudyTask> Distribute(Stage.Distribution distributionRule, IEnumerable<User> users,
     IEnumerable<StudyTask> tasks)
 {
     if (_distributors.ContainsKey(distributionRule))
     {
         return _distributors[distributionRule].Distribute(users, tasks);
     }
     throw new NotImplementedException("The distributer is not implemented");
 }
Пример #2
0
        /// <summary>
        /// Retrieve a dictionary of users and their amount of completed tasks in the given stage
        /// </summary>
        /// <param name="stage"></param>
        /// <returns></returns>
        private Dictionary<int, int> GetCompletedTasks(Stage stage)
        {
            var completedTasks = new ConcurrentDictionary<int, int>();

            foreach (var task in stage.Tasks)
            {
                foreach (var user in task.Users)
                {
                    if (task.IsFinished(user.ID))
                    {
                        completedTasks.AddOrUpdate(user.ID, 1, (id, count) => count + 1);
                    }
                }
            }
            return completedTasks.ToDictionary(k => k.Key, k => k.Value);
        }
Пример #3
0
        /// <summary>
        /// Create a stage for a study
        /// </summary>
        /// <param name="stageDto">The stageDTO to be created</param>
        /// <returns></returns>
        private Stage CreateStage(StageDto stageDto)
        {
            var stage = new Stage
            {
                Name = stageDto.Name,
                CurrentTaskType = StudyTask.Type.Review,
                DistributionRule =
                    (Stage.Distribution) Enum.Parse(typeof (Stage.Distribution), stageDto.DistributionRule.ToString()),
                VisibleFields = new List<FieldType>(),
                Users = new List<UserStudies>(),
                Criteria = new List<Criteria>()
            };

            stageDto.VisibleFields.ForEach(
                f => stage.VisibleFields.Add(new FieldType(f.ToString())));

            stageDto.ReviewerIDs.ForEach(u =>
                stage.Users.Add(new UserStudies
                {
                    StudyRole = UserStudies.Role.Reviewer,
                    User = _teamStorage.GetUser(u)
                }));

            stageDto.ValidatorIDs.ForEach(u =>
                stage.Users.Add(new UserStudies
                {
                    StudyRole = UserStudies.Role.Validator,
                    User = _teamStorage.GetUser(u)
                }));

            var criteria = new Criteria
            {
                Name = stageDto.Criteria.Name,
                DataMatch = stageDto.Criteria.DataMatch.Select(s => new StoredString {Value = s}).ToArray(),
                DataType =
                    (DataField.DataType) Enum.Parse(typeof (DataField.DataType), stageDto.Criteria.DataType.ToString()),
                Description = stageDto.Criteria.Description,
                Rule =
                    (Criteria.CriteriaRule)
                        Enum.Parse(typeof (Criteria.CriteriaRule), stageDto.Criteria.Rule.ToString())
            };

            if (stageDto.Criteria.TypeInfo != null)
            {
                criteria.TypeInfo = stageDto.Criteria.TypeInfo.Select(s => new StoredString {Value = s}).ToArray();
            }

            stage.Criteria.Add(criteria);

            return stage;
        }
Пример #4
0
 /// <summary>
 /// Distribute the tasks among the users of a stage
 /// </summary>
 /// <param name="users">Users to receive tasks</param>
 /// <param name="distributionRule">Distribution rule to follow (EqualOverlap, NoOverlap)</param>
 /// <param name="tasks"></param>
 /// <returns></returns>
 public IEnumerable<StudyTask> Distribute(IEnumerable<User> users, Stage.Distribution distributionRule,
     IEnumerable<StudyTask> tasks)
 {
     //Only distribute tasks that are editable
     return _taskDistributor.Distribute(distributionRule, users,
         tasks.Where(t => t.IsEditable));
 }
Пример #5
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); });
        }