From fb03464aa2c975837141b8755616ffb6afd9afdf Mon Sep 17 00:00:00 2001 From: Maria Grazia Alastra Date: Fri, 15 Apr 2016 15:47:43 -0400 Subject: [PATCH 1/3] IADevPipeline.js - factor out the ranking function --- src/js/ia/IADevPipeline.js | 127 ++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 58 deletions(-) diff --git a/src/js/ia/IADevPipeline.js b/src/js/ia/IADevPipeline.js index f8dc3f178..7aa6ccee8 100644 --- a/src/js/ia/IADevPipeline.js +++ b/src/js/ia/IADevPipeline.js @@ -458,6 +458,71 @@ return parseInt(moment().diff(date, "days", true)); } + function rank(ia) { + // Priority is higher when: + // - last activity (especially comment) is by a contributor (non-admin) + // - last activity happened long ago (the older the activity, the higher the priority) + if (ia.pr && (ia.pr.status === "open")) { + if (ia.last_comment) { + priority_val += ia.last_comment.admin? -20 : 20; + var idle_comment = elapsed_time(ia.last_comment.date); + if (ia.last_comment.admin) { + priority_val -= 20; + priority_val += idle_comment; + priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n"; + } else { + priority_val += 20; + priority_val += (2 * idle_comment); + priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n"; + } + } if (ia.last_commit) { + var idle_commit = elapsed_time(ia.last_commit.date); + if (ia.last_comment && moment.utc(ia.last_comment.date).isBefore(ia.last_commit.date)) { + priority_val += (1.5 * idle_commit); + priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n"; + } else if ((!ia.last_comment) && (!ia.last_commit.admin)) { + priority_val += (2 * idle_commit); + priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n"; + } + } + + // Priority drops if the PR is on hold + if (ia.pr && (ia.pr.status === "open")) { + var tags = ia.pr.tags; + + $.each(tags, function(idx) { + var tag = tags[idx]; + if (tag.name.toLowerCase() === "on hold") { + priority_val -= 100; + priority_msg += "- 100: the PR is on hold \n"; + } else if (tag.name.toLowerCase() === "priority: high") { + priority_val += 20; + priority_msg += "+ 20: the PR is high priority \n"; + } + }); + } + + // Priority is higher if the user has been mentioned in the last comment + if (ia.at_mentions && ia.at_mentions.indexOf(dev_p.data.username) !== -1) { + priority_val += 50; + priority_msg += "+ 50: you have been @ mentioned in the last comment \n"; + } + + // Has a PR, so it still has more priority than IAs which don't have one + if (priority_val <= 0) { + priority_val = 1; + priority_msg += "final value is 1: there's a PR, so it's higher priority than IAs without a PR \n"; + } + } + + var result = { + priority: priority_val, + priority_msg: priority_msg + }; + + return result; + } + // Sort each milestone array by priority function sort_pipeline() { $.each(dev_p.data.dev_milestones, function (key, val) { @@ -468,64 +533,10 @@ var ia = dev_p.data.dev_milestones[key][temp_ia]; if (dev_p.by_priority) { - // Priority is higher when: - // - last activity (especially comment) is by a contributor (non-admin) - // - last activity happened long ago (the older the activity, the higher the priority) - if (ia.pr && (ia.pr.status === "open")) { - if (ia.last_comment) { - priority_val += ia.last_comment.admin? -20 : 20; - var idle_comment = elapsed_time(ia.last_comment.date); - if (ia.last_comment.admin) { - priority_val -= 20; - priority_val += idle_comment; - priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n"; - } else { - priority_val += 20; - priority_val += (2 * idle_comment); - priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n"; - } - } if (ia.last_commit) { - var idle_commit = elapsed_time(ia.last_commit.date); - if (ia.last_comment && moment.utc(ia.last_comment.date).isBefore(ia.last_commit.date)) { - priority_val += (1.5 * idle_commit); - priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n"; - } else if ((!ia.last_comment) && (!ia.last_commit.admin)) { - priority_val += (2 * idle_commit); - priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n"; - } - } - - // Priority drops if the PR is on hold - if (ia.pr && (ia.pr.status === "open")) { - var tags = ia.pr.tags; - - $.each(tags, function(idx) { - var tag = tags[idx]; - if (tag.name.toLowerCase() === "on hold") { - priority_val -= 100; - priority_msg += "- 100: the PR is on hold \n"; - } else if (tag.name.toLowerCase() === "priority: high") { - priority_val += 20; - priority_msg += "+ 20: the PR is high priority \n"; - } - }); - } - - // Priority is higher if the user has been mentioned in the last comment - if (ia.at_mentions && ia.at_mentions.indexOf(dev_p.data.username) !== -1) { - priority_val += 50; - priority_msg += "+ 50: you have been @ mentioned in the last comment \n"; - } - - // Has a PR, so it still has more priority than IAs which don't have one - if (priority_val <= 0) { - priority_val = 1; - priority_msg += "final value is 1: there's a PR, so it's higher priority than IAs without a PR \n"; - } - } - - dev_p.data.dev_milestones[key][temp_ia].priority = priority_val; - dev_p.data.dev_milestones[key][temp_ia].priority_msg = priority_msg; + var rank = rank(ia); + + dev_p.data.dev_milestones[key][temp_ia].priority = rank.priority_val; + dev_p.data.dev_milestones[key][temp_ia].priority_msg = rank.priority_msg; } }); From 01d067d6b7183b3cd962322f3895400644099cf8 Mon Sep 17 00:00:00 2001 From: Maria Grazia Alastra Date: Fri, 15 Apr 2016 16:28:09 -0400 Subject: [PATCH 2/3] IADevPipeline.js - build the final ranking at the end of the function --- src/js/ia/IADevPipeline.js | 42 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/js/ia/IADevPipeline.js b/src/js/ia/IADevPipeline.js index 7aa6ccee8..f89046975 100644 --- a/src/js/ia/IADevPipeline.js +++ b/src/js/ia/IADevPipeline.js @@ -458,30 +458,34 @@ return parseInt(moment().diff(date, "days", true)); } - function rank(ia) { - // Priority is higher when: - // - last activity (especially comment) is by a contributor (non-admin) - // - last activity happened long ago (the older the activity, the higher the priority) + // Priority is higher when: + // - last activity (especially comment) is by a contributor (non-admin) + // - last activity happened long ago (the older the activity, the higher the priority) + function rank_ia(ia) { + var priority_val, score_last_comment, score_elapsed_time, score_tags, score_mention = 0; + var priority_msg = ''; + if (ia.pr && (ia.pr.status === "open")) { if (ia.last_comment) { - priority_val += ia.last_comment.admin? -20 : 20; + // Last comment var idle_comment = elapsed_time(ia.last_comment.date); if (ia.last_comment.admin) { - priority_val -= 20; - priority_val += idle_comment; + score_last_comment = -20; + score_elapsed_time = idle_comment; priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n"; } else { - priority_val += 20; - priority_val += (2 * idle_comment); + score_last_comment = 20; + score_elapsed_time = (2 * idle_comment); priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n"; } } if (ia.last_commit) { + // Last commit var idle_commit = elapsed_time(ia.last_commit.date); if (ia.last_comment && moment.utc(ia.last_comment.date).isBefore(ia.last_commit.date)) { - priority_val += (1.5 * idle_commit); + score_elapsed_time += (1.5 * idle_commit); priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n"; } else if ((!ia.last_comment) && (!ia.last_commit.admin)) { - priority_val += (2 * idle_commit); + score_elapsed_time += (2 * idle_commit); priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n"; } } @@ -493,21 +497,23 @@ $.each(tags, function(idx) { var tag = tags[idx]; if (tag.name.toLowerCase() === "on hold") { - priority_val -= 100; + score_tags = -100; priority_msg += "- 100: the PR is on hold \n"; } else if (tag.name.toLowerCase() === "priority: high") { - priority_val += 20; + score_tags = 20; priority_msg += "+ 20: the PR is high priority \n"; } }); } - // Priority is higher if the user has been mentioned in the last comment + // Priority is higher if the user was mentioned in the last comment if (ia.at_mentions && ia.at_mentions.indexOf(dev_p.data.username) !== -1) { - priority_val += 50; + score_mention = 50; priority_msg += "+ 50: you have been @ mentioned in the last comment \n"; } + priority_val = score_last_comment + score_elapsed_time + score_tags + score_mention; + // Has a PR, so it still has more priority than IAs which don't have one if (priority_val <= 0) { priority_val = 1; @@ -527,13 +533,11 @@ function sort_pipeline() { $.each(dev_p.data.dev_milestones, function (key, val) { $.each(dev_p.data.dev_milestones[key], function (temp_ia) { - var priority_val = 0; - var priority_msg = ''; - + var ia = dev_p.data.dev_milestones[key][temp_ia]; if (dev_p.by_priority) { - var rank = rank(ia); + var rank = rank_ia(ia); dev_p.data.dev_milestones[key][temp_ia].priority = rank.priority_val; dev_p.data.dev_milestones[key][temp_ia].priority_msg = rank.priority_msg; From 4ede7e6708964ef34de5b46d3cf081487301a91c Mon Sep 17 00:00:00 2001 From: Maria Grazia Alastra Date: Wed, 20 Apr 2016 17:03:21 -0400 Subject: [PATCH 3/3] IADevPipeline.js - make rank_ia less verbose --- src/js/ia/IADevPipeline.js | 41 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/js/ia/IADevPipeline.js b/src/js/ia/IADevPipeline.js index f89046975..342f4460d 100644 --- a/src/js/ia/IADevPipeline.js +++ b/src/js/ia/IADevPipeline.js @@ -462,8 +462,7 @@ // - last activity (especially comment) is by a contributor (non-admin) // - last activity happened long ago (the older the activity, the higher the priority) function rank_ia(ia) { - var priority_val, score_last_comment, score_elapsed_time, score_tags, score_mention = 0; - var priority_msg = ''; + var score_last_comment, score_elapsed_time, score_tags, score_mention = 0; if (ia.pr && (ia.pr.status === "open")) { if (ia.last_comment) { @@ -472,21 +471,23 @@ if (ia.last_comment.admin) { score_last_comment = -20; score_elapsed_time = idle_comment; - priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n"; + ia.priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n"; } else { score_last_comment = 20; score_elapsed_time = (2 * idle_comment); - priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n"; + ia.priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n"; } - } if (ia.last_commit) { + } + + if (ia.last_commit) { // Last commit var idle_commit = elapsed_time(ia.last_commit.date); if (ia.last_comment && moment.utc(ia.last_comment.date).isBefore(ia.last_commit.date)) { score_elapsed_time += (1.5 * idle_commit); - priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n"; + ia.priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n"; } else if ((!ia.last_comment) && (!ia.last_commit.admin)) { score_elapsed_time += (2 * idle_commit); - priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n"; + ia.priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n"; } } @@ -498,10 +499,10 @@ var tag = tags[idx]; if (tag.name.toLowerCase() === "on hold") { score_tags = -100; - priority_msg += "- 100: the PR is on hold \n"; + ia.priority_msg += "- 100: the PR is on hold \n"; } else if (tag.name.toLowerCase() === "priority: high") { score_tags = 20; - priority_msg += "+ 20: the PR is high priority \n"; + ia.priority_msg += "+ 20: the PR is high priority \n"; } }); } @@ -509,24 +510,19 @@ // Priority is higher if the user was mentioned in the last comment if (ia.at_mentions && ia.at_mentions.indexOf(dev_p.data.username) !== -1) { score_mention = 50; - priority_msg += "+ 50: you have been @ mentioned in the last comment \n"; + ia.priority_msg += "+ 50: you have been @ mentioned in the last comment \n"; } - priority_val = score_last_comment + score_elapsed_time + score_tags + score_mention; + ia.priority_val = score_last_comment + score_elapsed_time + score_tags + score_mention; // Has a PR, so it still has more priority than IAs which don't have one - if (priority_val <= 0) { - priority_val = 1; - priority_msg += "final value is 1: there's a PR, so it's higher priority than IAs without a PR \n"; + if (ia.priority_val <= 0) { + ia.priority_val = 1; + ia.priority_msg += "final value is 1: there's a PR, so it's higher priority than IAs without a PR \n"; } } - var result = { - priority: priority_val, - priority_msg: priority_msg - }; - - return result; + return ia; } // Sort each milestone array by priority @@ -537,10 +533,7 @@ var ia = dev_p.data.dev_milestones[key][temp_ia]; if (dev_p.by_priority) { - var rank = rank_ia(ia); - - dev_p.data.dev_milestones[key][temp_ia].priority = rank.priority_val; - dev_p.data.dev_milestones[key][temp_ia].priority_msg = rank.priority_msg; + dev_p.data.dev_milestones[key][temp_ia] = rank_ia(ia); } });