Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. class TeamTasks {
  2. public:
  3. const TasksInfo& GetPersonTasksInfo(const string& person) const {
  4. return tasks.at(person);
  5. }
  6.  
  7. void AddNewTask(const string& person) {
  8. tasks[person][TaskStatus::NEW]++;
  9. }
  10.  
  11. tuple<TasksInfo, TasksInfo> PerformPersonTasks(const string& person, int task_count) {
  12. auto p = tasks.find(person);
  13. /*if (p == tasks.end()) {
  14. throw invalid_argument("Person does not exist: " + person);
  15. }*/
  16. int counter = 0;
  17. TasksInfo updated;
  18. TasksInfo notUpdated = p->second;
  19.  
  20. if (task_count > 0) {
  21. for (auto& t : p->second) {
  22. switch (t.first) {
  23. case TaskStatus::NEW:
  24. while (counter < task_count && t.second > 0) {
  25. counter++;
  26. t.second--;
  27. notUpdated[TaskStatus::NEW]--;
  28. p->second[TaskStatus::IN_PROGRESS]++;
  29. updated[TaskStatus::IN_PROGRESS]++;
  30. }
  31. break;
  32. case TaskStatus::IN_PROGRESS:
  33. while (counter < task_count && t.second > 0) {
  34. counter++;
  35. t.second--;
  36. notUpdated[TaskStatus::IN_PROGRESS]--;
  37. p->second[TaskStatus::TESTING]++;
  38. updated[TaskStatus::TESTING]++;
  39. }
  40. break;
  41. case TaskStatus::TESTING:
  42. while (counter < task_count && t.second > 0) {
  43. counter++;
  44. t.second--;
  45. notUpdated[TaskStatus::TESTING]--;
  46. p->second[TaskStatus::DONE]++;
  47. updated[TaskStatus::DONE]++;
  48. }
  49. break;
  50. }
  51. if (counter == task_count)
  52. break;
  53. }
  54. }
  55.  
  56. if (p->second[TaskStatus::NEW] <= 0)
  57. p->second.erase(TaskStatus::NEW);
  58. if (p->second[TaskStatus::IN_PROGRESS] <= 0)
  59. p->second.erase(TaskStatus::IN_PROGRESS);
  60. if (p->second[TaskStatus::TESTING] <= 0)
  61. p->second.erase(TaskStatus::TESTING);
  62. if (p->second[TaskStatus::DONE] <= 0)
  63. p->second.erase(TaskStatus::DONE);
  64.  
  65. if (notUpdated[TaskStatus::NEW] <= 0)
  66. notUpdated.erase(TaskStatus::NEW);
  67. if (notUpdated[TaskStatus::IN_PROGRESS] <= 0)
  68. notUpdated.erase(TaskStatus::IN_PROGRESS);
  69. if (notUpdated[TaskStatus::TESTING] <= 0)
  70. notUpdated.erase(TaskStatus::TESTING);
  71. if (notUpdated[TaskStatus::DONE] <= 0)
  72. notUpdated.erase(TaskStatus::DONE);
  73.  
  74. return make_tuple(updated, notUpdated);
  75. }
  76.  
  77. private:
  78. map<string, TasksInfo> tasks;
  79. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement