Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PART 1] Create a "priority only" distribution #14691

Closed
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3222a99
Priority distributions wip
hschallhorn Jul 13, 2020
22a4912
merge
hschallhorn Jul 13, 2020
a45df4b
Fix tests
hschallhorn Jul 13, 2020
1cee714
make docs!
hschallhorn Jul 13, 2020
2fdbc09
Code climate
hschallhorn Jul 13, 2020
b653340
Merge branch 'master' into hschallhorn/14604-distribute-priority-only
hschallhorn Jul 13, 2020
25c9606
Allow unlimited priority legacy appeals to be distributed
hschallhorn Jul 13, 2020
3bd0698
Fix bug on wrong number of hearing cases distributed
hschallhorn Jul 14, 2020
fb7e038
Create priority only distributions
hschallhorn Jul 14, 2020
df2fd01
Merge branch 'master' into hschallhorn/14604-priority-only-distribution
hschallhorn Jul 14, 2020
0932ca5
Merge branch 'master' into hschallhorn/14604-distribute-priority-only
hschallhorn Jul 14, 2020
904c52f
Suggestions
hschallhorn Jul 14, 2020
a0a26e5
Update to priority_push
hschallhorn Jul 14, 2020
98c954f
Update to priority_push
hschallhorn Jul 14, 2020
12013e3
Fix schema
hschallhorn Jul 14, 2020
49db6c4
Merge branch 'hschallhorn/14604-distribute-priority-only' into hschal…
hschallhorn Jul 14, 2020
3d8b6b2
Code Climate
hschallhorn Jul 14, 2020
b902ddc
Updates
hschallhorn Jul 14, 2020
4c47117
Updates
hschallhorn Jul 14, 2020
b75e3a9
fix specs
hschallhorn Jul 14, 2020
04535b7
Merge branch 'master' into hschallhorn/14604-priority-only-distribution
hschallhorn Jul 15, 2020
0b8f944
Merge branch 'master' into hschallhorn/14604-priority-only-distribution
hschallhorn Jul 15, 2020
ef4f5ba
Allow unlimited priority legacy appeals to be distributed
hschallhorn Jul 13, 2020
4e05c00
Fix bug on wrong number of hearing cases distributed
hschallhorn Jul 14, 2020
5d96969
Create priority only distributions
hschallhorn Jul 14, 2020
ed9081d
Code Climate
hschallhorn Jul 14, 2020
ca76476
Updates
hschallhorn Jul 14, 2020
046454e
Updates
hschallhorn Jul 14, 2020
10b1656
fix specs
hschallhorn Jul 14, 2020
edb04dd
Merge branch 'hschallhorn/14604-priority-only-distribution' of https:…
hschallhorn Jul 15, 2020
d562a24
Rename ama distribution
hschallhorn Jul 16, 2020
78e9e7a
Merge branch 'master' into hschallhorn/14604-priority-only-distribution
hschallhorn Jul 16, 2020
463d33c
Merge branch 'master' into hschallhorn/14604-priority-only-distribution
hschallhorn Jul 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/models/concerns/ama_case_distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ def docket_coordinator
@docket_coordinator ||= DocketCoordinator.new
end

def priority_push_distribution(limit = nil)
@appeals = []
@rem = 0

if limit.nil?
# Distribute priority appeals that are tied to judges (not genpop) with no limit.
distribute_appeals(:legacy, nil, priority: true, genpop: "not_genpop")
distribute_appeals(:hearing, nil, priority: true, genpop: "not_genpop")
else
# Distribute <limit> number of cases, regardless of docket type, oldest first.
oldest_priority_appeals_by_docket(limit).each do |docket, number_of_cases|
distribute_appeals(docket, number_of_cases, priority: true)
end
end
end

def ama_distribution
@appeals = []
@rem = batch_size
Expand Down Expand Up @@ -59,7 +75,7 @@ def ama_distribution

def ama_statistics
{
batch_size: batch_size,
batch_size: priority_push? ? @appeals.count : batch_size,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

priority push does not work off of batch size, it either distributes without limit or distributes the provided limit.

total_batch_size: total_batch_size,
priority_count: priority_count,
direct_review_due_count: direct_review_due_count,
Expand All @@ -75,7 +91,7 @@ def ama_statistics
end

def distribute_appeals(docket, num, priority: false, genpop: "any", range: nil, bust_backlog: false)
return [] unless num > 0
return [] unless num.nil? || num > 0

if range.nil? && !bust_backlog
appeals = dockets[docket].distribute_appeals(self, priority: priority, genpop: genpop, limit: num)
Expand Down
6 changes: 4 additions & 2 deletions app/models/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class Distribution < CaseflowRecord
CASES_PER_ATTORNEY = 3
ALTERNATIVE_BATCH_SIZE = 15

scope :priority_push, -> { where(priority_push: true) }

class << self
def pending_for_judge(judge)
where(status: %w[pending started], judge: judge)
end
end

def distribute!
def distribute!(limit = nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows us to stipulate a limit for priority push cases, when we get to the "aim to hit priority target" portion of the job

return unless %w[pending error].include? status

if status == "error"
Expand All @@ -41,7 +43,7 @@ def distribute!
multi_transaction do
ActiveRecord::Base.connection.execute "SET LOCAL statement_timeout = #{transaction_time_out}"

ama_distribution
priority_push? ? priority_push_distribution(limit) : ama_distribution

update!(status: "completed", completed_at: Time.zone.now, statistics: ama_statistics)
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/dockets/hearing_request_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def distribute_appeals(distribution, priority: false, genpop: "any", limit: 1)
base_relation: base_relation, genpop: genpop, judge: distribution.judge
).call

# genpop 'any' returns 2 arrays of the limited base relation. This means if we only request 2 cases, appeals is a
# 2x2 array containing 4 cases overall and we will end up distributing 4 cases rather than 2. Instead, reinstate the
# limit here by filtering out the newest cases
if genpop == "any"
appeals_to_reject = appeals.flatten.sort_by(&:ready_for_distribution_at).drop(limit)
appeals = [appeals.first - appeals_to_reject, appeals.last - appeals_to_reject]
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a bug! Detailed here


HearingRequestCaseDistributor.new(
appeals: appeals, genpop: genpop, distribution: distribution, priority: priority
).call
Expand Down
5 changes: 3 additions & 2 deletions app/models/vacols/case_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class DocketNumberCentennialLoop < StandardError; end
#{JOIN_ASSOCIATED_VLJS_BY_PRIOR_DECISIONS}
)
where ((VLJ = ? and 1 = ?) or (VLJ is null and 1 = ?))
and rownum <= ?
and (rownum <= ? or 1 = ?)
"

SELECT_NONPRIORITY_APPEALS = "
Expand Down Expand Up @@ -324,7 +324,8 @@ def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false)
judge.vacols_attorney_id,
(genpop == "any" || genpop == "not_genpop") ? 1 : 0,
(genpop == "any" || genpop == "only_genpop") ? 1 : 0,
limit
limit,
limit.nil? ? 1 : 0
Copy link
Contributor Author

@hschallhorn hschallhorn Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows nil limit to be passed to distribute_priority_appeals, indicating that any and all cases should be distributed

])

distribute_appeals(fmtd_query, judge, dry_run)
Expand Down
Loading