github-actions[bot] commited on
Commit
1c10ad8
·
1 Parent(s): 9ec8d34

Automated Deploy: ed201601253c7a9f986bf283978f698c345ad45d

Browse files
baseball_batting/job_terminal.py CHANGED
@@ -2,6 +2,8 @@
2
  import math
3
  import re
4
  import time
 
 
5
  from .storage import read_json
6
 
7
 
@@ -17,6 +19,61 @@ def _read(path):
17
  return {}
18
 
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  class JobTerminal:
21
  def __init__(self, identifier, directory, clock=time.monotonic):
22
  self.identifier = _token(identifier)
@@ -81,6 +138,9 @@ class JobTerminal:
81
  if reference.get('reason_code'):
82
  text += ' reason='+_token(reference['reason_code'])
83
  self.emit(text)
 
 
 
84
  elif status == 'failed':
85
  reason = _read(self.directory/'error.json').get('reason_code')
86
  if reason:
 
2
  import math
3
  import re
4
  import time
5
+ from collections import Counter
6
+
7
  from .storage import read_json
8
 
9
 
 
19
  return {}
20
 
21
 
22
+ def _pitcher_checks(reference):
23
+ """Bounded diagnostics from the saved result, including existing v1 jobs."""
24
+ if reference.get('status') != 'unknown':
25
+ return []
26
+ candidates = reference.get('candidates')
27
+ if not isinstance(candidates, list) or not candidates:
28
+ return []
29
+ # Only server-defined rejection codes and numeric evidence reach stdout.
30
+ checks = {
31
+ 'no_stable_loaded_setup': [],
32
+ 'setup_axis_unstable': [('setup_spread_deg', 'maximum_setup_spread_deg')],
33
+ 'loaded_hand_side_ambiguous': [],
34
+ 'loaded_hand_side_inconsistent': [],
35
+ 'hand_motion_opposes_loaded_side': [('forward_velocity_fraction', 'minimum_forward_velocity_fraction')],
36
+ 'forward_hand_extension_unavailable': [],
37
+ 'body_track_discontinuous': [('maximum_axis_step_deg', 'maximum_axis_step_deg'),
38
+ ('maximum_hand_step_shoulder_widths', 'maximum_hand_step_shoulder_widths')],
39
+ 'insufficient_forward_hand_progress': [],
40
+ 'shoulder_turn_does_not_support_swing': [('shoulder_forward_turn_deg', 'minimum_shoulder_rotation_deg')],
41
+ 'hip_turn_does_not_support_swing': [('hip_forward_turn_deg', 'minimum_hip_rotation_deg')],
42
+ }
43
+ rows = [row for row in candidates[:40] if isinstance(row, dict)]
44
+ rejected = [row for row in rows if row.get('accepted') is False
45
+ and isinstance(row.get('reason_code'), str) and row['reason_code'] in checks]
46
+ counts = Counter(row['reason_code'] for row in rejected)
47
+ ordered = sorted(counts, key=lambda key: (-counts[key], key))
48
+ count = reference.get('accepted_candidate_count')
49
+ accepted = count if type(count) is int and count >= 0 else sum(row.get('accepted') is True for row in rows)
50
+ summary = f'pitcher_checks candidates={len(candidates)} accepted={accepted}'
51
+ if ordered:
52
+ summary += ' rejected='+','.join(f'{key}:{counts[key]}' for key in ordered[:3])
53
+ if len(ordered) > 3:
54
+ summary += ',other:'+str(sum(counts[key] for key in ordered[3:]))
55
+ lines = [summary]
56
+ limits = reference.get('limits')
57
+ limits = limits if isinstance(limits, dict) else {}
58
+ for reason in ordered:
59
+ row = next(item for item in rejected if item['reason_code'] == reason)
60
+ frame = row.get('peak_frame')
61
+ if type(frame) is not int or frame < 0:
62
+ continue
63
+ values = []
64
+ for key, limit_key in checks[reason]:
65
+ value, limit = row.get(key), limits.get(limit_key)
66
+ if type(value) in (int, float) and math.isfinite(value):
67
+ values.append(f'{key}={value:.3f}')
68
+ if type(limit) in (int, float) and math.isfinite(limit):
69
+ values.append(f'{limit_key}={limit:.3f}' if limit_key != key else f'limit={limit:.3f}')
70
+ if values:
71
+ lines.append(f'pitcher_check frame={frame} reason={reason} '+' '.join(values))
72
+ if len(lines) >= 3:
73
+ break
74
+ return lines
75
+
76
+
77
  class JobTerminal:
78
  def __init__(self, identifier, directory, clock=time.monotonic):
79
  self.identifier = _token(identifier)
 
138
  if reference.get('reason_code'):
139
  text += ' reason='+_token(reference['reason_code'])
140
  self.emit(text)
141
+ if name == 'pitcher':
142
+ for line in _pitcher_checks(reference):
143
+ self.emit(line)
144
  elif status == 'failed':
145
  reason = _read(self.directory/'error.json').get('reason_code')
146
  if reason:
docs/GPU_API_DEPLOYMENT.md CHANGED
@@ -86,6 +86,12 @@ Analysis jobs print concise progress to the server terminal (Docker/container
86
  stdout): job ID, stage changes, progress counts when available, a heartbeat every
87
  15 seconds during long steps, and final status with elapsed time. Motion jobs
88
  also summarize the up and pitcher directions, or the reason they are unknown.
 
 
 
 
 
 
89
  Full model output stays in each job's `worker.log`; payloads and uploads are not
90
  dumped to the terminal. Use `docker compose logs -f api` to follow live progress.
91
 
 
86
  stdout): job ID, stage changes, progress counts when available, a heartbeat every
87
  15 seconds during long steps, and final status with elapsed time. Motion jobs
88
  also summarize the up and pitcher directions, or the reason they are unknown.
89
+ For rejected body-direction estimates, `pitcher_checks` lists candidate counts
90
+ and the three most common failed checks. Up to two `pitcher_check` lines show
91
+ source frame numbers and numeric evidence when available. The generic
92
+ `no_clear_setup_and_swing` means different candidates failed different checks;
93
+ the detailed rows are already saved in `coordinates.pitcher_estimation.candidates`
94
+ in the motion result JSON, including results created before this logging change.
95
  Full model output stays in each job's `worker.log`; payloads and uploads are not
96
  dumped to the terminal. Use `docker compose logs -f api` to follow live progress.
97
 
tests/test_job_terminal.py CHANGED
@@ -1,7 +1,9 @@
1
  import sys
 
 
 
2
  from baseball_batting.job_terminal import JobTerminal
3
  from baseball_batting.storage import atomic_json
4
- from test_api import fake_service, settings
5
 
6
 
7
  def test_progress_is_visible_but_throttled_with_heartbeat(tmp_path, capsys):
@@ -38,6 +40,44 @@ def test_results_are_short_and_do_not_dump_payloads(tmp_path, capsys):
38
  assert len(out.splitlines()) == 3
39
 
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def test_missing_and_partial_files_do_not_break_logging(tmp_path, capsys):
42
  log = JobTerminal('id', tmp_path)
43
  log.progress(force=True)
 
1
  import sys
2
+
3
+ from test_api import fake_service, settings
4
+
5
  from baseball_batting.job_terminal import JobTerminal
6
  from baseball_batting.storage import atomic_json
 
7
 
8
 
9
  def test_progress_is_visible_but_throttled_with_heartbeat(tmp_path, capsys):
 
40
  assert len(out.splitlines()) == 3
41
 
42
 
43
+ def test_mixed_direction_rejections_show_causes_and_numeric_evidence(tmp_path, capsys):
44
+ atomic_json(tmp_path/'result.json', {'coordinates':{'pitcher_estimation':{
45
+ 'status':'unknown', 'method':'automatic_body_swing_direction_v1',
46
+ 'reason_code':'no_clear_setup_and_swing', 'accepted_candidate_count':0,
47
+ 'limits':{'maximum_setup_spread_deg':12}, 'private':'DO_NOT_LOG',
48
+ 'candidates':[
49
+ {'peak_frame':18, 'accepted':False, 'reason_code':'no_stable_loaded_setup'},
50
+ {'peak_frame':40, 'accepted':False, 'reason_code':'setup_axis_unstable', 'setup_spread_deg':18.75},
51
+ {'peak_frame':60, 'accepted':False, 'reason_code':'no_stable_loaded_setup'},
52
+ ]}}})
53
+ JobTerminal('id', tmp_path).finish('completed')
54
+ output = capsys.readouterr().out
55
+ assert 'reason=no_clear_setup_and_swing' in output
56
+ assert 'pitcher_checks candidates=3 accepted=0 rejected=no_stable_loaded_setup:2,setup_axis_unstable:1' in output
57
+ assert 'frame=40 reason=setup_axis_unstable setup_spread_deg=18.750 maximum_setup_spread_deg=12.000' in output
58
+ assert 'DO_NOT_LOG' not in output
59
+ assert len(output.splitlines()) == 4
60
+
61
+
62
+ def test_direction_diagnostics_are_bounded_and_ignore_raw_strings():
63
+ from baseball_batting.job_terminal import _pitcher_checks
64
+ reference = {'status':'unknown', 'limits':{'maximum_setup_spread_deg':'DO_NOT_LOG'},
65
+ 'candidates':[
66
+ {'accepted':False, 'reason_code':'setup_axis_unstable', 'setup_spread_deg':16, 'peak_frame':10},
67
+ {'accepted':False, 'reason_code':'hand_motion_opposes_loaded_side', 'forward_velocity_fraction':-.3, 'peak_frame':20},
68
+ {'accepted':False, 'reason_code':'hip_turn_does_not_support_swing', 'hip_forward_turn_deg':5, 'peak_frame':30},
69
+ {'accepted':False, 'reason_code':'shoulder_turn_does_not_support_swing', 'shoulder_forward_turn_deg':'DO_NOT_LOG', 'peak_frame':40},
70
+ {'accepted':False, 'reason_code':'DO_NOT_LOG', 'peak_frame':50},
71
+ {'accepted':False, 'reason_code':['DO_NOT_LOG']}, None,
72
+ ]*100}
73
+ lines = _pitcher_checks(reference)
74
+ assert len(lines) <= 3 and all(len(line) < 500 for line in lines)
75
+ assert 'DO_NOT_LOG' not in '\n'.join(lines)
76
+ assert 'other:' in lines[0]
77
+ assert _pitcher_checks({**reference, 'status':'estimated'}) == []
78
+ assert _pitcher_checks({'status':'unknown', 'candidates':None}) == []
79
+
80
+
81
  def test_missing_and_partial_files_do_not_break_logging(tmp_path, capsys):
82
  log = JobTerminal('id', tmp_path)
83
  log.progress(force=True)