Advertisement
ridwan100

ReviewAssIgner

Jul 8th, 2024 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct Task {
  4.     int taskId;
  5.     string assigneeName;
  6.     string reviewerName;
  7.     string status;
  8.     double estimateInHours;
  9. };
  10.  
  11. vector<Task> assignReviewers(vector<Task>& tasks) {
  12.     unordered_map<string,double>reviwerMap;
  13.      for (const auto& task : tasks){
  14.         if(task.status == "in-review" && task.reviewerName != "" || task.status == "done" && task.reviewerName != ""){
  15.              reviwerMap[task.reviewerName] += (task.estimateInHours/3);
  16.         }
  17.         reviwerMap[task.assigneeName] += task.estimateInHours;
  18.          
  19.      }
  20.          
  21.    
  22.      for(auto& task:tasks){
  23.         if(task.status == "in-review" && task.reviewerName.empty()){
  24.          double minimumEffortSpent = INT_MAX;
  25.          string reviewer;
  26.          for(const auto& [memberName, totalEffort] :reviwerMap){
  27.             if(task.assigneeName != memberName && totalEffort < minimumEffortSpent){
  28.                 minimumEffortSpent = totalEffort;
  29.                 reviewer = memberName;
  30.             }
  31.          }
  32.         task.reviewerName = reviewer;
  33.         reviwerMap[reviewer] += (task.estimateInHours / 3);
  34.        
  35.  
  36.          
  37.      }
  38.      }
  39.      
  40.     return tasks;
  41. }
  42.  
  43. int main() {
  44.     vector<Task> tasks = {
  45.         {1, "John", "", "todo", 4},
  46.         {2, "Jane", "Khaled", "in-review", 10},
  47.         {3, "Jim", "John", "in-review", 9},
  48.         {4, "Khaled", "", "in-review", 5},
  49.         {5, "John", "", "in-review", 7},
  50.         {6, "Khaled", "", "in-review", 12},
  51.         {7, "Jim", "", "in-review", 3},
  52.         {8, "Jane", "", "in-review", 8},
  53.         {9, "Jane", "", "in-progress", 15},
  54.         {10, "Tariq", "", "in-review", 13},
  55.         {11, "Jane", "Tariq", "done", 8},
  56.     };
  57.  
  58.     vector<Task> updatedTasks = assignReviewers(tasks);
  59.  
  60.     for (const auto& task : updatedTasks) {
  61.        cout << "taskId: " << task.taskId << ", assigneeName: " << task.assigneeName << ", reviewerName: " << task.reviewerName << ", status: " << task.status << ", estimateInHours: " << task.estimateInHours << std::endl;
  62.     }
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement