m1m02530125 commited on
Commit
ac927ca
·
1 Parent(s): 659087a

曜日別タップサジェストを複数候補・頻出順に対応

Browse files

get_employee_dow_patterns が曜日ごとの最頻パターン1件のみを返していたが、
2回以上提出歴のある全パターンを頻度降順のリストで返すように変更し、
希望シフト入力画面のタップサイクルでも候補を全て頻出順に表示する。

Files changed (2) hide show
  1. db/repositories.py +5 -7
  2. templates/shifts/input.html +9 -10
db/repositories.py CHANGED
@@ -648,8 +648,8 @@ def get_employee_pattern_history(emp_id: int) -> list[tuple[str, int, Optional[s
648
  return [(r["pattern_id"], r["cnt"], r["cs"], r["ce"]) for r in rows]
649
 
650
 
651
- def get_employee_dow_patterns(emp_id: int) -> dict[int, str]:
652
- """従業員の曜日別最頻パターンを {python_weekday(0=月..6=日): pattern_id} で返す。
653
  2回以上出現したパターンのみ提案対象とする。"""
654
  conn = get_connection()
655
  rows = conn.execute(
@@ -677,11 +677,9 @@ def get_employee_dow_patterns(emp_id: int) -> dict[int, str]:
677
  dow_counts[py_dow][pid] = dow_counts[py_dow].get(pid, 0) + cnt
678
  result = {}
679
  for dow, patterns in dow_counts.items():
680
- if not patterns:
681
- continue
682
- best_pid = max(patterns, key=patterns.get)
683
- if patterns[best_pid] >= 2:
684
- result[dow] = best_pid
685
  return result
686
 
687
 
 
648
  return [(r["pattern_id"], r["cnt"], r["cs"], r["ce"]) for r in rows]
649
 
650
 
651
+ def get_employee_dow_patterns(emp_id: int) -> dict[int, list[str]]:
652
+ """従業員の曜日別の頻出パターンを {python_weekday(0=月..6=日): [pattern_id, ...]}(頻度降順)で返す。
653
  2回以上出現したパターンのみ提案対象とする。"""
654
  conn = get_connection()
655
  rows = conn.execute(
 
677
  dow_counts[py_dow][pid] = dow_counts[py_dow].get(pid, 0) + cnt
678
  result = {}
679
  for dow, patterns in dow_counts.items():
680
+ pids = [pid for pid, cnt in sorted(patterns.items(), key=lambda x: -x[1]) if cnt >= 2]
681
+ if pids:
682
+ result[dow] = pids
 
 
683
  return result
684
 
685
 
templates/shifts/input.html CHANGED
@@ -374,25 +374,24 @@ const PAT_CATS_JS = {
374
  {% for pid, cat in PAT_CATS.items() %}{{ pid|tojson }}: {{ cat|tojson }},{% endfor %}
375
  };
376
 
377
- // 曜日別の最頻パターン({python_weekday(0=月..6=日): pattern_id}、2回以上提出歴がある曜日のみ)
378
  const DOW_SUGGESTIONS = {
379
- {% for dow, pid in dow_suggestions.items() %}{{ dow }}: {{ pid|tojson }},{% endfor %}
380
  };
381
 
382
- // タップサイクル順:[休み, この曜日でよく使うパターン, 過去履歴サジェスト(最大3), 有給, カスタム手動入力]
383
- // 曜日(0=月..6=日)ごとに用意し、その曜日の入力履歴を優先表示する
384
  const TOP_PATTERNS = [{% for pid, cnt, cs, ce in top_patterns[:3] %}{{ pid|tojson }},{% endfor %}];
385
  const PAT_DEFAULTS = ['d_std1', 'b_std'];
 
386
  const PAT_CYCLE_BY_DOW = {};
387
  for (let dow = 0; dow < 7; dow++) {
388
  const seen = new Set(['', 'paid_leave', 'custom']); // 末尾固定枠を予約
389
  const cycle = [''];
390
- const dowPid = DOW_SUGGESTIONS[dow];
391
- if (dowPid && !seen.has(dowPid) && PAT_LABELS[dowPid]) {
392
- seen.add(dowPid); cycle.push(dowPid);
393
- }
394
- for (const p of [...TOP_PATTERNS, ...PAT_DEFAULTS]) {
395
- if (!seen.has(p) && PAT_LABELS[p]) { seen.add(p); cycle.push(p); if (cycle.length >= 4) break; }
396
  }
397
  cycle.push('paid_leave'); // 有給(固定)
398
  cycle.push('custom'); // カスタム手動入力(固定)
 
374
  {% for pid, cat in PAT_CATS.items() %}{{ pid|tojson }}: {{ cat|tojson }},{% endfor %}
375
  };
376
 
377
+ // 曜日別の頻出パターン({python_weekday(0=月..6=日): [pattern_id, ...]}、頻度降順・2回以上提出歴があるもののみ)
378
  const DOW_SUGGESTIONS = {
379
+ {% for dow, pids in dow_suggestions.items() %}{{ dow }}: {{ pids|tojson }},{% endfor %}
380
  };
381
 
382
+ // タップサイクル順:[休み, この曜日の頻出パターン(頻度順), 過去履歴サジェスト, 有給, カスタム手動入力]
383
+ // 曜日(0=月..6=日)ごとに用意し、その曜日の入力履歴を頻出順に優先表示する(最大3候補)
384
  const TOP_PATTERNS = [{% for pid, cnt, cs, ce in top_patterns[:3] %}{{ pid|tojson }},{% endfor %}];
385
  const PAT_DEFAULTS = ['d_std1', 'b_std'];
386
+ const SUGGESTION_SLOTS = 3;
387
  const PAT_CYCLE_BY_DOW = {};
388
  for (let dow = 0; dow < 7; dow++) {
389
  const seen = new Set(['', 'paid_leave', 'custom']); // 末尾固定枠を予約
390
  const cycle = [''];
391
+ const dowPids = DOW_SUGGESTIONS[dow] || [];
392
+ for (const p of [...dowPids, ...TOP_PATTERNS, ...PAT_DEFAULTS]) {
393
+ if (cycle.length > SUGGESTION_SLOTS) break;
394
+ if (!seen.has(p) && PAT_LABELS[p]) { seen.add(p); cycle.push(p); }
 
 
395
  }
396
  cycle.push('paid_leave'); // 有給(固定)
397
  cycle.push('custom'); // カスタム手動入力(固定)