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 4] Create non default distribution seed data #14802

Merged
merged 31 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3bf5af0
Better handling of dispatch judge and atty
hschallhorn Jul 29, 2020
81fa04b
Fix factories to be able to be called after resetting sequences
hschallhorn Jul 29, 2020
edb3bcd
Add distribution seed file
hschallhorn Jul 29, 2020
0b7a931
Add a case that will error
hschallhorn Jul 29, 2020
0933296
Integrate bug fix
hschallhorn Jul 30, 2020
4ad20a7
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Jul 30, 2020
7986f95
Fix job
hschallhorn Jul 30, 2020
8070de9
Fixes
hschallhorn Jul 30, 2020
505ca1b
Fix report
hschallhorn Jul 30, 2020
a1d7e54
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Jul 30, 2020
f441a66
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 3, 2020
cab8086
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 3, 2020
c0ab88b
Fix tied to judge trait
hschallhorn Aug 4, 2020
f883fef
User random keys
hschallhorn Aug 4, 2020
692eff2
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 6, 2020
2d796ff
Integrate changes from fix
hschallhorn Aug 6, 2020
4554d88
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 6, 2020
1f581e0
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 7, 2020
0f5188a
Fix tests
hschallhorn Aug 11, 2020
8d3e300
Merge branch 'master' into hschallhorn/14604-testing
hschallhorn Aug 11, 2020
e10e5f8
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 11, 2020
a1c8ab6
Code climate
hschallhorn Aug 11, 2020
7bf0dd4
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 11, 2020
a89d1bf
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 18, 2020
05e9a42
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 18, 2020
92e163d
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 25, 2020
af12a4d
Feedback
hschallhorn Aug 31, 2020
42fecd0
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Aug 31, 2020
3acdd66
Update priority_distributions.rb
hschallhorn Aug 31, 2020
0f03b97
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Sep 3, 2020
0dfb2f1
Merge branch 'hschallhorn/14604-job-report' into hschallhorn/14604-te…
hschallhorn Sep 4, 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
2 changes: 1 addition & 1 deletion app/jobs/push_priority_appeals_to_judges_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def slack_report
report << ""
report << "*Debugging information*"
report << "Priority Target: #{priority_target}"
report << "Previous monthly distributions: #{eligible_judge_priority_distributions_this_month}"
report << "Previous monthly distributions: #{priority_distributions_this_month_for_eligible_judges}"

if appeals_not_distributed.values.flatten.any?
add_stuck_appeals_to_report(report, appeals_not_distributed)
Expand Down
389 changes: 389 additions & 0 deletions db/seeds/priority_distributions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,389 @@
# frozen_string_literal: true

# Create distribution seeds to test priority push case distribution job.
# Mocks previously distributed cases for judges. Sets up cases ready to be distributed.
# Invoke with:
# RequestStore[:current_user] = User.system_user
# Dir[Rails.root.join("db/seeds/*.rb")].sort.each { |f| require f }
# Seeds::PriorityDistributions.new.seed!
Comment on lines +3 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

🍳 🙆


module Seeds
class PriorityDistributions < Base
def seed!
organize_judges
create_previous_distribtions
create_cases_tied_to_judges
create_genpop_cases
create_errorable_cases
end

private

def organize_judges
JudgeTeam.unscoped.find_by(name: "BVAACTING").inactive!
JudgeTeam.find_by(name: "BVAAWAKEFIELD").update!(accepts_priority_pushed_cases: false)
end

def create_previous_distribtions
judges_with_previous_distributions.each do |judge|
2.times { create_priority_distribution_this_month(judge) }
create_priority_distribution_last_month(judge)
create_nonpriority_distribution_this_month(judge)
end
end

def create_cases_tied_to_judges
judges_with_tied_cases.each do |judge|
create_legacy_cases_tied_to_judge(judge)
create_hearing_cases_tied_to_judge(judge)
end
end

def create_genpop_cases
create_legacy_genpop_cases
create_ama_hearing_genpop_cases
create_direct_review_genpop_cases
create_evidence_submission_genpop_cases
end

def create_errorable_cases
create_legacy_appeal_with_previous_distribution
end

def create_legacy_cases_tied_to_judge(judge)
create_legacy_ready_priority_cases_tied_to_judge(judge)
create_legacy_nonready_priority_cases_tied_to_judge(judge)
create_legacy_ready_nonpriority_cases_tied_to_judge(judge)
end

def create_hearing_cases_tied_to_judge(judge)
create_hearing_ready_priority_cases_tied_to_judge(judge)
create_hearing_nonready_priority_cases_tied_to_judge(judge)
create_hearing_ready_nonpriority_cases_tied_to_judge(judge)
end

def create_legacy_genpop_cases
create_legacy_ready_priority_genpop_cases
create_legacy_ready_nonpriority_genpop_cases
create_legacy_nonready_priority_genpop_cases
end

def create_ama_hearing_genpop_cases
create_ama_hearing_ready_priority_genpop_cases
create_ama_hearing_ready_nonpriority_genpop_cases
create_ama_hearing_nonready_priority_genpop_cases
end

def create_direct_review_genpop_cases
create_direct_review_ready_priority_genpop_cases
create_direct_review_ready_nonpriority_genpop_cases
create_direct_review_nonready_priority_genpop_cases
end

def create_evidence_submission_genpop_cases
create_evidence_submission_ready_priority_genpop_cases
create_evidence_submission_ready_nonpriority_genpop_cases
create_evidence_submission_nonready_priority_genpop_cases
end

def create_priority_distribution_this_month(judge)
create_unvalidated_completed_distribution(
traits: [:priority, :this_month],
judge: judge,
statistics: { "batch_size" => rand(10) }
)
end

def create_priority_distribution_last_month(judge)
create_unvalidated_completed_distribution(
traits: [:priority, :last_month],
judge: judge,
statistics: { "batch_size" => rand(10) }
)
end

def create_nonpriority_distribution_this_month(judge)
create_unvalidated_completed_distribution(
traits: [:this_month],
judge: judge,
statistics: { "batch_size" => rand(10) }
)
end

def create_legacy_ready_priority_cases_tied_to_judge(judge)
rand(5).times do
create(
:case,
:aod,
:ready_for_distribution,
:tied_to_judge,
tied_judge: judge,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
end
end

def create_legacy_nonready_priority_cases_tied_to_judge(judge)
rand(5).times do
create(
:case,
:aod,
:tied_to_judge,
tied_judge: judge,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
end
end

def create_legacy_ready_nonpriority_cases_tied_to_judge(judge)
rand(5).times do
create(
:case,
:ready_for_distribution,
:tied_to_judge,
tied_judge: judge,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
end
end

def create_hearing_ready_priority_cases_tied_to_judge(judge)
rand(5).times do
create(
:appeal,
:hearing_docket,
:ready_for_distribution,
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
:advanced_on_docket_due_to_age,
:held_hearing,
:tied_to_judge,
tied_judge: judge,
adding_user: User.first
)
end
end

def create_hearing_nonready_priority_cases_tied_to_judge(judge)
rand(5).times do
create(
:appeal,
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
:hearing_docket,
:with_post_intake_tasks,
:advanced_on_docket_due_to_age,
:held_hearing,
:tied_to_judge,
tied_judge: judge,
adding_user: User.first
)
end
end

def create_hearing_ready_nonpriority_cases_tied_to_judge(judge)
rand(5).times do
create(
:appeal,
:hearing_docket,
:ready_for_distribution,
:held_hearing,
:tied_to_judge,
tied_judge: judge,
adding_user: User.first
)
end
end

def create_legacy_ready_priority_genpop_cases
rand(50).times do
create(
:case,
:aod,
:ready_for_distribution,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
end
end

def create_legacy_nonready_priority_genpop_cases
rand(5).times do
create(
:case,
:aod,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
end
end

def create_legacy_ready_nonpriority_genpop_cases
rand(5).times do
create(
:case,
:ready_for_distribution,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
end
end

def create_ama_hearing_ready_priority_genpop_cases
rand(50).times do
create(
:appeal,
:hearing_docket,
:ready_for_distribution,
:advanced_on_docket_due_to_age,
:held_hearing,
adding_user: User.first
)
end
end

def create_ama_hearing_nonready_priority_genpop_cases
rand(5).times do
create(
:appeal,
:hearing_docket,
:with_post_intake_tasks,
:advanced_on_docket_due_to_age,
:held_hearing,
adding_user: User.first
)
end
end

def create_ama_hearing_ready_nonpriority_genpop_cases
rand(5).times do
create(
:appeal,
:hearing_docket,
:ready_for_distribution,
:held_hearing,
adding_user: User.first
)
end
end

def create_direct_review_ready_priority_genpop_cases
rand(50).times do
create(
:appeal,
:direct_review_docket,
:ready_for_distribution,
:advanced_on_docket_due_to_age
)
end
end

def create_direct_review_nonready_priority_genpop_cases
rand(5).times do
create(
:appeal,
:direct_review_docket,
:with_post_intake_tasks,
:advanced_on_docket_due_to_age
)
end
end

def create_direct_review_ready_nonpriority_genpop_cases
rand(5).times do
create(
:appeal,
:direct_review_docket,
:ready_for_distribution
)
end
end

def create_evidence_submission_ready_priority_genpop_cases
rand(10).times do
FactoryBot.create(
:appeal,
:evidence_submission_docket,
:ready_for_distribution,
:advanced_on_docket_due_to_age
)
end
end

def create_evidence_submission_nonready_priority_genpop_cases
rand(50).times do
create(
:appeal,
:evidence_submission_docket,
:with_post_intake_tasks,
:advanced_on_docket_due_to_age
)
end
end

def create_evidence_submission_ready_nonpriority_genpop_cases
rand(50).times do
create(
:appeal,
:evidence_submission_docket,
:ready_for_distribution
)
end
end

def create_legacy_appeal_with_previous_distribution
vacols_case = create(
:case,
:aod,
:ready_for_distribution,
bfkey: random_key,
correspondent: create(:correspondent, stafkey: random_key)
)
create(:legacy_appeal, :with_schedule_hearing_tasks, vacols_case: vacols_case)

create_distribution_for_case_id(vacols_case.bfkey)
end

def create_distribution_for_case_id(case_id)
create_unvalidated_completed_distribution(
traits: [:priority, :completed, :this_month],
judge: User.third,
statistics: { "batch_size" => rand(10) }
).distributed_cases.create(
case_id: case_id,
priority: case_id,
docket: "legacy",
ready_at: Time.zone.now,
docket_index: "123",
genpop: false,
genpop_query: "any"
)
end

def create_unvalidated_completed_distribution(attrs = {})
distribution = FactoryBot.build(:distribution, *attrs.delete(:traits), attrs)
distribution.save!(validate: false)
distribution.completed!
distribution
end

def judges_with_tied_cases
@judges_with_tied_cases ||= begin
judges_with_judge_teams.unshift(User.find_by(full_name: "Steve Attorney_Cases Casper"))
end
end

def judges_with_previous_distributions
@judges_with_previous_distributions ||= begin
judges_with_judge_teams.unshift(User.find_by(full_name: "Keith Judge_CaseToAssign_NoTeam Keeling"))
end
end

def judges_with_judge_teams
JudgeTeam.unscoped.map(&:judge)
end

def random_key
rand.to_s[2..11]
end
end
end
Loading