[Bps-public-commit] rt-extension-automaticassignment branch, master, updated. dc36ac1db16afca692c260e8c7a46d522c271c1c

Shawn Moore shawn at bestpractical.com
Wed Aug 17 16:05:18 EDT 2016


The branch, master has been updated
       via  dc36ac1db16afca692c260e8c7a46d522c271c1c (commit)
      from  b55e378efa497dae2496c5ecbbbe33972c071439 (commit)

Summary of changes:
 etc/AutomaticAssignment_Config.pm                  |   2 +-
 .../Chooser/{TicketStatus => ActiveTickets}        |   2 +-
 .../AutomaticAssignment/Chooser/ActiveTickets.pm   |  56 ++++++++++
 .../AutomaticAssignment/Chooser/TicketStatus.pm    | 117 ---------------------
 4 files changed, 58 insertions(+), 119 deletions(-)
 rename html/Admin/Queues/Elements/Chooser/{TicketStatus => ActiveTickets} (86%)
 create mode 100644 lib/RT/Extension/AutomaticAssignment/Chooser/ActiveTickets.pm
 delete mode 100644 lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm

- Log -----------------------------------------------------------------
commit dc36ac1db16afca692c260e8c7a46d522c271c1c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Aug 17 20:06:46 2016 +0000

    Rename and simplify TicketStatus to ActiveTickets

diff --git a/etc/AutomaticAssignment_Config.pm b/etc/AutomaticAssignment_Config.pm
index 484aef6..992ed6d 100644
--- a/etc/AutomaticAssignment_Config.pm
+++ b/etc/AutomaticAssignment_Config.pm
@@ -6,9 +6,9 @@ Set($AutomaticAssignmentFilters, [qw(
 )]) unless $AutomaticAssignmentFilters;
 
 Set($AutomaticAssignmentChoosers, [qw(
+    ActiveTickets
     Random
     RoundRobin
-    TicketStatus
     TimeLeft
 )]) unless $AutomaticAssignmentChoosers;
 
diff --git a/html/Admin/Queues/Elements/Chooser/TicketStatus b/html/Admin/Queues/Elements/Chooser/ActiveTickets
similarity index 86%
rename from html/Admin/Queues/Elements/Chooser/TicketStatus
rename to html/Admin/Queues/Elements/Chooser/ActiveTickets
index 2c9fe4a..1630e1b 100644
--- a/html/Admin/Queues/Elements/Chooser/TicketStatus
+++ b/html/Admin/Queues/Elements/Chooser/ActiveTickets
@@ -1,4 +1,4 @@
-<&| /Admin/Queues/Elements/SortableBox, prefix => $prefix, is_filter => 0, class_name => 'TicketStatus' &>
+<&| /Admin/Queues/Elements/SortableBox, prefix => $prefix, is_filter => 0, class_name => 'ActiveTickets' &>
 <p>This chooser selects the user with the fewest number of active tickets. If multiple users have the same number of tickets, then the ticket is assigned randomly to one of them.</p>
 </&>
 <%ARGS>
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/ActiveTickets.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/ActiveTickets.pm
new file mode 100644
index 0000000..c33f1f3
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/ActiveTickets.pm
@@ -0,0 +1,56 @@
+package RT::Extension::AutomaticAssignment::Chooser::ActiveTickets;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Chooser';
+
+sub ChooseOwnerForTicket {
+    my $class  = shift;
+    my $ticket = shift;
+    my @users  = @{ shift(@_) };
+    my $config = shift;
+
+    # for ActiveTickets we only consider tickets in the same queue
+    my $tickets = RT::Tickets->new($ticket->CurrentUser);
+    $tickets->LimitQueue(VALUE => $ticket->Queue);
+
+    $tickets->LimitToActiveStatus;
+
+    # track how many tickets are in each active status for
+    # each owner except for nobody
+    my %by_owner;
+    while (my $ticket = $tickets->Next) {
+        next if $ticket->Owner = RT->Nobody->id;
+        $by_owner{ $ticket->Owner }++;
+    }
+
+    my $fewest_ticket_count;
+    my @fewest;
+
+    for my $user (@users) {
+        my $count = $by_owner{ $user->Id };
+
+        # either the first user we've seen, or this user
+        # has fewer tickets than anyone else we've seen this round
+        if (!defined($fewest_ticket_count) || $count < $fewest_ticket_count) {
+            @fewest = $user;
+            $fewest_ticket_count = $count;
+        }
+        elsif ($count == $fewest_ticket_count) {
+            push @fewest, $user;
+        }
+    }
+
+    # found exactly one user, so return this user as the owner
+    if (@fewest == 1) {
+        return $fewest[0];
+    }
+
+    # all remaining users have the exact same number of active tickets, so
+    # pick a random one
+    return $fewest[rand @fewest];
+}
+
+sub Description { "Active Tickets" }
+
+1;
+
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
deleted file mode 100644
index c13c5eb..0000000
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
+++ /dev/null
@@ -1,117 +0,0 @@
-package RT::Extension::AutomaticAssignment::Chooser::TicketStatus;
-use strict;
-use warnings;
-use base 'RT::Extension::AutomaticAssignment::Chooser';
-
-sub ChooseOwnerForTicket {
-    my $class  = shift;
-    my $ticket = shift;
-    my @users  = @{ shift(@_) };
-    my $config = shift;
-
-    # for TicketStatus we only consider tickets in the same queue
-    my $tickets = RT::Tickets->new($ticket->CurrentUser);
-    $tickets->LimitQueue(VALUE => $ticket->Queue);
-
-    my @all_statuses; # for trimming down the tickets to consider
-    my %primary_status; # for coalescing multiple statuses at the same level
-    my @rounds; # for tracking which statuses are more important than others
-
-    # ties => [ ['new', 'open'], 'stalled' ]
-    # this says find the user with the fewest number of new or open tickets.
-    # if there are multiple such users, then select the one with the fewest
-    # number of stalled tickets. if there are multiple again, then we pick
-    # one at random
-    # in this scenario, "open" is folded into "new" like so:
-    #     @all_statuses = ('new', 'open', 'stalled')
-    #     %primary_status = (new => 'new', open => 'new', stalled => 'stalled')
-    #     @rounds = ('new', 'stalled')
-
-    if ($config->{ties}) {
-        for my $statuses (@{ $config->{ties} }) {
-            if (ref($statuses)) {
-                # multiple statuses at the same round (like new/open above)
-                # arbitrarily map to the first status in the list (new)
-                my $primary = $statuses->[0];
-                push @all_statuses, @$statuses;
-                push @rounds, $primary;
-                $primary_status{$_} = $primary for @$statuses;
-            }
-            else {
-                # just a single status in this round (like stalled above)
-                my $status = $statuses;
-                push @all_statuses, $status;
-                push @rounds, $status;
-                $primary_status{$status} = $status;
-            }
-        }
-    }
-    else {
-        # if the config does not specify status tiebreakers,
-        # then simplify by selecting the user with the fewest
-        # active-status tickets. we map everything to a single
-        # "active" round
-        @all_statuses = $ticket->QueueObj->ActiveStatusArray;
-        $primary_status{$_} = 'active' for @all_statuses;
-        @rounds = 'active';
-    }
-
-    # limit to all the statuses we've seen thus far
-    # we certainly don't want to look at all resolved tickets (unless
-    # directed to)
-    for my $status (@all_statuses) {
-        $tickets->LimitStatus(VALUE => $status);
-    }
-
-    # track how many tickets are in each primary status for
-    # each owner except for nobody
-    my %status_by_owner;
-    while (my $ticket = $tickets->Next) {
-        next if $ticket->Owner = RT->Nobody->id;
-        my $primary_status = $primary_status{ $ticket->Status };
-        $status_by_owner{ $ticket->Owner }{ $primary_status }++;
-    }
-
-    # for each round, find the users with the least number of tickets
-    # in that status. if we find just one user, we return that new owner.
-    # if we find multiple, we continue on to the next round with just
-    # the users who tied for the fewest number of tickets
-    my @fewest;
-    for my $status (@rounds) {
-        @fewest = ();
-        my $fewest_ticket_count;
-
-        for my $user (@users) {
-            my $count = $status_by_owner{ $user->Id }{ $status };
-
-            # either the first user we've seen, or this user
-            # has fewer tickets than anyone else we've seen this round
-            if (!defined($fewest_ticket_count) || $count < $fewest_ticket_count) {
-                @fewest = $user;
-                $fewest_ticket_count = $count;
-            }
-            elsif ($count == $fewest_ticket_count) {
-                push @fewest, $user;
-            }
-        }
-
-        # found exactly one user, so return this user as the owner
-        if (@fewest == 1) {
-            return $fewest[0];
-        }
-        # otherwise, continue to the next round with the users who tied for
-        # fewest tickets
-        else {
-            @users = @fewest;
-        }
-    }
-
-    # all remaining users have the exact same number of tickets by status, so
-    # pick a random one
-    return $fewest[rand @fewest];
-}
-
-sub Description { "Ticket Status" }
-
-1;
-

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list