Caseflow: Investigate priority legacy cases that have been stuck at ready to distribute

Created on 24 Jun 2020  ยท  48Comments  ยท  Source: department-of-veterans-affairs/caseflow

Priority cases are cases that are AOD/CAVC remands that the Board is legislated to work on in priority order and the Board wants to get done asap due the outstanding circumstances on the case. During background investigation around the incoming requests to modify the automatic case distribution algorithm, I discovered that there are ~100 or so of these cases that have been waiting over 1 month to be worked. We need to investigate these and figure out why they are stuck and keep them moving.

All of the cases waiting that long are tied to a judge, meaning the case was a legacy hearing that must be decided by the judge who held the hearing by law, or it was a CAVC remand that must be decided by the judge who issued the original decision.

The scope of this ticket is to investigate only the stuck priority legacy cases that are tied to judges who are actively pulling distributions, which as of 5/25, there are 33 of. The other cases, where the judges are not actively pulling distributions, are due to the judge being an AVLJ (acting VLJ, without the ability to pull judges), or other such exceptions that will be handled manually by the Board.

Background

auto-case-distribution Medium caseflow-queue Echo ๐Ÿฌ Investigation Judge

All 48 comments

Estimating at a 3 for investigation.

Find out why they're stuck, and fix/file ticket to fix it. (If the other tickets won't fix it already)

@alisan16 How did you get 33 "stuck priority legacy cases that are tied to judges who are actively pulling distributions"? How does one determine if a legacy case is stuck?

@yoomlam I am using the term "stuck" to refer to cases that have been waiting in ready to distribute state for over 1 month. Please reference the Metabase dashboard which has a table of priority legacy cases, the date the case was ready, the judge the case is tied to, and whether the judge is actively requesting distributions. Priority cases are typically distributed within 2 weeks, so if they have been waiting for 1 month, something is likely blocking the case from being distributed. The scope of this ticket is only to investigate the cases that are tied to judges who are actively requesting distributions, but are not receiving those older legacy cases tied to them that have been ready for at least one month.

The Metabase query for Priority Legacy Appeals Ready for Distribution is meant to mimic VACOLS::CaseDocket.distribute_priority_appeals. However there are differences that affect the query results: order by was removed from the JOIN_ASSOCIATED_VLJS_BY_HEARINGS and JOIN_ASSOCIATED_VLJS_BY_PRIOR_DECISIONS sections in the query, which affect which VLJ an appeal is tied to.

  • order by HEARING_DATE desc
  • order by BFDDEC desc

I created another Metabase query 'priority legacy cases tied to active judge - adjusted' that restores the order by clauses and makes other adjustments:

  • order by BFDLOOUT (does not affect results but mimics distribute_priority_appeals)
  • adds column last_judge_distrib: last distribution to the judge
  • adds column last_case_distrib: last time the case was distributed

Using this query, there are only 7 "stuck" cases with the date (that the case was ready) earlier than 5/25, only one of which was before May.

Running VACOLS::CaseDocket.distribute_priority_appeals(judge, "not_genpop", 1000, dry_run: true) against the judges for the 7 cases shows that the "stuck" cases will be distributed to the judge when the function is next called.

Doing a more thorough investigation, one case is not being distributed:

# 9 stuck legacy cases with date on or before 5/25
stuck_bfkeys=%w[4012451 3469884 3667338 4037809 2802534 4025978 4039043 4009420 3176803]
judges=%w[BVAKALIBRAN BVASDREISS BVAWDONNELLY BVACBRUCE BVAHROBERT BVAKKORDICH BVADHACHEY VACOSTROMG]
cases=judges.map{|css_id| 
  VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: css_id), 
    "not_genpop", 1000, dry_run: true) 
}

bfkeys=cases.flatten.map{|obj| obj["bfkey"]}
bfkeys.count
=> 80
stuck_bfkeys - bfkeys
=> ["3176803"] # this is tied to VACOSTROMG according to the query

stromscases=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "VACOSTROMG"), "not_genpop", 1000, dry_run: true)
=> []

Need to dig further into case 3176803:

  1. verify that this case would be distributed to VACOSTROMG
  2. why is the function returning empty when there are (seemingly) several tied to VACOSTROMG

Reminder to self: The Metabase query is running on yesterday's data, whereas Rails console commands are running against current data. There is a possibility that some data has recently changed and is causing this.

Follow-up to case 3176803:

  • It's current location code is SMITHA5 (set today 'Wed, 08 Jul 2020'). The BFCURLOC must be 81 or 83 for the case to be distributed.

Great investigation @yoomlam! Please update the Metabase questions and dashboard (feel free to overwrite and edit the dashboard however) accordingly so that the data displayed there is accurate and up to date.

Original Metabase query updated. I scanned the other legacy-related charts in the same dashboard for similar order by problems and they look correct.

Checking earlier cases (with where completed_at > '2020-03-01' removed from the query):

stuck_bfkeys=%w[3973896 3970338 3985161 3999821 4000168
 4001487 4005419 4006273 4012579 4021651]
judges=%w[BVARSCHARNB BVABCHATTER]
cases=judges.map{|css_id| 
  VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: css_id), 
    "not_genpop", 1000, dry_run: true) 
}

bfkeys=cases.flatten.map{|obj| obj["bfkey"]}
bfkeys.count
=> 27
stuck_bfkeys - bfkeys
=> []

Good! All earlier cases will be distributed on the next distribution for these judges who are actively pulling cases.

@yoomlam Following up on this. I am looking at the table again and re-added the where completed_at > '2020-03-01' clause. That one only applies to the distributions_90d_active column, which represents whether the judge has pulled a distribution in the past 90 days.

I am still seeing the oldest case in this new query as ready on 2020-04-27, and the last judge distribution was on 7/9/2020. Why didn't the judge receive this case?

VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAMMARTIN"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"3567789", "bfdloout"=>2020-04-29 15:45:43 UTC, "vlj"=>"332"},
 {"bfkey"=>"4052820", "bfdloout"=>2020-07-09 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4053094", "bfdloout"=>2020-07-10 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4054038", "bfdloout"=>2020-07-12 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4053766", "bfdloout"=>2020-07-12 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4053780", "bfdloout"=>2020-07-12 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4054117", "bfdloout"=>2020-07-13 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4054764", "bfdloout"=>2020-07-14 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"4052600", "bfdloout"=>2020-07-14 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"2917356", "bfdloout"=>2020-07-15 00:00:00 UTC, "vlj"=>"332"},
 {"bfkey"=>"2916645", "bfdloout"=>2020-07-15 00:00:00 UTC, "vlj"=>"332"}]

As long as VACOLS::CaseDocket.distribute_priority_appeals is being called for that judge, the appeal with "bfkey"=>"3567789" should be distributed next.

CORRECTION: Prior distributions:

> Distribution.where(judge_id: User.find_by(css_id: "BVAMMARTIN").id).count
=> 60

@hschallhorn You recently found a bug in ACD. Any ideas?

@yoomlam The judge_ids in the table are their VACOLS atty IDs, not their Caseflow user IDs, which is what the Distributions table uses. You'll need to grab the id from the users table based on the CSSID of the judge

css_id = VACOLS::Staff.find_by(sattyid: 332).sdomainid
=> "BVAMMARTIN"
judge_id = User.find_by_css_id(css_id).id
=> 1402
Distribution.where(judge_id: judge_id).count
=> 60
# Last 5 distributions for the judge
> ds=Distribution.where(judge_id: User.find_by(css_id: "BVAMMARTIN").id).order(created_at: :asc)
> ds.last(5).pluck(:id, :status, :completed_at)
=> [[7357, "completed", Tue, 26 May 2020 13:26:11 UTC +00:00],
 [7501, "completed", Fri, 05 Jun 2020 12:45:59 UTC +00:00],
 [7657, "completed", Thu, 18 Jun 2020 12:27:47 UTC +00:00],
 [7780, "completed", Tue, 30 Jun 2020 12:56:15 UTC +00:00],
 [7874, "completed", Thu, 09 Jul 2020 16:15:55 UTC +00:00]]

# Examine the last distribution of cases
> d=ds.last
=> [7874, "completed", Thu, 09 Jul 2020 16:15:55 UTC +00:00]
> d.distributed_cases.count
=> 30
> dcs=d.distributed_cases
> dcs.pluck(:docket, :genpop, :genpop_query, :ready_at)
=> [["legacy", false, "not_genpop", Thu, 04 Jun 2020 00:00:00 UTC +00:00],
 ["legacy", false, "not_genpop", Wed, 01 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", false, "not_genpop", Mon, 06 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", false, "not_genpop", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["hearing", false, "not_genpop", Wed, 01 Jul 2020 14:19:05 UTC +00:00],
 ["hearing", false, "not_genpop", Mon, 06 Jul 2020 13:56:44 UTC +00:00],
 ["legacy", false, "not_genpop", Wed, 08 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", false, "not_genpop", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["hearing", false, "not_genpop", Tue, 07 Jul 2020 16:39:07 UTC +00:00],
 ["hearing", false, "not_genpop", Tue, 07 Jul 2020 16:38:28 UTC +00:00],
 ["hearing", false, "not_genpop", Tue, 07 Jul 2020 16:34:41 UTC +00:00],
 ["hearing", false, "not_genpop", Tue, 07 Jul 2020 17:50:25 UTC +00:00],
 ["hearing", false, "not_genpop", Tue, 07 Jul 2020 17:51:41 UTC +00:00],
 ["evidence_submission", nil, nil, Tue, 28 Apr 2020 14:02:43 UTC +00:00],
 ["evidence_submission", nil, nil, Wed, 01 Jul 2020 11:12:38 UTC +00:00],
 ["direct_review", nil, nil, Thu, 25 Jun 2020 14:07:39 UTC +00:00],
 ["direct_review", nil, nil, Wed, 01 Jul 2020 11:15:04 UTC +00:00],
 ["direct_review", nil, nil, Wed, 01 Jul 2020 11:16:00 UTC +00:00],
 ["direct_review", nil, nil, Wed, 01 Jul 2020 11:16:30 UTC +00:00],
 ["direct_review", nil, nil, Wed, 01 Jul 2020 11:18:51 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["legacy", true, "any", Thu, 09 Jul 2020 00:00:00 UTC +00:00],
 ["direct_review", nil, nil, Thu, 14 May 2020 11:35:23 UTC +00:00]]

Priority legacy appeals were distributed in the last distribution.

@yoomlam What were the ready_at dates for those priority legacy appeals? The question is whether appeal with bfkey 3567789 was skipped over (hence stuck), or whether it will be distributed next. I'm following up since the last comment from 7 days ago said these appeals would be distributed with the next distribution request, but the last distribution was July 9 and this case is still waiting.

BLUF: I believe we can unstick this case by following the Bat Team instructions for RedistributedCase::CannotRedistribute.

It looks like it was distributed to BMULLINS in Nov 2019:

> DistributedCase.where(case_id: 3567789)
=> [#<DistributedCase:0x000000000b3bb658
  id: 85024,
  distribution_id: 4449,
  case_id: "3567789",
  docket: "legacy",
  priority: true,
  genpop: true,
  genpop_query: "any",
  docket_index: nil,
  ready_at: Mon, 25 Nov 2019 11:58:10 UTC +00:00,
  task_id: nil,
  created_at: Mon, 25 Nov 2019 17:02:25 UTC +00:00,
  updated_at: Mon, 25 Nov 2019 17:02:25 UTC +00:00>]
> d=Distribution.find(4449)
=> #<Distribution:0x000000000b29a710
 id: 4449,
 judge_id: 1241,
 status: "completed",
 completed_at: Mon, 25 Nov 2019 17:02:28 UTC +00:00, ...
> d.judge
=> #<User:0x000000000a8e1e80
 id: 1241,
 station_id: "101",
 css_id: "BVABMULLINS", ...

and is up for redistribution:

> pp VACOLS::Priorloc.where(lockey: vacols_id).order(:locdout).pluck(:locdout, :locstto, :locstrcv)
[[Fri, 30 Jun 2017, "77", "JWAGNER"],
 [Tue, 01 May 2018, "99", "RO29"],
 [Sat, 20 Oct 2018, "77", "IMBUTLER"],
 [Wed, 07 Aug 2019, "78", "DEWC"],
 [Mon, 12 Aug 2019, "01", "DEWC"],
 [Mon, 12 Aug 2019, "57", "DSUSER"],
 [Mon, 12 Aug 2019, "CASEFLOW", "MLITTLE"],
 [Thu, 15 Aug 2019, "CASEFLOW", "VACOCARTER1"],
 [Mon, 25 Nov 2019, "81", "BMULLINS"],
 [Mon, 25 Nov 2019, "BMULLINS", "BMULLINS"],
 [Mon, 25 Nov 2019, "ANOLLEY", "VACOCARTER1"],
 [Mon, 25 Nov 2019, "CASEFLOW", "VACOCARTER1"],
 [Wed, 01 Apr 2020, "CASEFLOW", "VACOCARTER1"],
 [Wed, 29 Apr 2020, "81", "VACOCARTER1"],
 [Wed, 29 Apr 2020, "81", nil]]

The last location being 81 reminded me of RedistributedCase::CannotRedistribute.

I could not find a RedistributedCase::CannotRedistribute Sentry error for this case on or around July 9th, when the judge last got a distribution.

After digging into the code https://github.com/department-of-veterans-affairs/caseflow/blob/13b99749f8bac8b6d969f693f1d230f4fb2fa4dd/app/services/redistributed_case.rb#L18-L22

I tested distributing this case (based on this code) because it should fail to redistribute:

new_distrib=Distribution.new
new_distrib.judge_id=User.find_by(css_id: "BVAMMARTIN").id

rdc=RedistributedCase.new(case_id: 3567789, new_distribution: new_distrib)
rdc.ok_to_redistribute?
=> false
rdc.allow! # should result in a Sentry alert
=> false

A Sentry alert appeared as expected.

Since redistribution should fail, I try replicating behavior at a less-nested level in the code:

docket=LegacyDocket.new
da=docket.distribute_appeals(new_distrib, priority: true, genpop: "not_genpop", limit: 1)
=> []

which causes this Sentry alert as expected. This shows that it selects case 3567789 and is trying to redistribute it.
Running this updated the location_code (as expected):

> pp VACOLS::Priorloc.where(lockey: vacols_id).order(:locdout).pluck(:locdout, :locstto, :locstrcv)
=> ...
 [Mon, 25 Nov 2019, "ANOLLEY", "VACOCARTER1"],
 [Mon, 25 Nov 2019, "CASEFLOW", "VACOCARTER1"],
 [Wed, 01 Apr 2020, "CASEFLOW", "VACOCARTER1"],
 [Wed, 29 Apr 2020, "81", "VACOCARTER1"],
 [Wed, 29 Apr 2020, "81", "DSUSER"],
 [Wed, 15 Jul 2020, "MMARTIN", nil]]

A redistribution should have been attempted by Caseflow according to the results of VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAMMARTIN"),"not_genpop", 1000, dry_run: true) above based on this code.

If I can search Sentry for CannotRedistribute and 3567789, then I can confirm if a redistribution was attempted (besides the manual ones I just attempted).

Why is this case failing to redistribute? Looks like it could be due to tasks still being open in caseflow https://github.com/department-of-veterans-affairs/caseflow/blob/13b99749f8bac8b6d969f693f1d230f4fb2fa4dd/app/services/redistributed_case.rb#L26-L38

@alisan16 I renamed the existing distributed case (since Bat Team typically does this anyway), which will unstick the case.

dc=DistributedCase.find_by(case_id: 3567789)
dc.update!(case_id: "#{dc.case_id}-attempt1")

Open question: I could not confirm if a redistribution attempt was made (I can't find evidence in Sentry). And if not attempted, why? All my testing shows that redistribution of the case should have been attempted. I'll keep an eye on the Metabase tables.

Slack convo with Hunter as a sanity check

double checked all priority appeals the case_ready_date was earlier than the last_judge_distrib based on metabase

def legacy_appeal_relevant_tasks(legacy_appeal)
  legacy_appeal.tasks.reject do |task|
    task.is_a?(TrackVeteranTask) || task.is_a?(RootTask)
  end
end
def legacy_appeal_hearing_tasks(legacy_appeal)
  legacy_appeal_relevant_tasks(legacy_appeal).select { |task| task.is_a?(HearingTask) }
end
def ok_to_redistribute?(legacy_appeal)
  return true if legacy_appeal_relevant_tasks(legacy_appeal).blank?
  return false if legacy_appeal_relevant_tasks(legacy_appeal).any?(&:open?)
  return true if !legacy_appeal_hearing_tasks(legacy_appeal).empty? && legacy_appeal_hearing_tasks(legacy_appeal).all?(&:cancelled?)
  false
end
vacols_ids = %w"4009420 4043579 4037606 4036646 4025076 4047259 4048922 3692374 4050054 4003730 3819806 4051641 3993694 3202745 3733544 3841892 4048540 4039189 4039514 4051434 4050593 3694659 4051596 4040195 3274453 3607891 4039384 4051589 3150132 3409818 4049132 4050394 4035809 3232624 4051438 4053257 4053064 4053514 4005931 4052716 4052849 4053411 4026290 4052267 4053319 4027163 4053604 4052121 4053297 4026828 4042996 4053924 4052087 4053882 4052746 4027286 3255605L 4045504 4046884 4006087 4053355 4053776 4053544 4053858 4053291 4053311 4052794 4053940 4044661 4052893 4050272 4047022 4053056 4052962 4045592 4038281 4053395 4050764 4052900 4034041 4052093 4051426 4053475 4027284 4049669 4052174 4008260 4027486 4054038 4052969 4028557 4043003 3753239 4052467 4053504 4053867 3921982 4053945 4053747 4053573 2887363 4053497 4027430 4033615 4027489 4053432 4052493 3948393 4052558 4050623 4052919 4053736 4052878 4053737 4052368 4053869 4052960 4052918 4044984 4053371 4041678 4053094 4053561 4053951 4053752 4052808 4052090 4052763 4052124 2766687 4027585 3998387 4053780 4053313 4052820 4053766 4026703 4053793 4053241 4052330 4055145 4031764 4029762 3642899 3010352 3485149 4054687 3949148 4031057 4051583 4042004 4032541 4054835 4055018 4055038 4005263 2990134 4050615 3995552 4032982 4051585 4029863 4054577 4055190 4054925 4042587 2634267 4055036 4055120 4055136 4055008 4054872 4055148 4055033 4055015 4045348 3122465 4055110 4015307 3184631 4055130 4054962 4054926 4032856 4052617"

appeals = LegacyAppeal.where(vacols_id: vacols_ids)
appeals_needing_redistribution = appeals.reject { |appeal| DistributedCase.find_by(case_id: appeal.vacols_id).nil? }
appeals_needing_redistribution.reject { |appeal| ok_to_redistribute?(appeal) }.map(&:vacols_id)
=> ["3232624", "3607891", "3753239"]

@yoomlam looks like we have 3 more cases that will not be distributed the next time their judge requests cases

Thanks @hschallhorn! You saved me a bunch of time โณ .

Enabling those 3 cases to be redistributed:

appeals_needing_redistribution.count
=> 20
cases_with_existing_distributed_case=appeals_needing_redistribution.reject { |appeal| ok_to_redistribute?(appeal) }.map(&:vacols_id)
cases_with_existing_distributed_case.map{|case_id|
  dc=DistributedCase.find_by(case_id: case_id)
  dc.update!(case_id: "#{case_id}-attempt1")
}

# Double-checking:
appeals_needing_redistribution = appeals.reject { |appeal| DistributedCase.find_by(case_id: appeal.vacols_id).nil? }
appeals_needing_redistribution.count
=> 17
appeals_needing_redistribution.reject { |appeal| ok_to_redistribute?(appeal) }.map(&:vacols_id)
=> []

We'll no longer have to do this manually once a PR for Automate fix for RedistributedCase::CannotRedistribute Sentry alert #14705 is deployed.

Weekly check at Priority Legacy Appeals Ready for Distribution Tied to Judges who actively pull distributions
shows:
image

# Check cases that would be distributed to BVAKALIBRAN on the next request
> VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAKALIBRAN"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4001319", "bfdloout"=>2020-04-01 00:00:00 UTC, "vlj"=>"398"},
 {"bfkey"=>"4052893", "bfdloout"=>2020-07-10 00:00:00 UTC, "vlj"=>"398"},
 {"bfkey"=>"4055968", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"398"},
 {"bfkey"=>"4056500", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"398"},
 {"bfkey"=>"4056603", "bfdloout"=>2020-07-19 00:00:00 UTC, "vlj"=>"398"},
 {"bfkey"=>"3438443", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"398"},
 {"bfkey"=>"4057120", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"398"}]
# Good: case 4001319 should be distributed

# Check for existing DistributedCase that would prevent distribution:
> DistributedCase.find_by(case_id: "40001319")
=> nil

Looks good!

image

# Check for existing DistributedCase that would prevent distribution:
> DistributedCase.find_by(case_id: "3482461")
=> nil
> DistributedCase.find_by(case_id: "4008732")
=> nil
> DistributedCase.find_by(case_id: "4034620")
=> nil
> DistributedCase.find_by(case_id: "4044582")
=> nil
> DistributedCase.find_by(case_id: "3770758")
=> nil
> DistributedCase.find_by(case_id: "2947232")
=> nil
> DistributedCase.find_by(case_id: "4022507")
=> nil
> DistributedCase.find_by(case_id: "4025076")
=> nil

# Check cases that would be distributed to judges on the next request
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVADWSINGLE"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"3482461", "bfdloout"=>2020-01-18 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4027163", "bfdloout"=>2020-07-09 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4054852", "bfdloout"=>2020-07-14 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4057327", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4057962", "bfdloout"=>2020-07-21 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4056126", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4044643", "bfdloout"=>2020-07-23 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"2896191", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"3609373", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"450"},
 {"bfkey"=>"4059783", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"450"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVANKROES"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4008732", "bfdloout"=>2020-04-30 00:00:00 UTC, "vlj"=>"955"},
 {"bfkey"=>"4055042", "bfdloout"=>2020-07-17 00:00:00 UTC, "vlj"=>"955"},
 {"bfkey"=>"4039986", "bfdloout"=>2020-07-17 00:00:00 UTC, "vlj"=>"955"},
 {"bfkey"=>"4056303", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"955"},
 {"bfkey"=>"4058333", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"955"},
 {"bfkey"=>"4058372", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"955"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAPMLYNCH"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4034620", "bfdloout"=>2020-05-26 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"4057620", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"4057331", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"3041005", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"3988687", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"4049014", "bfdloout"=>2020-07-23 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"4059608", "bfdloout"=>2020-07-26 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"4059609", "bfdloout"=>2020-07-26 00:00:00 UTC, "vlj"=>"438"},
 {"bfkey"=>"4059814", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"438"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAEDEICHERT"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4044582", "bfdloout"=>2020-06-07 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4056827", "bfdloout"=>2020-07-19 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4057066", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4056943", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4058467", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4059816", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"1144"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAJFRANCIS"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"3770758", "bfdloout"=>2020-06-10 00:00:00 UTC, "vlj"=>"881"},
 {"bfkey"=>"3443428", "bfdloout"=>2020-06-30 00:00:00 UTC, "vlj"=>"881"},
 {"bfkey"=>"4058134", "bfdloout"=>2020-07-21 00:00:00 UTC, "vlj"=>"881"},
 {"bfkey"=>"4054979", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"881"},
 {"bfkey"=>"4052915", "bfdloout"=>2020-07-23 00:00:00 UTC, "vlj"=>"881"},
 {"bfkey"=>"4059789", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"881"},
 {"bfkey"=>"4059839", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"881"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVALBARNARD"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"2947232", "bfdloout"=>2020-06-10 00:00:00 UTC, "vlj"=>"323"},
 {"bfkey"=>"4058617", "bfdloout"=>2020-07-23 00:00:00 UTC, "vlj"=>"323"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVADHACHEY"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4022507", "bfdloout"=>2020-06-16 00:00:00 UTC, "vlj"=>"824"},
 {"bfkey"=>"4058271", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"824"},
 {"bfkey"=>"4059785", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"824"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAJMONROE"),"not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4025076", "bfdloout"=>2020-06-26 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4053021", "bfdloout"=>2020-07-10 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4048334", "bfdloout"=>2020-07-16 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4056578", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4057343", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"3663616", "bfdloout"=>2020-07-21 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4057723", "bfdloout"=>2020-07-21 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4058937", "bfdloout"=>2020-07-24 00:00:00 UTC, "vlj"=>"418"},
 {"bfkey"=>"4041450", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"418"}]

Weekly check:
image

Updated 2 DistributedCases that has a non-null last_case_distrib so that distribution will succeed:

dc=DistributedCase.find_by(case_id: "3201779")
=> #<DistributedCase:0x000000000c2e6b28
 id: 31810,
 distribution_id: 1665,
 ...
dc.update!(case_id: "#{dc.case_id}-attempt1")
=> true

dc=DistributedCase.find_by(case_id: "3959600")
=> #<DistributedCase:0x000000000b034278
 id: 71597,
 distribution_id: 3874,
 ...
dc.update!(case_id: "#{dc.case_id}-attempt1")
=> true

Let's look at the cases the were ready in June.

judges=%w[BVASHENEKS BVADJOHNSON BVADHACHEY BVANDOAN BVAEDEICHERT BVAVCLEMENT BVASDREISS BVADHACHEY BVAMAPAPPAS]
=> ["BVASHENEKS", "BVADJOHNSON", "BVADHACHEY", "BVANDOAN", "BVAEDEICHERT", "BVAVCLEMENT", "BVASDREISS", "BVADHACHEY", "BVAMAPAPPAS"]

# Just look at the next case to be distributed and compare against Metabase:
judges.map{|jcss_id| VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true).first}
=> [{"bfkey"=>"3272013", "bfdloout"=>2019-12-05 00:00:00 UTC, "vlj"=>"945"},
 {"bfkey"=>"4017646", "bfdloout"=>2020-03-19 00:00:00 UTC, "vlj"=>"895"},
 {"bfkey"=>"3556214", "bfdloout"=>2020-03-25 00:00:00 UTC, "vlj"=>"824"},
 {"bfkey"=>"2893151", "bfdloout"=>2020-03-26 00:00:00 UTC, "vlj"=>"918"},
 {"bfkey"=>"4044582", "bfdloout"=>2020-06-07 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"3098142", "bfdloout"=>2020-06-10 00:00:00 UTC, "vlj"=>"571"},
 {"bfkey"=>"3579388", "bfdloout"=>2020-06-10 00:00:00 UTC, "vlj"=>"467"},
 {"bfkey"=>"3556214", "bfdloout"=>2020-03-25 00:00:00 UTC, "vlj"=>"824"},  # investigate BVADHACHEY
 {"bfkey"=>"3201779", "bfdloout"=>2020-06-30 00:00:00 UTC, "vlj"=>"346"}]

All except one will be distributed next. Let's get BVADHACHEY's full distribution:

VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVADHACHEY"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"3556214", "bfdloout"=>2020-03-25 00:00:00 UTC, "vlj"=>"824"},
 {"bfkey"=>"4022507", "bfdloout"=>2020-06-16 00:00:00 UTC, "vlj"=>"824"},
 {"bfkey"=>"4058271", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"824"}]

Ok good. 4022507 will be the second case distributed.

Looked into a few cases that were ready in July.
image

Why does BVAJHWA only get distributed 1 case, and that case does not match either of the 2 that are tied to them?

VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVAJHWA"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4033448", "bfdloout"=>2020-08-03 00:00:00 UTC, "vlj"=>"947"}]

jt=JudgeTeam.for_judge(User.find_by(css_id:"BVAJHWA"))
jt.non_admins.size
=> 8

Answer: Because the 2 cases were recently distributed (Metabase is querying outdated data in Redshift).

dc=DistributedCase.find_by(case_id: "4053311")
=> #<DistributedCase:0x000000000e41e188
 id: 162671,
 distribution_id: 8103,
 case_id: "4053311",
 docket: "legacy",
 priority: true,
 genpop: false,
 genpop_query: "not_genpop",
 docket_index: nil,
 ready_at: Sat, 11 Jul 2020 00:00:00 UTC +00:00,
 task_id: nil,
 created_at: Mon, 03 Aug 2020 14:05:05 UTC +00:00,
 updated_at: Mon, 03 Aug 2020 14:05:05 UTC +00:00>
dc=DistributedCase.find_by(case_id: "4047313")
=> #<DistributedCase:0x000000000e1aa280
 id: 162672,
 distribution_id: 8103,
 case_id: "4047313",
 docket: "legacy",
 priority: true,
 genpop: false,
 genpop_query: "not_genpop",
 docket_index: nil,
 ready_at: Thu, 16 Jul 2020 00:00:00 UTC +00:00,
 task_id: nil,
 created_at: Mon, 03 Aug 2020 14:05:05 UTC +00:00,
 updated_at: Mon, 03 Aug 2020 14:05:05 UTC +00:00>

The remaining cases in the screenshot will be distributed in the judge's next request:

VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVAJREINHART"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4015307", "bfdloout"=>2020-07-15 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4040592", "bfdloout"=>2020-07-17 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4018707", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4032547", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4054375", "bfdloout"=>2020-07-23 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4018929", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4060269", "bfdloout"=>2020-07-30 00:00:00 UTC, "vlj"=>"894"},
 {"bfkey"=>"4033183", "bfdloout"=>2020-07-30 00:00:00 UTC, "vlj"=>"894"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVAEDEICHERT"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4044582", "bfdloout"=>2020-06-07 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4056827", "bfdloout"=>2020-07-19 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4056943", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4057066", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4058467", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4060808", "bfdloout"=>2020-07-30 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4033060", "bfdloout"=>2020-07-30 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4061071", "bfdloout"=>2020-07-31 00:00:00 UTC, "vlj"=>"1144"},
 {"bfkey"=>"4061654", "bfdloout"=>2020-08-02 00:00:00 UTC, "vlj"=>"1144"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVAVMOSHI"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4047271", "bfdloout"=>2020-07-17 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4052680", "bfdloout"=>2020-07-17 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4055908", "bfdloout"=>2020-07-17 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4056707", "bfdloout"=>2020-07-19 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4057588", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4047071", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4058312", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4058404", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4058945", "bfdloout"=>2020-07-24 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4058954", "bfdloout"=>2020-07-24 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4058952", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4003003", "bfdloout"=>2020-07-30 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"3880501", "bfdloout"=>2020-07-30 00:00:00 UTC, "vlj"=>"1591"},
 {"bfkey"=>"4048881", "bfdloout"=>2020-08-03 00:00:00 UTC, "vlj"=>"1591"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVAMTENNER"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4027286", "bfdloout"=>2020-07-10 00:00:00 UTC, "vlj"=>"728"},
 {"bfkey"=>"4027497", "bfdloout"=>2020-07-16 00:00:00 UTC, "vlj"=>"728"},
 {"bfkey"=>"4056038", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"728"},
 {"bfkey"=>"4028736", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"728"},
 {"bfkey"=>"4053083", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"728"},
 {"bfkey"=>"4059999", "bfdloout"=>2020-07-27 00:00:00 UTC, "vlj"=>"728"},
 {"bfkey"=>"4061849", "bfdloout"=>2020-08-02 00:00:00 UTC, "vlj"=>"728"}]
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id:"BVAHROBERT"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4056560", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4056276", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4043684", "bfdloout"=>2020-07-20 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4057960", "bfdloout"=>2020-07-21 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4058413", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4050091", "bfdloout"=>2020-07-22 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4059726", "bfdloout"=>2020-07-26 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4047262", "bfdloout"=>2020-07-28 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4043096", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4060518", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4060562", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4048019", "bfdloout"=>2020-07-31 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4061889", "bfdloout"=>2020-08-02 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4043951", "bfdloout"=>2020-08-03 00:00:00 UTC, "vlj"=>"536"}]

Looking at priority legacy cases not tied to a judge that have a non-null last_case_distrib in this Metabase view, I updated the DistributedCases so that distribution will succeed:

dc=DistributedCase.find_by(case_id: "3990529")
=> #<DistributedCase:0x000000000e409210
dc.update!(case_id: "#{dc.case_id}-attempt1")
=> true

dc=DistributedCase.find_by(case_id: "4047114")
=> #<DistributedCase:0x000000000e243e08
dc.update!(case_id: "#{dc.case_id}-attempt1")
=> true

dc=DistributedCase.find_by(case_id: "3175907")
=> #<DistributedCase:0x000000000c925228
dc.update!(case_id: "#{dc.case_id}-attempt1")
=> true

dc=DistributedCase.find_by(case_id: "3959600")
=> nil

Weekly check:
image

None of the 328 listed appeals have a non-null last_case_distrib so there shouldn't be existing DistributedCases to prevent distribution.
Checking to make sure appeals will be distributed in the next distribution (with some automation):

copied_from_table=%w[
BVAGWASIK 3867877
BVALJENG 3953218
BVAWDONNELLY 4045098
BVADHACHEY 4022507
BVAMSORISIO 3909167
BVAMELARKIN 3567017
BVATCATINO 3380380
BVAMTENNER 4027286
BVAMTENNER 4056038
BVAMTENNER 4027497
BVAHROBERT 4056276
BVASKREMBS 4056743
BVAHROBERT 4056560
BVAMKILCOYN 4055148
VACOSTROMG 4052443
BVAMTENNER 4053083
BVAHROBERT 4058413
BVAHROBERT 4059726
BVASKREMBS 4051638
BVAMKILCOYN 4051007
BVADGRATZ 4058607
BVAJZJONES 4048568
BVAHROBERT 4043684
BVAMELARKIN 4059707
BVAMAUER 4058337
BVAVELEZE 4058650
BVAMAUER 4054095
BVAMTENNER 4028736
BVALBARNARD 4058617
]
judge_appeals=copied_from_table.in_groups_of(2).map{|pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{|jcss_id,vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, bfs.pluck("bfkey").find_index(vacols_id)]
}

# Which cases will not be distributed as the next appeal?
appeal_indices.select{|jcss_id, app_id| app_id!=0}
=> [["BVAMTENNER", 2],
 ["BVAMTENNER", 1],
 ["BVAHROBERT", 1],
 ["BVAMTENNER", 4],
 ["BVAHROBERT", 4],
 ["BVAHROBERT", 6],
 ["BVASKREMBS", 1],
 ["BVAMKILCOYN", 1],
 ["BVAHROBERT", 2],
 ["BVAMELARKIN", 1],
 ["BVAMAUER", 1],
 ["BVAMTENNER", 3]]
# BVAMTENNER and BVAHROBERT will get several priority legacy appeals in the next distribution

# Which cases will not be distributed in the next set of distribution?
appeal_indices.select{|jcss_id, app_id| app_id.nil?}
=> []

Looks good! We can use the above for automation if desired.

Addressed 2 cases:

case_ids=%w[3899368 3219154]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc.update!(case_id: "#{dc.case_id}-attempt1")
}

Checking all cases with case_ready_date through the end of July:

copied_from_table=%w[
BVAGRSENYK 3899368
BVAHSEESEL 3669425
BVAGWASIK 3867877
BVALJENG 3953218
BVADHACHEY 4022507
BVAMSORISIO 3909167
BVAMTENNER 4027286
BVATCATINO 3380380
BVAMTENNER 4027497
BVAMTENNER 4056038
BVASKREMBS 4056743
BVAHROBERT 4056560
BVAMKILCOYN 4055148
BVASKREMBS 4051638
BVAMTENNER 4053083
BVADGRATZ 4058607
BVAMKILCOYN 4051007
BVALBARNARD 4058617
BVAMTENNER 4028736
BVADHACHEY 4058271
BVAMKILCOYN 3993738
BVALBARNARD 4059042
BVAMJSKALT 4041571
BVAMKILCOYN 4054027
BVASKREMBS 4048569
BVALREIN 4031099
VACOWHITEY 4047231
BVASKREMBS 4057895
BVAETAMLYN 4061016
BVAASPECTOR 4045869
BVALBARNARD 4061831
BVAMTENNER 4061849
BVALBARNARD 4031851
BVAMKILCOYN 4032588
BVAAJAEGER 4044096
BVAMKILCOYN 4060256
BVALBARNARD 4044637
BVAESLEBOFF 4056270
BVAGWASIK 4027652
BVAMTENNER 4059999
VACOWHITEY 4048925
BVAAPSIMPSON 4054659
BVAAPSIMPSON 4060261
BVASKREMBS 4051601
BVAAJAEGER 4060934
BVAJMONROE 4061638
BVAAJAEGER 4017846
BVAAPSIMPSON 4058262
BVALBARNARD 4053055
BVAAPSIMPSON 4061844
];
judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, bfs.pluck("bfkey").find_index(vacols_id)]
}
# Which cases will not be distributed as the next appeal?
appeal_indices.select{ |jcss_id, app_id| app_id!=0}
=> [["BVAMTENNER", 1],
 ["BVAMTENNER", 2],
 ["BVASKREMBS", 1],
 ["BVAMTENNER", 4],
 ["BVAMKILCOYN", 2],
 ["BVAMTENNER", 3],
 ["BVADHACHEY", 1],
 ["BVAMKILCOYN", 1],
 ["BVALBARNARD", 1],
 ["BVAMKILCOYN", 5],
 ["BVASKREMBS", 3],
 ["VACOWHITEY", 1],
 ["BVASKREMBS", 4],
 ["BVALBARNARD", 5],
 ["BVAMTENNER", 6],
 ["BVALBARNARD", 4],
 ["BVAMKILCOYN", 3],
 ["BVAAJAEGER", 2],
 ["BVAMKILCOYN", 4],
 ["BVALBARNARD", 3],
 ["BVAGWASIK", 1],
 ["BVAMTENNER", 5],
 ["BVAAPSIMPSON", 1],
 ["BVASKREMBS", 2],
 ["BVAAJAEGER", 1],
 ["BVAAPSIMPSON", 2],
 ["BVALBARNARD", 2],
 ["BVAAPSIMPSON", 3]]

# Which cases will not be distributed in the next set of distributions?
appeal_indices.select{|jcss_id, app_id| app_id.nil?}
=> []

Looks good.

Addressed 1 case:

case_ids=%w[3860945]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc.update!(case_id: "#{dc.case_id}-attempt1")
}

Checking all cases with case_ready_date through the end of July:

copied_from_table=%w[
BVACBRUCE 4047236
BVADHACHEY 4022507
BVAMBLACK 3822290
BVAMTENNER 4027286
BVAMTENNER 4056038
BVAMTENNER 4027497
BVASKREMBS 4056743
BVAHROBERT 4056560
BVAMKILCOYN 4055148
BVASKREMBS 4051638
BVAMTENNER 4053083
BVAMKILCOYN 4051007
BVAMTENNER 4028736
BVADHACHEY 4058271
BVAMKILCOYN 3993738
BVALBARNARD 4059042
BVAMJSKALT 4041571
BVAMKILCOYN 4054027
BVASKREMBS 4048569
BVAASPECTOR 4045869
VACOWHITEY 4047231
BVASKREMBS 4057895
BVALBARNARD 4061831
BVAMTENNER 4061849
BVALBARNARD 4031851
BVAMKILCOYN 4060256
BVAAJAEGER 4044096
BVAMKILCOYN 4032588
BVALBARNARD 4044637
BVAMTENNER 4059999
VACOWHITEY 4048925
BVAAPSIMPSON 4054659
BVAAPSIMPSON 4060261
BVASKREMBS 4051601
BVAAJAEGER 4060934
BVAJMONROE 4061638
BVAAJAEGER 4017846
BVALBARNARD 4053055
BVAAPSIMPSON 4058262
BVAAPSIMPSON 4061844
];
judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
# Which cases will not be distributed as the next appeal?
appeal_indices.select{ |jcss_id, app_id| app_id!=0}
=> [["BVAMTENNER", 2],
 ["BVAMTENNER", 1],
 ["BVASKREMBS", 1],
 ["BVAMTENNER", 4],
 ["BVAMKILCOYN", 1],
 ["BVAMTENNER", 3],
 ["BVADHACHEY", 1],
 ["BVAMKILCOYN", 2],
 ["BVALBARNARD", 1],
 ["BVAMKILCOYN", 5],
 ["BVASKREMBS", 4],
 ["VACOWHITEY", 1],
 ["BVASKREMBS", 3],
 ["BVALBARNARD", 4],
 ["BVAMTENNER", 6],
 ["BVALBARNARD", 3],
 ["BVAMKILCOYN", 4],
 ["BVAAJAEGER", 1],
 ["BVAMKILCOYN", 3],
 ["BVALBARNARD", 2],
 ["BVAMTENNER", 5],
 ["BVAAPSIMPSON", 2],
 ["BVASKREMBS", 2],
 ["BVAAJAEGER", 2],
 ["BVAAPSIMPSON", 1],
 ["BVAAPSIMPSON", 3]]

# Which cases will not be distributed in the next set of distributions?
appeal_indices.select{|jcss_id, app_id| app_id.nil?}
=> []

Looks good.
Also checked about 200 subsequent cases.

Many cases need redistributing:
image

# cases ready in July
case_ids=%w[4047236
4056743
4051638
4031851
4053055
4017846
4051601
4044637
4057895
4061831
4059042
4048569
4060934
4044096 ]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc.update!(case_id: "#{dc.case_id}-attempt1")
}

# cases ready in Aug
case_ids=%w[
4063157
4062124
4030236
4055303
4042962
4063164
3768750
4045772
4058434
3824613
4063750
4059778
4030244
4042665
4024432
4058243
4061074
4061840
2528382
4034139
4051602
4064899
4048062
4052511
4064442
4008917
4064435
4050399
4052596
4063766
4047940
4063964
4063657
4050421
4045543
4032366
4035888
4061087
4056774
4034947
4061627
4066043
4065728
4066173
4065308
4066758
4066249
4066625
4066698
4060603
4067507
4043548
4066675
4063826
4054988
4066630
4067416
4067818
4036145
4066070
4015849
4067475
4047373
4059045
4065078
4065774
4067143
4059373
4054518
4065415
4042748
4057508
4066906
4054616
4067224
4050994
4065347
4066506
4065089
4067661
4067159
4065321
4037240
4063488
4052426
4067184
4032535
4066102
4066349
4066710
4067311
4062394
4066661
4067588
4034062
4063669
4063986
4066255
4065311
4067082
4067906
4067391
4053251
4065310
4058118
4066178
4066831
4067865
4067926
4036583
4044518
4039165
4066480
4036078
4067122
4066533
4067519
4067109
4067626
4065450
4030955
4067817
4065393
4068068
4068547
4056450
4069227
4068345
4059611
4068065
4068302
4029866
4039497
4068758
4011382
4061636
4040032
4064846
4068338
4064793
4068542
4057226
4038983
4068827
4019091
4037666
4068702
4065313
4029036
4069496
4041520
3569479
4065402
4040033
4068256
4069063
4068610
4069050
4068206
4069117
4069024
4068237
]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc.update!(case_id: "#{dc.case_id}-attempt1")
}
copied_from_table=%w[
BVACBRUCE 4047236
BVADHACHEY 4022507
BVAKBANFIELD 2993728
BVADAMES 3647167
BVASKREMBS 4056743
BVAHROBERT 4056560
BVASKREMBS 4051638
BVADHACHEY 4058271
BVADBRENN 3868150
BVALBARNARD 4031851
BVALBARNARD 4053055
BVAAJAEGER 4017846
BVASKREMBS 4051601
BVALBARNARD 4044637
BVASKREMBS 4057895
BVALBARNARD 4061831
BVALBARNARD 4059042
BVASKREMBS 4048569
BVAASPECTOR 4045869
BVAAJAEGER 4060934
BVAAPSIMPSON 4054659
BVAAJAEGER 4044096
BVAJMONROE 4061638
BVAMJSKALT 4041571
BVAAPSIMPSON 4058262
VACOWHITEY 4047231
BVAAPSIMPSON 4061844
VACOWHITEY 4048925
BVAAPSIMPSON 4060261
]
judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
# Which cases will not be distributed as the next appeal?
appeal_indices.select{ |jcss_id, vacols_id, app_id| app_id!=0}
# Which cases will not be distributed in the next set of distributions?
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVACBRUCE", "4047236", nil],
 ["BVADAMES", "3647167", nil],  # <-- distributed today
 ["BVASKREMBS", "4056743", nil],
 ["BVASKREMBS", "4051638", nil],
 ["BVALBARNARD", "4031851", nil],
 ["BVALBARNARD", "4053055", nil],
 ["BVAAJAEGER", "4017846", nil],
 ["BVASKREMBS", "4051601", nil],
 ["BVALBARNARD", "4044637", nil],
 ["BVASKREMBS", "4057895", nil],
 ["BVALBARNARD", "4061831", nil],
 ["BVALBARNARD", "4059042", nil],
 ["BVASKREMBS", "4048569", nil],
 ["BVAAJAEGER", "4060934", nil],
 ["BVAAJAEGER", "4044096", nil]]

Why are these cases not being distributed?

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVACBRUCE"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4071595", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"1062"}]

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVADAMES"), "not_genpop", 1000, dry_run: true)
=> []

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVASKREMBS"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4041573", "bfdloout"=>2020-08-28 00:00:00 UTC, "vlj"=>"840"}]

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVALBARNARD"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4069782", "bfdloout"=>2020-08-26 00:00:00 UTC, "vlj"=>"323"}, {"bfkey"=>"4056029", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"323"}]

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAAJAEGER"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4071431", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"784"}]

Not many are being distributed at a time -- curious.

Where are the cases currently? When were they distributed?

not_dist.map{  |jcss_id, vacols_id, app_id| [jcss_id, LegacyAppeal.find_by_vacols_id(vacols_id).location_code, vacols_id, DistributedCase.find_by(case_id: "#{vacols_id}")&.created_at, DistributedCase.find_by(case_id: "#{vacols_id}-attempt1")&.created_at] }
=> [["BVACBRUCE", "VACOMILLEN2", "4047236", nil, Fri, 28 Aug 2020 14:43:29 UTC +00:00],
 ["BVADAMES", "DAMES", "3647167", Mon, 31 Aug 2020 19:45:08 UTC +00:00, nil],  # distributed to correct location
 ["BVASKREMBS", "SKREMBS", "4056743", nil, Wed, 26 Aug 2020 17:25:05 UTC +00:00],   # distributed to correct location
 ["BVASKREMBS", "SMITHJ5", "4051638", nil, Wed, 26 Aug 2020 17:25:05 UTC +00:00],
 ["BVALBARNARD", "CASEFLOW", "4031851", nil, Wed, 26 Aug 2020 11:39:03 UTC +00:00],
 ["BVALBARNARD", "ELLIOR", "4053055", nil, Wed, 26 Aug 2020 11:39:03 UTC +00:00],
 ["BVAAJAEGER", "AJAEGER", "4017846", nil, Wed, 26 Aug 2020 20:52:39 UTC +00:00],  # distributed to correct location
 ["BVASKREMBS", "SKREMBS", "4051601", nil, Wed, 26 Aug 2020 17:25:05 UTC +00:00],  # distributed to correct location
 ["BVALBARNARD", "ZIMMEM", "4044637", nil, Wed, 26 Aug 2020 11:39:03 UTC +00:00],
 ["BVASKREMBS", "SKREMBS", "4057895", nil, Wed, 26 Aug 2020 17:25:05 UTC +00:00],  # distributed to correct location
 ["BVALBARNARD", "LBARNARD", "4061831", nil, Wed, 26 Aug 2020 11:39:03 UTC +00:00],  # distributed to correct location
 ["BVALBARNARD", "ZIMMEM", "4059042", nil, Wed, 26 Aug 2020 11:39:03 UTC +00:00],
 ["BVASKREMBS", "SMITHJ5", "4048569", nil, Wed, 26 Aug 2020 17:25:05 UTC +00:00],
 ["BVAAJAEGER", "CLARKK1", "4060934", nil, Wed, 26 Aug 2020 20:52:39 UTC +00:00],
 ["BVAAJAEGER", "VACOWAITEJ", "4044096", nil, Wed, 26 Aug 2020 20:52:39 UTC +00:00]]

Some were distributed to the correct location on Wed or Fri. 1 was distribute today.

Some judges have many appeals to be distributed.

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAAPSIMPSON"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4060261", "bfdloout"=>2020-07-28 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4054659", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4058262", "bfdloout"=>2020-07-29 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4061844", "bfdloout"=>2020-08-02 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4062332", "bfdloout"=>2020-08-04 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4063006", "bfdloout"=>2020-08-06 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4054845", "bfdloout"=>2020-08-14 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4048963", "bfdloout"=>2020-08-17 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4066052", "bfdloout"=>2020-08-20 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4066358", "bfdloout"=>2020-08-20 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4036052", "bfdloout"=>2020-08-20 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4069495", "bfdloout"=>2020-08-25 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4054232", "bfdloout"=>2020-08-26 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4071152", "bfdloout"=>2020-08-28 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4071157", "bfdloout"=>2020-08-28 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4035495", "bfdloout"=>2020-08-28 00:00:00 UTC, "vlj"=>"607"},
 {"bfkey"=>"4060382", "bfdloout"=>2020-08-28 00:00:00 UTC, "vlj"=>"607"}]

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVAHROBERT"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4056560", "bfdloout"=>2020-07-18 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4064947", "bfdloout"=>2020-08-14 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4065172", "bfdloout"=>2020-08-17 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4065509", "bfdloout"=>2020-08-18 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4042885", "bfdloout"=>2020-08-18 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4066129", "bfdloout"=>2020-08-20 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4066294", "bfdloout"=>2020-08-20 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4066521", "bfdloout"=>2020-08-20 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4068509", "bfdloout"=>2020-08-24 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4069086", "bfdloout"=>2020-08-25 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"3522510", "bfdloout"=>2020-08-25 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4069616", "bfdloout"=>2020-08-25 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4066525", "bfdloout"=>2020-08-27 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4067767", "bfdloout"=>2020-08-27 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4071554", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4070000", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"4057769", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"536"},
 {"bfkey"=>"3991548", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"536"}]

Let's examine the undistributed cases:

pp LegacyAppeal.find_by_vacols_id("4047236").location_history.pluck(:locdout, :locstto, :locstrcv)
[[Sun, 14 Jun 2020, "01", "VACOWOOLFQ"],
 [Sun, 14 Jun 2020, "81", "CBRUCE"],
 [Fri, 28 Aug 2020, "CBRUCE", "CBRUCE"],
 [Mon, 31 Aug 2020, "VACOMILLEN2", nil]]
# was at CBRUCE who assigned it to VACOMILLEN2 today

pp LegacyAppeal.find_by_vacols_id("4051638").location_history.pluck(:locdout, :locstto, :locstrcv)
=> [[Sun, 05 Jul 2020, "01", "CWILLIAMS"],
 [Sun, 05 Jul 2020, "55", "MCALLA"],
 [Wed, 08 Jul 2020, "55", "PLUMEM"],
 [Thu, 23 Jul 2020, "55", "VACOGRIGOA"],
 [Fri, 24 Jul 2020, "81", "SKREMBS"],
 [Wed, 26 Aug 2020, "SKREMBS", "SKREMBS"],
 [Wed, 26 Aug 2020, "SMITHJ5", nil]]
# judge recently reassigned to someone else

pp LegacyAppeal.find_by_vacols_id("4031851").location_history.pluck(:locdout, :locstto, :locstrcv)
=> [[Mon, 13 Apr 2020, "77", "VACOWEEKEC"],
 [Fri, 24 Apr 2020, "60", "VACODAVISD11"],
 [Wed, 29 Jul 2020, "81", "LBARNARD"],
 [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"],
 [Thu, 27 Aug 2020, "JMOATS", "JMOATS"],
 [Mon, 31 Aug 2020, "CASEFLOW", nil]]
# judge recently reassigned to someone else

pp LegacyAppeal.find_by_vacols_id("4053055").location_history.pluck(:locdout, :locstto, :locstrcv)
=> [[Fri, 10 Jul 2020, "01", "MCARTER"],
 [Fri, 10 Jul 2020, "55", "MCALLA"],
 [Wed, 15 Jul 2020, "55", "SSCOTT"],
 [Mon, 27 Jul 2020, "55", "VACOGRIGOA"],
 [Tue, 28 Jul 2020, "81", "LBARNARD"],
 [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"],
 [Mon, 31 Aug 2020, "ELLIOR", nil]]
# same

pp LegacyAppeal.find_by_vacols_id("4044637").location_history.pluck(:locdout, :locstto, :locstrcv)
pp LegacyAppeal.find_by_vacols_id("4059042").location_history.pluck(:locdout, :locstto, :locstrcv)
pp LegacyAppeal.find_by_vacols_id("4048569").location_history.pluck(:locdout, :locstto, :locstrcv)

It looks like Metabase is not using recent (Redshift) data, hence, it is reporting cases that have been distributed. I'll check again tomorrow when (hopefully) the data is updated.

case_ids_table=%w[
3647167 BVADAMES
4010528 BVALCOLLINS
];
case_ids_pairs=case_ids_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
# Check current location
undistrib_case_ids = case_ids_pairs.select{|cid, jcss_id|
  loc=LegacyAppeal.find_by_vacols_id(cid).location_code
  VACOLS::Staff.find_by(slogid: loc.upcase).sdomainid != jcss_id
}
=> []
# Both were distributed yesterday, so there's no need to rename DistributedCase
# Case may have recently been distributed to judge and judge reassigned case
undistrib_case_ids.map{|cid, jcss_id|
  pp LegacyAppeal.find_by_vacols_id(cid).location_history.pluck(:locdout, :locstto, :locstrcv)
}
copied_from_table=%w[
BVACBRUCE 4047236
BVADHACHEY 4022507
BVAKBANFIELD 2993728
BVASKREMBS 4056743
BVAHROBERT 4056560
BVADBRENN 3868150
BVADHACHEY 4058271
BVASKREMBS 4051638
BVAMJSKALT 4041571
BVALBARNARD 4059042
BVASKREMBS 4048569
BVAASPECTOR 4045869
VACOWHITEY 4047231
BVASKREMBS 4057895
BVALBARNARD 4061831
BVAAPSIMPSON 4054659
BVALBARNARD 4031851
BVASKREMBS 4051601
BVAAJAEGER 4044096
BVAJMONROE 4061638
BVALBARNARD 4044637
BVALBARNARD 4053055
VACOWHITEY 4048925
BVAAPSIMPSON 4058262
BVAAPSIMPSON 4060261
BVAAPSIMPSON 4061844
BVAAJAEGER 4060934
BVAAJAEGER 4017846
];
judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
# Which cases will not be distributed in the next set of distributions?
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVACBRUCE", "4047236", nil], 
 ["BVAKBANFIELD", "2993728", nil], 
 ["BVASKREMBS", "4056743", nil],
 ["BVADBRENN", "3868150", nil],
 ["BVASKREMBS", "4051638", nil],
 ["BVALBARNARD", "4059042", nil],
 ["BVASKREMBS", "4048569", nil],
 ["BVASKREMBS", "4057895", nil],
 ["BVALBARNARD", "4061831", nil],
 ["BVALBARNARD", "4031851", nil],
 ["BVASKREMBS", "4051601", nil],
 ["BVAAJAEGER", "4044096", nil],
 ["BVALBARNARD", "4044637", nil],
 ["BVALBARNARD", "4053055", nil],
 ["BVAAJAEGER", "4060934", nil],
 ["BVAAJAEGER", "4017846", nil]]

undistrib_cases = not_dist.select{|jcss_id, vacols_id, _| 
  loc=LegacyAppeal.find_by_vacols_id(vacols_id).location_code
  VACOLS::Staff.find_by(slogid: loc.upcase).sdomainid != jcss_id
}
=> [["BVACBRUCE", "4047236", nil], # judge recently reassigned to someone else
 ["BVASKREMBS", "4051638", nil],
 ["BVALBARNARD", "4059042", nil],
 ["BVASKREMBS", "4048569", nil],
 ["BVALBARNARD", "4031851", nil],
 ["BVAAJAEGER", "4044096", nil],
 ["BVALBARNARD", "4044637", nil],
 ["BVALBARNARD", "4053055", nil],
 ["BVAAJAEGER", "4060934", nil]]

time_assigned_to_judge=undistrib_cases.map{|jcss_id, vacols_id, _| 
  hist=LegacyAppeal.find_by_vacols_id(vacols_id).location_history.pluck(:locdout, :locstto, :locstrcv)
  hist.select{|locdout, locstto, locstrcv| locstrcv == VACOLS::Staff.find_by(sdomainid: jcss_id.upcase).slogid}
}
=> [[[Sun, 14 Jun 2020, "81", "CBRUCE"], [Fri, 28 Aug 2020, "CBRUCE", "CBRUCE"]],
 [[Fri, 24 Jul 2020, "81", "SKREMBS"], [Wed, 26 Aug 2020, "SKREMBS", "SKREMBS"]],
 [[Tue, 28 Jul 2020, "81", "LBARNARD"], [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"]],
 [[Tue, 28 Jul 2020, "81", "SKREMBS"], [Wed, 26 Aug 2020, "SKREMBS", "SKREMBS"]],
 [[Wed, 29 Jul 2020, "81", "LBARNARD"], [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"]],
 [[Fri, 31 Jul 2020, "81", "AJAEGER"], [Wed, 26 Aug 2020, "AJAEGER", "AJAEGER"]],
 [[Wed, 29 Jul 2020, "81", "LBARNARD"], [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"]],
 [[Tue, 28 Jul 2020, "81", "LBARNARD"], [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"]],
 [[Thu, 30 Jul 2020, "81", "AJAEGER"], [Wed, 26 Aug 2020, "AJAEGER", "AJAEGER"]]]
# All of these were recently assigned.

Now let's check cases ready in on Aug 3rd:

copied_from_table=%w[
BVALBARNARD 4030236
VACOWHITEY 4044424
VACOWHITEY 4062276
BVACTRUEBA 3768750
BVAMJSKALT 4061935
BVADWSINGLE 3427904
BVALBARNARD 4063157
BVADWIGHT 3824613
BVADBROWN 4019554
BVAAJAEGER 4042962
BVAAPSIMPSON 4063006
BVAAJAEGER 4045772
VACOWHITEY 4063033
BVALBARNARD 4063164
VACOWHITEY 4060676
BVALBARNARD 4062124
BVAMJSKALT 4028843
BVAAJAEGER 4058434
BVAAPSIMPSON 4062332
BVAJFRANCIS 3723677
BVADBROWN 4051356
BVAJZJONES 3655537
BVAAJAEGER 4055303
BVAMJSKALT 4052520
BVASKREMBS 4061074
];
judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
# Which cases will not be distributed in the next set of distributions?
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVALBARNARD", "4030236", nil],
 ["BVACTRUEBA", "3768750", nil],
 ["BVADWSINGLE", "3427904", nil],
 ["BVALBARNARD", "4063157", nil],
 ["BVADWIGHT", "3824613", nil],
 ["BVAAJAEGER", "4042962", nil],
 ["BVAAJAEGER", "4045772", nil],
 ["BVALBARNARD", "4063164", nil],
 ["BVALBARNARD", "4062124", nil],
 ["BVAAJAEGER", "4058434", nil],
 ["BVAJFRANCIS", "3723677", nil],
 ["BVAJZJONES", "3655537", nil],
 ["BVAAJAEGER", "4055303", nil],
 ["BVASKREMBS", "4061074", nil]]

undistrib_cases = not_dist.select{|jcss_id, vacols_id, _| 
  loc=LegacyAppeal.find_by_vacols_id(vacols_id).location_code
  VACOLS::Staff.find_by(slogid: loc.upcase).sdomainid != jcss_id
}
=> [["BVALBARNARD", "4030236", nil],
 ["BVADWSINGLE", "3427904", nil],
 ["BVAAJAEGER", "4042962", nil],
 ["BVAAJAEGER", "4058434", nil],
 ["BVAAJAEGER", "4055303", nil],
 ["BVASKREMBS", "4061074", nil]]

time_assigned_to_judge=undistrib_cases.map{|jcss_id, vacols_id, _| 
  hist=LegacyAppeal.find_by_vacols_id(vacols_id).location_history.pluck(:locdout, :locstto, :locstrcv)
  hist.select{|locdout, locstto, locstrcv| locstrcv == VACOLS::Staff.find_by(sdomainid: jcss_id.upcase).slogid}
}
=> [[[Tue, 04 Aug 2020, "81", "LBARNARD"], [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"]],
 [[Sun, 09 Aug 2020, "81", "DWSINGLE"], [Wed, 26 Aug 2020, "DWSINGLE", "DWSINGLE"]],
 [[Wed, 05 Aug 2020, "81", "AJAEGER"], [Wed, 26 Aug 2020, "AJAEGER", "AJAEGER"], [Mon, 31 Aug 2020, "AJAEGER", "AJAEGER"]],
 [[Wed, 05 Aug 2020, "81", "AJAEGER"], [Wed, 26 Aug 2020, "AJAEGER", "AJAEGER"]],
 [[Mon, 03 Aug 2020, "81", "AJAEGER"], [Wed, 26 Aug 2020, "AJAEGER", "AJAEGER"]],
 [[Thu, 13 Aug 2020, "81", "SKREMBS"], [Wed, 26 Aug 2020, "SKREMBS", "SKREMBS"]]]
# All of these were recently assigned.

PR #15080 updated the query to account for Virtual Hearings. I updated the Metabase queries: https://query.prod.appeals.va.gov/question/60 and https://query.prod.appeals.va.gov/question/42.

Other investigation notes:

Dig into 1 case and judge

On Tue Sep 1 15:23:14 CDT 2020

bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: "BVALBARNARD"), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4069782", "bfdloout"=>2020-08-26 00:00:00 UTC, "vlj"=>"323"},
 {"bfkey"=>"4071898", "bfdloout"=>2020-09-01 00:00:00 UTC, "vlj"=>"323"},
 {"bfkey"=>"4051106", "bfdloout"=>2020-09-01 00:00:00 UTC, "vlj"=>"323"}]

hist=LegacyAppeal.find_by_vacols_id(4030236).location_history.pluck(:locdout, :locstto, :locstrcv)
 => [[Mon, 06 Apr 2020, "77", "VACOWEEKEC"],
 [Sat, 18 Apr 2020, "60", "VACODAVISD11"],
 [Wed, 22 Jul 2020, "55", "MCALLA"],
 [Thu, 23 Jul 2020, "55", "PLUMEM"],
 [Wed, 29 Jul 2020, "55", "JENKIM12"],
 [Tue, 04 Aug 2020, "81", "LBARNARD"],
 [Wed, 26 Aug 2020, "LBARNARD", "LBARNARD"],
 [Mon, 31 Aug 2020, "JMOATS", nil]]

dc=DistributedCase.find_by(case_id: "4030236")
=> nil
dc=DistributedCase.find_by(case_id: "4030236-attempt1")
=> #<DistributedCase:0x000000000d682e70
 id: 167459,
 distribution_id: 8320,
 case_id: "4030236-attempt1",
 docket: "legacy",
 priority: true,
 genpop: false,
 genpop_query: "not_genpop",
 docket_index: nil,
 ready_at: Tue, 04 Aug 2020 00:00:00 UTC +00:00,
 task_id: nil,
 created_at: Wed, 26 Aug 2020 11:39:03 UTC +00:00,
 updated_at: Mon, 31 Aug 2020 20:53:16 UTC +00:00>
  • Case was distributed Wed (Aug 26). 2020-08-26T11:39:14.548192-04:00 was judge's last distribution
  • Then judge reassigned on Mon (Aug 31).

Why is case listed in Metabase?

  • Redshift update started 8/31/2020, 11:00:35 PM GMT-0400 and succcessfully finished. Latest last_judge_distrib date is 2020-08-31T21:58:46.005909-04:00
  • Case should not appear in Metabase since it was distributed on Wed
  • Running CaseDocket.distribute_priority_appeals does not list case, so the Metabase query probably needs updating.

    • checked SQL query and updated the query to account for Virtual Hearings

  • Checked AWS DMS and noticed failure in DMS task relating to VACOLS. Asked Rajinder

VACOLS DB replication was fixed. Metabase query results look much better!

case_ids=%w[ 4005121 3832879 3996145 ]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc.update!(case_id: "#{dc.case_id}-attempt1")
}

# Ready cases through July 
copied_from_table=%w[
BVADHACHEY 4022507
BVAHROBERT 4056560
BVAGWASIK 4033403
BVADHACHEY 4058271
BVAMJSKALT 4041571
BVAPMLYNCH 3573048
VACOWHITEY 4047231
BVAASPECTOR 4045869
BVAAMAINELLI 3478000
BVAJMONROE 4061638
VACOWHITEY 4048925
];

judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> []

# Cases ready on Aug 3rd and Aug 10th
copied_from_table=%w[
BVADAMES 3444979
VACOWHITEY 4044424
VACOWHITEY 4062276
BVAEDEICHERT 3734186
VACOWHITEY 4063033
BVATCATINO 3877493
VACOWHITEY 4060676
BVAMJSKALT 4061935
BVAMJSKALT 4028843
BVADBROWN 4019554
BVADBROWN 4051356
BVAMLANE 3589650
BVAAMACKEN 3549824
BVAMJSKALT 4052520
BVAMJSKALT 4064914
BVAPSORISIO 3403843
BVAJHAGER 4063818
BVADHACHEY 4063489
VACOWHITEY 4064621
BVAVCHIAPP 3483021
BVAJMONROE 4063502
BVADBROWN 4063340
BVAAMACKEN 3640712
BVADHACHEY 4063570
BVAJMONROE 4033668
BVAMJSKALT 4035890
BVAHROBERT 4064947
BVADHACHEY 4063623
BVARKESSEL 4062476
];

judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> []

# Cases ready on Aug 17th
... (75 cases)
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> []

If queries do not return results, the replication process may still be in progress -- check DMS.
An insufficient privileges issue is preventing replication.

Let's start using dc.update(case_id: "#{appeal.uuid}-attempt-#{Time.zone.now}") re #15163

Metabase query results seem to be working.

case_ids=%w[ 
4056560
4064947
4065172
4066521
4042885
4066129
4065509
4066294
4068509
4067767
3991548
4070000
4057769
4072710
3546346
3220702
 ]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc&.update!(case_id: "#{dc.case_id}-attempt-#{Time.zone.now}")
}

# Ready cases through July 
copied_from_table=%w[
BVAKBANFIELD 2787836
BVADHACHEY 4022507
BVAMCGRAHAM 3386121
BVADWHITEHD 4059339
BVADHACHEY 4058271
BVAGWASIK 4033403
BVAASPECTOR 4045869
VACOWHITEY 4047231
BVAJMONROE 4061638
VACOWHITEY 4048925
];

judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVAKBANFIELD", "2787836", nil]]

jcss_id="BVAKBANFIELD"
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> []
# "BVAKBANFIELD" is not distributed anything?

# Case was distributed today:
DistributedCase.find_by(case_id: "2787836")
=> #<DistributedCase:0x000000000b326d00
 id: 170594,
 distribution_id: 8473,
 case_id: "2787836",
 docket: "legacy",
 priority: true,
 genpop: false,
 genpop_query: "not_genpop",
 docket_index: nil,
 ready_at: Thu, 14 May 2020 00:00:00 UTC +00:00,
 task_id: nil,
 created_at: Thu, 10 Sep 2020 13:02:58 UTC +00:00,
 updated_at: Thu, 10 Sep 2020 13:02:58 UTC +00:00>

Checked ready-cases through Aug 17:

...
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVAKBANFIELD", "3978182", nil]]

# Case was distributed today:
DistributedCase.find_by(case_id: "3978182")
=> #<DistributedCase:0x000000000c9b2358
 id: 170595,
 distribution_id: 8473,
 case_id: "3978182",
 docket: "legacy",
 priority: true,
 genpop: false,
 genpop_query: "not_genpop",
 docket_index: nil,
 ready_at: Thu, 20 Aug 2020 00:00:00 UTC +00:00,
 task_id: nil,
 created_at: Thu, 10 Sep 2020 13:02:58 UTC +00:00,
 updated_at: Thu, 10 Sep 2020 13:02:58 UTC +00:00>

Checked ready-cases through Aug 24:

...
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVAKBANFIELD", "4066019", nil], ["BVAKBANFIELD", "4053558", nil], ["BVAKBANFIELD", "4032688", nil]]
# Cases were distributed today:
not_dist.map{|css_id, vid, aid| DistributedCase.find_by(case_id: vid)}

Checked ready-cases through Aug 31:

...
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVASKENNEDY", "4072904", nil]]
# Cases were distributed today:
not_dist.map{|css_id, vid, aid| DistributedCase.find_by(case_id: vid)}

Fixed cases that would block redistribution:

case_ids=%w[ 4061638 4012728 3251007 4013715 4017208 ]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc&.update!(case_id: "#{dc.case_id}-attempt-#{Time.zone.now}")
}

Checked 51 ready-cases through Aug 24:

...
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVADWHITEHD", "3566006", nil], ["BVAHSCHARTZ", "4070848", nil]]
# Cases were distributed today?
not_dist.map{|css_id, vid, aid| DistributedCase.find_by(case_id: vid)}
=> [nil,
 #<DistributedCase:0x000000000c9747b0
  id: 171716,
  ...
]

# Case 3566006 was not distributed! Why?
# Check what would be distributed to judge:
jcss_id="BVADWHITEHD"
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4059339", "bfdloout"=>2020-07-25 00:00:00 UTC, "vlj"=>"1092"},
 {"bfkey"=>"4067271", "bfdloout"=>2020-08-31 00:00:00 UTC, "vlj"=>"1092"},
 {"bfkey"=>"4071524", "bfdloout"=>2020-09-08 00:00:00 UTC, "vlj"=>"1092"},
 {"bfkey"=>"4073556", "bfdloout"=>2020-09-11 00:00:00 UTC, "vlj"=>"1092"}]
# I expected 3566006 to be second in the list since it's `case_ready_date` is 2020-08-17

# Where is the case now?
LegacyAppeal.find_by(vacols_id: 3566006).location_code
=> "DWHITEHD"
a.location_history.map(&:summary)
=> ...
 {:assigned_by=>"BOOKEK", :assigned_at=>Tue, 15 Sep 2020, :location=>"DWHITEHD", :date_in=>nil, :date_out=>Tue, 15 Sep 2020}]
# Ok, it was manually assigned to judge today

Checked 95 ready-cases through Aug 31:

...
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
=> [["BVAURPOWELL", "4071476", nil],
 ["BVAMMARTIN", "4067065", nil],
 ["BVAMMARTIN", "4072355", nil],
 ["BVAURPOWELL", "4072468", nil],
 ["BVAMMARTIN", "4020294", nil],
 ["BVABWILSON", "4066999", nil],
 ["BVAMMARTIN", "4072885", nil],
 ["BVAMMARTIN", "4039078", nil],
 ["BVABWILSON", "4057389", nil],
 ["BVAHSCHARTZ", "4071418", nil],
 ["BVAASCIRE", "4052768", nil],
 ["BVAMMARTIN", "4072300", nil],
 ["BVAURPOWELL", "4072232", nil],
 ["BVABWILSON", "4072418", nil],
 ["BVAMMARTIN", "4072592", nil]]

# Cases were distributed today?
not_dist.map{|css_id, vid, aid| DistributedCase.find_by(case_id: vid)}
=> ... # a few were not distributed today
not_dist2 = not_dist.select{|css_id, vid, aid| DistributedCase.find_by(case_id: vid).nil?}
=> [["BVAURPOWELL", "4071476", nil], ["BVAURPOWELL", "4072468", nil], ["BVAURPOWELL", "4072232", nil]]

not_dist2.map{|css_id, vid, aid| LegacyAppeal.find_by(vacols_id: vid).location_code }
=> ["URPOWELL", "URPOWELL", "URPOWELL"]
# cases are currently assigned to the judge. Good.

Checked first 100 ready-cases through Sep 7:

copied_from_table=%w[ ... ];
judge_appeals=copied_from_table.in_groups_of(2).map{ |pair| [pair.first, pair.second]};
appeal_indices=judge_appeals.map{ |jcss_id, vacols_id| 
  bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
  [jcss_id, vacols_id, bfs.pluck("bfkey").find_index(vacols_id)]
};
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?};
not_dist.count
=> 50
not_dist2 = not_dist.select{|css_id, vid, aid| DistributedCase.find_by(case_id: vid).nil?};
not_dist2.count
=> 45

not_dist3 = not_dist2.map{|css_id, vid, aid| 
  loc=LegacyAppeal.find_by(vacols_id: vid)&.location_code 
  judge_logid=VACOLS::Staff.find_by(sdomainid: css_id).slogid
  [ loc, css_id, vid ] if loc != judge_logid
}.compact
=> [[nil, "BVADBRENN", "4073273"],
 ["VACOALLENA4", "VACOMARCUS", "3195331"],
 ["VACOMONTAA", "BVAMJSKALT", "4065902"],
 ["TDOUGLAS", "BVAURPOWELL", "3600126"],
 ["VACOBOIVID", "VACOMARCUS", "3911105"],
 [nil, "BVALBARNARD", "4073597"],
 [nil, "BVAESLEBOFF", "4072788"],
 [nil, "BVAPSORISIO", "4073221"]]
# 4 cases do not have a LegacyAppeal record (yet)
# The remaining cases are currently located at (assigned to) a staff person
case_ids=%w[ 3991317 3598807 ];
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  dc&.update!(case_id: "#{dc.case_id}-attempt-#{Time.zone.now}")
}

Should no longer need to do this after today due to #15248.
Checked 383 ready-cases through Sep 14. All good!

Only 205 rows in https://query.prod.appeals.va.gov/question/60 results.

3 cases already have a DistributedCase. They were all distributed today. Yay!

case_ids=%w[ 4037764 4033752 4020232 ];
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  last_judge_distrib = Distribution.where(judge: dc.distribution.judge).order(:id).last.started_at if dc
  [dc&.id, dc&.created_at, dc&.ready_at, dc&.distribution.judge.css_id, last_judge_distrib]
}
=> [[174669,
  Mon, 28 Sep 2020 16:34:13 UTC +00:00,
  Fri, 25 Sep 2020 00:00:00 UTC +00:00,
  "BVAKKENNERLY",
  Mon, 28 Sep 2020 16:33:47 UTC +00:00],
 [174593,
  Mon, 28 Sep 2020 12:26:00 UTC +00:00,
  Fri, 25 Sep 2020 00:00:00 UTC +00:00,
  "BVADWHITEHD",
  Mon, 28 Sep 2020 12:47:17 UTC +00:00],
 [174589,
  Mon, 28 Sep 2020 12:25:22 UTC +00:00,
  Thu, 24 Sep 2020 00:00:00 UTC +00:00,
  "BVAKZADORA",
  Mon, 28 Sep 2020 12:44:44 UTC +00:00]]

Let's check the other 202 cases:

# Checking first batch of 101 cases
...
not_dist3
=> [["81", "BVAURPOWELL", "4067955"], [nil, "BVAURPOWELL", "4048521"]]
not_dist3.map{ |loc,judge,vid| LegacyAppeal.find_by(vacols_id: vid).nil? }
=> [false, true]

jcss_id="BVAURPOWELL"
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
<d_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> []
# Huh? No cases would be distributed to BVAURPOWELL
JudgeTeam.for_judge(User.find_by(css_id: jcss_id))
=> nil # Judge has no JudgeTeam. This is a known problem that Hunter will be addressing

# Checking remaining 100+ cases
...
not_dist3
=> [[nil, "BVAURPOWELL", "4048659"],
 [nil, "BVAURPOWELL", "4074578"],
 [nil, "BVAURPOWELL", "4077101"]]
# same judge (who has no JudgeTeam)

Looks good except for judge BVAURPOWELL (who has no JudgeTeam).
4 of the 5 cases do not have a LegacyAppeal record.

Only 425 rows in https://query.prod.appeals.va.gov/question/60 results.

6 cases already have a DistributedCase.

case_ids=%w[ 3237727 2736983 2133510L 2443466 3486627 4068028]
case_ids.map{|cid|
  dc=DistributedCase.find_by(case_id: cid)
  last_judge_distrib = Distribution.where(judge: dc.distribution.judge).order(:id).last.started_at if dc
  [dc&.id, dc&.created_at, dc&.ready_at, dc&.distribution.judge.css_id, last_judge_distrib]
}
# They were all distributed today. Yay!

Will check the other cases tomorrow after the Redshift DB is updated to reflect effects of the priority-push job.
Update: Down to only 66 rows! Looks good:

not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
not_dist.count
=> 0

I notice 2 priority legacy cases tied to BVAURPOWELL, who is inactive as of (Sept 28?). The 2 cases would be attempt to distributed to them:

jcss_id="BVAURPOWELL"
bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> [
{"bfkey"=>"4073158", "bfdloout"=>2020-10-01 00:00:00 UTC, "vlj"=>"153"}, 
{"bfkey"=>"4072525", "bfdloout"=>2020-10-02 00:00:00 UTC, "vlj"=>"153"}]

From Ann-Marie:

Cases tied to AVLJs or deactivated VLJs will not be auto-distributed as there is a current manual process in place to have these distributed by members of the Board.

Down to 55 rows in https://query.prod.appeals.va.gov/question/60.

not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
not_dist.count
=> 0

235 row in https://query.prod.appeals.va.gov/question/60, most of which were distributed. The DMS job (that copies VACOLS DB to Redshift) is not working so the query results are using data from Oct 15.

For the remaining 46 rows:

not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?}
not_dist.count
=> 3

not_dist2 = not_dist.select{|css_id, vid, aid| DistributedCase.find_by(case_id: vid).nil?};
=> [["BVASDREISS", "3856200", nil], ["BVAJMONROE", "4062179", nil], ["BVAJREINHART", "4077852", nil]]
not_dist2.count
=> 3
# These do not have associated DistributedCase records:
not_dist.map{|css_id, vid, aid| DistributedCase.where('case_id like ?', "%#{vid}%")}
=> [[], [], []]

not_dist3 = not_dist2.map{|css_id, vid, aid| 
  loc=LegacyAppeal.find_by(vacols_id: vid)&.location_code 
  judge_logid=VACOLS::Staff.find_by(sdomainid: css_id).slogid
  [ loc, css_id, vid ] if loc != judge_logid
}.compact
=> [["81", "BVASDREISS", "3856200"], ["99", "BVAJREINHART", "4077852"]]

# Case 4062179 is at the correct judge, but the other 2 are not
LegacyAppeal.find_by(vacols_id: 4062179)&.location_code
=> "JMONROE"
VACOLS::Staff.find_by(sdomainid: "BVAJMONROE").slogid
=> "JMONROE"

not_dist3.map{|loc, css_id, vid| LegacyAppeal.find_by(vacols_id: vid).location_history.pluck(:locdout, :locstto, :locstrcv)}
=> [[[Mon, 19 Nov 2018, "77", "IMBUTLER"],
  [Wed, 02 Oct 2019, "78", "JOFFER"],
  [Tue, 08 Oct 2019, "01", "JOFFER"],
  [Tue, 08 Oct 2019, "57", "DSUSER"],
  [Tue, 08 Oct 2019, "CASEFLOW", "VACOJOHNST9"],
  [Tue, 30 Jun 2020, "CASEFLOW", "DSUSER"],
  [Thu, 06 Aug 2020, "33", "VACOPYOSK"], # 33=transcription
  [Thu, 10 Sep 2020, "81", nil]], # 81=case_storage

 [[Tue, 29 Sep 2020, "01", "MCARTER"], 
  [Tue, 29 Sep 2020, "81", "DSUSER"], 
  [Thu, 15 Oct 2020, "99", nil]]]  # 99=closed
# Case 4077852 was closed and never went to BVAJREINHART

jcss_id="BVASDREISS"
bfs=VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4064755", "bfdloout"=>2020-10-20 00:00:00 UTC, "vlj"=>"467"}, 
    {"bfkey"=>"4076484", "bfdloout"=>2020-10-20 00:00:00 UTC, "vlj"=>"467"}]
# Why won't case 3856200 be distributed to BVASDREISS?
la=LegacyAppeal.find_by(vacols_id: 3856200)
la.treee
                                                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
LegacyAppeal 428179 (legacy) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ ID     โ”‚ STATUS      โ”‚ ASGN_BY โ”‚ ASGN_TO            โ”‚ UPDATED_AT              โ”‚
โ””โ”€โ”€ RootTask                                        โ”‚ 457956 โ”‚ on_hold     โ”‚         โ”‚ Bva                โ”‚ 2019-10-08 17:00:28 UTC โ”‚
    โ”œโ”€โ”€ HearingTask                                 โ”‚ 457957 โ”‚ completed   โ”‚         โ”‚ Bva                โ”‚ 2020-08-06 05:05:40 UTC โ”‚
    โ”‚   โ”œโ”€โ”€ ScheduleHearingTask                     โ”‚ 457958 โ”‚ completed   โ”‚         โ”‚ Bva                โ”‚ 2020-06-30 20:27:22 UTC โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ HearingAdminActionVerifyAddressTask โ”‚ 466813 โ”‚ cancelled   โ”‚         โ”‚ HearingsManagement โ”‚ 2019-10-17 16:03:15 UTC โ”‚
    โ”‚   โ””โ”€โ”€ AssignHearingDispositionTask            โ”‚ 989945 โ”‚ completed   โ”‚         โ”‚ Bva                โ”‚ 2020-08-06 05:05:40 UTC โ”‚
    โ””โ”€โ”€ TrackVeteranTask                            โ”‚ 990018 โ”‚ in_progress โ”‚         โ”‚ PrivateBar         โ”‚ 2020-06-30 21:00:15 UTC โ”‚
                                                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Hunter's response:

appeal = LegacyAppeal.find_by(vacols_id: 3856200)
VACOLS::CaseDocket.priority_ready_appeal_vacols_ids.include? appeal.vacols_id
=> false
# Appeal is considered either not ready or not priority
appeal.aod?
=> true
# Is priority
appeal.location_code
=> "81"
# Appeal is in case storage, one of the conditions for "ready to distribute"
VACOLS::Case.find_by(bfkey: appeal.vacols_id).bfmpro
=> "ACT"
# Appeal is active, one of the conditions for "ready to distribute"
VACOLS::Case.find_by(bfkey: appeal.vacols_id).bfbox
=> nil
# Case does not belong to a special team, one of the conditions for "ready to distribute"
VACOLS::Note.where(tsktknm: appeal.vacols_id, tskdcls: nil, tskactcd: ['EXT', 'HCL', 'POA']).count
=> 0
# No blocking diary items in vacols, one of the conditions for "ready to distribute"
VACOLS::Mail.where(mlfolder: appeal.vacols_id, mlcompdate: nil).pluck(:mltype)
=> ["07"]
# There is an open blocking mail item in vacols, meaning this case is not ready to distribute

Refs:

235 row in https://query.prod.appeals.va.gov/question/60.

Why isn't case 4021717 being distributed?

cid=4021717
dc=DistributedCase.find_by(case_id: cid)
last_judge_distrib = Distribution.where(judge: dc.distribution.judge).order(:id).last.started_at if dc
pp [dc&.id, dc&.created_at, dc&.ready_at, dc&.distribution.judge.css_id, last_judge_distrib]
[155268,
 Tue, 30 Jun 2020 16:50:39 UTC +00:00,
 Thu, 25 Jun 2020 00:00:00 UTC +00:00,
 "BVAAJAEGER",
 Mon, 09 Nov 2020 12:09:52 UTC +00:00]

jcss_id="BVAAJAEGER"
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"4073283", "bfdloout"=>2020-09-10 00:00:00 UTC, "vlj"=>"784"}]

appeal.location_history.map(&:summary)
=> [{:assigned_by=>"SCOLLINS", :assigned_at=>Tue, 18 Feb 2020, :location=>"77", :date_in=>Mon, 09 Mar 2020, 
...
 {:assigned_by=>"VACOSAYLOM", :assigned_at=>Mon, 28 Sep 2020, :location=>"CASEFLOW", :date_in=>Fri, 16 Oct 2020, :date_out=>Mon, 28 Sep 2020},
 {:assigned_by=>"DSUSER", :assigned_at=>Fri, 16 Oct 2020, :location=>"33", :date_in=>Mon, 09 Nov 2020, :date_out=>Fri, 16 Oct 2020},
 {:assigned_by=>"BVABINNSS", :assigned_at=>Mon, 09 Nov 2020, :location=>"81", :date_in=>nil, :date_out=>Mon, 09 Nov 2020}]


appeal = LegacyAppeal.find_by(vacols_id: 4021717)
VACOLS::CaseDocket.priority_ready_appeal_vacols_ids.include? appeal.vacols_id
=> true
appeal.aod?
=> false
appeal.cavc?
=> true
appeal.location_code
=> "81"
VACOLS::Case.find_by(bfkey: appeal.vacols_id).bfmpro
=> "ACT"
VACOLS::Case.find_by(bfkey: appeal.vacols_id).bfbox
=> nil
VACOLS::Note.where(tsktknm: appeal.vacols_id, tskdcls: nil, tskactcd: ['EXT', 'HCL', 'POA']).count
=> 0
VACOLS::Mail.where(mlfolder: appeal.vacols_id, mlcompdate: nil).pluck(:mltype)
=> []

# extracting from `VACOLS::CaseDocket.priority_ready_appeal_vacols_ids`
h=VACOLS::CaseDocket.connection.exec_query(VACOLS::CaseDocket::SELECT_PRIORITY_APPEALS).to_hash
h.select{|o| o["bfkey"]=="4021717"}
=> [{"bfkey"=>"4021717", "bfdloout"=>2020-11-09 00:00:00 UTC, "vlj"=>"871"}]

jcss_id=VACOLS::Staff.find_by(sattyid: "871").sdomainid
=> "BVADAMES"
VACOLS::CaseDocket.distribute_priority_appeals(User.find_by(css_id: jcss_id), "not_genpop", 1000, dry_run: true)
=> [{"bfkey"=>"3065396", "bfdloout"=>2020-09-10 00:00:00 UTC, "vlj"=>"871"},
 {"bfkey"=>"4089707", "bfdloout"=>2020-11-09 00:00:00 UTC, "vlj"=>"871"},
 {"bfkey"=>"4021717", "bfdloout"=>2020-11-09 00:00:00 UTC, "vlj"=>"871"},
# Cool, it will be distributed to BVADAMES

# Check that last distribution to BVADAMES
Distribution.where(judge_id: 827).order(:id).last
=> #<Distribution:0x000000000d6220e8
 ...
 completed_at: Mon, 09 Nov 2020 15:20:03 UTC +00:00,
 created_at: Mon, 09 Nov 2020 15:19:25 UTC +00:00,
 updated_at: Mon, 09 Nov 2020 15:20:05 UTC +00:00,
 started_at: Mon, 09 Nov 2020 15:19:26 UTC +00:00,
 errored_at: nil,
 priority_push: false>

Checking the other 234 cases (in batches of 100 or less):

# 2nd batch potentially found some:
not_dist=appeal_indices.select{|jcss_id, vacols_id, app_id| app_id.nil?};
not_dist.count
=> 4
not_dist
=> [["BVASBELCHER", "4083277", nil], ["BVADWSINGLE", "4089619", nil], ["BVASBELCHER", "4089667", nil], ["BVAMMARTIN", "4089676", nil]]
not_dist2 = not_dist.select{|css_id, vid, aid| DistributedCase.find_by(case_id: vid).nil?}
=> [["BVADWSINGLE", "4089619", nil]]
not_dist3 = not_dist2.map{|css_id, vid, aid|
  loc=LegacyAppeal.find_by(vacols_id: vid)&.location_code
  judge_logid=VACOLS::Staff.find_by(sdomainid: css_id).slogid
  [ loc, css_id, vid ] if loc != judge_logid
}.compact
=> []
# Good. Moving on to final batch...
not_dist.count
=> 0
# Good.

459 rows in https://query.prod.appeals.va.gov/question/60. All look good!
Will stop doing regular checks since no problems have occurred in months.

Only 1 case with a blocking mail task:

appeal.vacols_id
=> "4052851"
VACOLS::Mail.where(mlfolder: appeal.vacols_id, mlcompdate: nil).pluck(:mltype)
=> ["27"] # mail task blocks distribution

@yoomlam I found 4 appeals in this reporting that may be "stuck". Can we look into these? Below is what I have found so far:

4093061 - ready date 11/16/2020 (this one does appear to be "stuck")

  • location 81
  • no active tasks
  • no prior hearings

4091725 - ready date 3/15/2021

  • location 81
  • no active tasks
  • original appeal had hearing held (noticed the judge name is not displayed on the Case Details page)

4113569 - ready date 3/15/2021

  • location 81
  • no active tasks
  • original appeal had hearing held (noticed the judge name is not displayed on the Case Details page)

4113942 - ready date 3/15/2021

  • location 81
  • no active tasks
  • original appeal had hearing held (noticed the judge name is not displayed on the Case Details page)

The first was assigned today; the remaining are in case_storage (81) and are tied to judges (with VACOLS ids: JMCDNALD, RWSCHOLZ, MSABLSKY) who do not have User records in Caseflow.

LegacyAppeal.find_by(vacols_id: 4093061).location_history.map(&:summary)
=> [{:assigned_by=>"HDAYS", :assigned_at=>Thu, 19 Nov 2020, :location=>"01", :date_in=>Thu, 19 Nov 2020, :date_out=>Thu, 19 Nov 2020},
 {:assigned_by=>"HDAYS", :assigned_at=>Thu, 19 Nov 2020, :location=>"81", :date_in=>Tue, 23 Mar 2021, :date_out=>Thu, 19 Nov 2020},
 {:assigned_by=>"ASPECTOR", :assigned_at=>Tue, 23 Mar 2021, :location=>"ASPECTOR", :date_in=>nil, :date_out=>Tue, 23 Mar 2021}]
# Assigned today

LegacyAppeal.find_by(vacols_id: 4091725).location_history.map(&:summary)
=> [{:assigned_by=>"VACODAVISD11", :assigned_at=>Tue, 17 Nov 2020, :location=>"77", :date_in=>Tue, 17 Nov 2020, :date_out=>Tue, 17 Nov 2020},
 {:assigned_by=>"VACODAVISD11", :assigned_at=>Tue, 17 Nov 2020, :location=>"60", :date_in=>Mon, 08 Mar 2021, :date_out=>Tue, 17 Nov 2020},
 {:assigned_by=>"SCOLLINS", :assigned_at=>Mon, 08 Mar 2021, :location=>"55", :date_in=>Tue, 16 Mar 2021, :date_out=>Mon, 08 Mar 2021},
 {:assigned_by=>"VACOSAUNDM", :assigned_at=>Tue, 16 Mar 2021, :location=>"55", :date_in=>Tue, 16 Mar 2021, :date_out=>Tue, 16 Mar 2021},
 {:assigned_by=>"VACOSAUNDM", :assigned_at=>Tue, 16 Mar 2021, :location=>"55", :date_in=>Wed, 17 Mar 2021, :date_out=>Tue, 16 Mar 2021},
 {:assigned_by=>"VACOGRIGOA", :assigned_at=>Wed, 17 Mar 2021, :location=>"81", :date_in=>nil, :date_out=>Wed, 17 Mar 2021}]
appeal=LegacyAppeal.find_by(vacols_id: 4091725)
appeal.hearings
=> []
# Following procedure in previous comment:
VACOLS::Case.find_by(bfkey: appeal.vacols_id).bfbox
VACOLS::Note.where(tsktknm: appeal.vacols_id, tskdcls: nil, tskactcd: ['EXT', 'HCL', 'POA']).count
VACOLS::Mail.where(mlfolder: appeal.vacols_id, mlcompdate: nil).pluck(:mltype)
h=VACOLS::CaseDocket.connection.exec_query(VACOLS::CaseDocket::SELECT_PRIORITY_APPEALS).to_hash
ah=h.select{|o| o["bfkey"]==appeal.vacols_id}
=> [{"bfkey"=>"4091725", "bfdloout"=>2021-03-17 00:00:00 UTC, "vlj"=>"340"}]
VACOLS::Staff.find_by(sattyid: ah.first["vlj"]).stafkey
=> "JMCDNALD"
jcss_id=VACOLS::Staff.find_by(sattyid: ah.first["vlj"]).sdomainid
=> nil
# The judge is not in Caseflow

LegacyAppeal.find_by(vacols_id: 4113569).location_history.map(&:summary)
=> [{:assigned_by=>"HDAYS", :assigned_at=>Thu, 18 Mar 2021, :location=>"01", :date_in=>Thu, 18 Mar 2021, :date_out=>Thu, 18 Mar 2021},
 {:assigned_by=>"HDAYS", :assigned_at=>Thu, 18 Mar 2021, :location=>"81", :date_in=>nil, :date_out=>Thu, 18 Mar 2021}]
appeal=LegacyAppeal.find_by(vacols_id: 4113569);
ah=h.select{|o| o["bfkey"]==appeal.vacols_id}
=> [{"bfkey"=>"4113569", "bfdloout"=>2021-03-18 00:00:00 UTC, "vlj"=>"742"}]
VACOLS::Staff.find_by(sattyid: ah.first["vlj"]).stafkey
=> "RWSCHOLZ"
jcss_id=VACOLS::Staff.find_by(sattyid: ah.first["vlj"]).sdomainid
=> nil
# The judge is not in Caseflow

LegacyAppeal.find_by(vacols_id: 4113942).location_history.map(&:summary)
=> [{:assigned_by=>"HDAYS", :assigned_at=>Fri, 19 Mar 2021, :location=>"01", :date_in=>Fri, 19 Mar 2021, :date_out=>Fri, 19 Mar 2021},
 {:assigned_by=>"HDAYS", :assigned_at=>Fri, 19 Mar 2021, :location=>"81", :date_in=>nil, :date_out=>Fri, 19 Mar 2021}]
appeal=LegacyAppeal.find_by(vacols_id: 4113942);
ah=h.select{|o| o["bfkey"]==appeal.vacols_id}
=> [{"bfkey"=>"4113942", "bfdloout"=>2021-03-19 00:00:00 UTC, "vlj"=>"242"}]
VACOLS::Staff.find_by(sattyid: ah.first["vlj"]).stafkey
=> "MSABLSKY"
jcss_id=VACOLS::Staff.find_by(sattyid: ah.first["vlj"]).sdomainid
=> nil
# The judge is not in Caseflow

Summary of above investigation and follow-up investigation:
All cases listed in Metabase charts involving Priority Legacy cases have been distributed except for:

  • cases tied to 5 VLJs who don't have a Caseflow user account
  • cases that were recently added to case storage (they'll get distributed next Monday morning at the latest)

Details in HackMD

Was this page helpful?
0 / 5 - 0 ratings