Commit ·
bb8e0f9
1
Parent(s): 680a8f5
feat: 実際のシフト表データを元にしたテスト用シードスクリプトを追加
Browse files3月1-15日の実績シフト(38名)を基にテストデータを生成する
scripts/seed_test_data.py を追加。確定済みアサインに加えて
確定前のシフト希望データも生成し、アプリの動作確認に使用できる。
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- scripts/__init__.py +0 -0
- scripts/seed_test_data.py +630 -0
scripts/__init__.py
ADDED
|
File without changes
|
scripts/seed_test_data.py
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
"""
|
| 3 |
+
テストデータ生成スクリプト — 3月前半シフト (3/1〜3/15)
|
| 4 |
+
|
| 5 |
+
実際の確定シフト表をDBに登録し、確定前の希望シフト(実際のシフトに
|
| 6 |
+
近いが一部異なるバリエーション)も合わせて投入します。
|
| 7 |
+
|
| 8 |
+
使い方:
|
| 9 |
+
cd /home/shift-tool
|
| 10 |
+
python scripts/seed_test_data.py # データを追加
|
| 11 |
+
python scripts/seed_test_data.py --reset # 全データ削除後に追加
|
| 12 |
+
"""
|
| 13 |
+
from __future__ import annotations
|
| 14 |
+
import sys, os, random, argparse
|
| 15 |
+
|
| 16 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 17 |
+
|
| 18 |
+
from db.database import initialize_db, get_connection
|
| 19 |
+
from db import repositories as repo
|
| 20 |
+
from models.employee import Employee, FixedPattern
|
| 21 |
+
from models.schedule import SchedulePeriod, ShiftRequest, ShiftAssignment
|
| 22 |
+
from utils.constants import EmploymentType, SkillLevel, TimeSlot, Position
|
| 23 |
+
from utils.shift_patterns import ALL_PATTERNS, PATTERN_MAP, ShiftPattern
|
| 24 |
+
|
| 25 |
+
random.seed(42) # 再現性のある乱数
|
| 26 |
+
|
| 27 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 28 |
+
# 定数
|
| 29 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 30 |
+
PERIOD_START = "2024-03-01"
|
| 31 |
+
PERIOD_END = "2024-03-15"
|
| 32 |
+
|
| 33 |
+
# スロット判定の閾値
|
| 34 |
+
BREAKFAST_START, BREAKFAST_END = 6.0, 11.0
|
| 35 |
+
DINNER_START, DINNER_END = 17.0, 23.0
|
| 36 |
+
MIN_OVERLAP_H = 2.0
|
| 37 |
+
|
| 38 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 39 |
+
# 従業員マスター
|
| 40 |
+
# (name, employment_type, hall_skill, kitchen_skill, default_position)
|
| 41 |
+
# default_position: 主に担当するポジション ('hall' / 'kitchen')
|
| 42 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 43 |
+
EMPLOYEE_MASTER = [
|
| 44 |
+
# ── 正社員(ホール系・管理職) ─────────────────────────────────────
|
| 45 |
+
("池山", "full_time", "leader", "general", "hall"),
|
| 46 |
+
("安本", "full_time", "leader", "general", "hall"),
|
| 47 |
+
("﨑本", "full_time", "leader", "general", "hall"),
|
| 48 |
+
# ── 正社員(キッチン系・管理職) ───────────────────────────────────
|
| 49 |
+
("岡田", "full_time", "general", "leader", "kitchen"),
|
| 50 |
+
("鎌田", "full_time", "general", "leader", "kitchen"),
|
| 51 |
+
("タオリ", "full_time", "general", "veteran", "kitchen"),
|
| 52 |
+
# ── アルバイト(朝食ホール系) ─────────────────────────────────────
|
| 53 |
+
("林", "part_time", "veteran", "beginner", "hall"),
|
| 54 |
+
("ミツイ", "part_time", "veteran", "beginner", "hall"),
|
| 55 |
+
("細田", "part_time", "general", "general", "hall"),
|
| 56 |
+
("アッスミタ", "part_time", "general", "beginner", "hall"),
|
| 57 |
+
("マニス", "part_time", "general", "beginner", "hall"),
|
| 58 |
+
("レジーナ", "part_time", "general", "beginner", "hall"),
|
| 59 |
+
("ビルシャナ", "part_time", "general", "beginner", "hall"),
|
| 60 |
+
("藤内", "part_time", "general", "beginner", "hall"),
|
| 61 |
+
("上田", "part_time", "general", "beginner", "hall"),
|
| 62 |
+
("津波古", "part_time", "general", "beginner", "hall"),
|
| 63 |
+
("カテリナ", "part_time", "general", "beginner", "hall"),
|
| 64 |
+
("キム", "part_time", "general", "beginner", "hall"),
|
| 65 |
+
("齊藤", "part_time", "general", "beginner", "hall"),
|
| 66 |
+
("藤畑", "part_time", "beginner","beginner", "hall"),
|
| 67 |
+
# ── アルバイト(朝食キッチン系) ───────────────────────────────────
|
| 68 |
+
("田中", "part_time", "beginner","general", "kitchen"),
|
| 69 |
+
("島野", "part_time", "beginner","general", "kitchen"),
|
| 70 |
+
("チャー", "part_time", "beginner","general", "kitchen"),
|
| 71 |
+
("坂田", "part_time", "general", "general", "kitchen"),
|
| 72 |
+
("北", "part_time", "beginner","beginner", "kitchen"),
|
| 73 |
+
# ── アルバイト(ディナーホール系) ─────────────────────────────────
|
| 74 |
+
("南愛菜", "part_time", "general", "beginner", "hall"),
|
| 75 |
+
("ドリアン", "part_time", "general", "beginner", "hall"),
|
| 76 |
+
("中家", "part_time", "general", "beginner", "hall"),
|
| 77 |
+
("光久", "part_time", "general", "beginner", "hall"),
|
| 78 |
+
("南志穂", "part_time", "general", "beginner", "hall"),
|
| 79 |
+
("岡本", "part_time", "general", "general", "hall"),
|
| 80 |
+
("廣田", "part_time", "beginner","beginner", "hall"),
|
| 81 |
+
("リット", "part_time", "general", "beginner", "hall"),
|
| 82 |
+
("鈴木", "part_time", "general", "beginner", "hall"),
|
| 83 |
+
# ── アルバイト(ディナーキッチン系) ───────────────────────────────
|
| 84 |
+
("名古", "part_time", "beginner","general", "kitchen"),
|
| 85 |
+
("坂本", "part_time", "beginner","general", "kitchen"),
|
| 86 |
+
# ── その他 ────────────────────────────────────────────────────────
|
| 87 |
+
("井上", "part_time", "beginner","beginner", "hall"),
|
| 88 |
+
("アリャー", "part_time", "beginner","beginner", "hall"),
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 92 |
+
# 確定シフトデータ (CSVから抽出)
|
| 93 |
+
# 形式: {name: {date: (start_decimal, end_decimal, note)}}
|
| 94 |
+
# - start/end が None の場合は有給か休み
|
| 95 |
+
# - note == "有給" → 有給休暇
|
| 96 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 97 |
+
CONFIRMED_SHIFTS: dict[str, dict[str, tuple]] = {
|
| 98 |
+
"池山": {
|
| 99 |
+
"2024-03-01": (13.0, 22.5, ""),
|
| 100 |
+
"2024-03-03": (13.0, 22.5, ""),
|
| 101 |
+
"2024-03-04": (13.0, 22.5, ""),
|
| 102 |
+
"2024-03-06": (13.0, 22.5, ""),
|
| 103 |
+
"2024-03-08": (13.0, 22.5, ""),
|
| 104 |
+
"2024-03-09": (None, None, "有給"),
|
| 105 |
+
"2024-03-10": (13.0, 22.5, ""),
|
| 106 |
+
"2024-03-11": (13.0, 22.5, ""),
|
| 107 |
+
"2024-03-13": (13.0, 22.5, ""),
|
| 108 |
+
"2024-03-14": (13.0, 22.5, ""),
|
| 109 |
+
},
|
| 110 |
+
"安本": {
|
| 111 |
+
"2024-03-02": (13.0, 22.5, ""),
|
| 112 |
+
"2024-03-03": (13.0, 22.5, ""),
|
| 113 |
+
"2024-03-05": (13.0, 22.5, ""),
|
| 114 |
+
"2024-03-06": (13.0, 22.5, ""),
|
| 115 |
+
"2024-03-08": (13.0, 22.5, ""),
|
| 116 |
+
"2024-03-09": (13.0, 22.5, ""),
|
| 117 |
+
"2024-03-11": (13.0, 22.5, ""),
|
| 118 |
+
"2024-03-12": (13.0, 22.5, ""),
|
| 119 |
+
"2024-03-13": (13.0, 22.5, ""),
|
| 120 |
+
"2024-03-14": (None, None, "有給"),
|
| 121 |
+
},
|
| 122 |
+
"﨑本": {
|
| 123 |
+
"2024-03-01": (13.0, 22.5, ""),
|
| 124 |
+
"2024-03-02": (13.0, 22.5, ""),
|
| 125 |
+
"2024-03-03": (13.0, 22.5, ""),
|
| 126 |
+
"2024-03-04": (13.0, 22.5, ""),
|
| 127 |
+
"2024-03-06": (13.0, 22.5, ""),
|
| 128 |
+
"2024-03-07": (13.0, 22.5, ""),
|
| 129 |
+
"2024-03-08": (13.0, 22.5, ""),
|
| 130 |
+
"2024-03-10": (13.0, 22.5, ""),
|
| 131 |
+
"2024-03-11": (13.0, 22.5, ""),
|
| 132 |
+
"2024-03-14": (13.0, 22.5, ""),
|
| 133 |
+
"2024-03-15": (13.0, 22.5, ""),
|
| 134 |
+
},
|
| 135 |
+
"岡田": {
|
| 136 |
+
"2024-03-02": (14.0, 23.0, ""),
|
| 137 |
+
"2024-03-03": (10.0, 23.0, "休憩4h"),
|
| 138 |
+
"2024-03-04": (14.0, 23.0, ""),
|
| 139 |
+
"2024-03-06": (14.0, 23.0, ""),
|
| 140 |
+
"2024-03-07": (10.0, 19.0, ""),
|
| 141 |
+
"2024-03-08": (14.0, 23.0, ""),
|
| 142 |
+
"2024-03-10": (14.0, 23.0, ""),
|
| 143 |
+
"2024-03-11": (None, None, "有給"),
|
| 144 |
+
"2024-03-12": (14.0, 23.0, ""),
|
| 145 |
+
},
|
| 146 |
+
"鎌田": {
|
| 147 |
+
"2024-03-01": (14.0, 23.0, ""),
|
| 148 |
+
"2024-03-02": (14.0, 23.0, ""),
|
| 149 |
+
"2024-03-05": (14.0, 23.0, ""),
|
| 150 |
+
"2024-03-06": (14.0, 23.0, ""),
|
| 151 |
+
"2024-03-07": (14.0, 23.0, ""),
|
| 152 |
+
"2024-03-09": (14.0, 23.0, ""),
|
| 153 |
+
"2024-03-11": (14.0, 23.0, ""),
|
| 154 |
+
"2024-03-12": (14.0, 23.0, ""),
|
| 155 |
+
"2024-03-13": (12.0, 23.0, ""),
|
| 156 |
+
},
|
| 157 |
+
"タオリ": {
|
| 158 |
+
"2024-03-01": (5.75, 14.75, ""),
|
| 159 |
+
"2024-03-03": (14.0, 23.0, ""),
|
| 160 |
+
"2024-03-04": (14.0, 23.0, ""),
|
| 161 |
+
"2024-03-05": (14.0, 23.0, ""),
|
| 162 |
+
"2024-03-06": (5.75, 14.75, ""),
|
| 163 |
+
"2024-03-09": (14.0, 23.0, ""),
|
| 164 |
+
"2024-03-10": (14.0, 23.0, ""),
|
| 165 |
+
"2024-03-11": (14.0, 23.0, ""),
|
| 166 |
+
"2024-03-12": (5.75, 14.75, ""),
|
| 167 |
+
},
|
| 168 |
+
"林": {
|
| 169 |
+
"2024-03-02": (5.75, 14.75, ""),
|
| 170 |
+
"2024-03-03": (5.75, 11.5, ""),
|
| 171 |
+
"2024-03-05": (5.75, 11.5, ""),
|
| 172 |
+
"2024-03-06": (5.75, 14.75, ""),
|
| 173 |
+
"2024-03-07": (5.75, 14.75, ""),
|
| 174 |
+
"2024-03-08": (5.75, 11.5, ""),
|
| 175 |
+
"2024-03-10": (5.75, 14.75, ""),
|
| 176 |
+
"2024-03-11": (5.75, 14.75, ""),
|
| 177 |
+
"2024-03-13": (5.75, 14.75, ""),
|
| 178 |
+
"2024-03-15": (5.75, 14.75, ""),
|
| 179 |
+
},
|
| 180 |
+
"ミツイ": {
|
| 181 |
+
"2024-03-01": (5.75, 14.75, ""),
|
| 182 |
+
"2024-03-03": (5.75, 14.5, ""),
|
| 183 |
+
"2024-03-04": (5.75, 14.75, ""),
|
| 184 |
+
"2024-03-05": (5.75, 11.5, ""),
|
| 185 |
+
"2024-03-09": (5.75, 14.75, ""),
|
| 186 |
+
"2024-03-10": (5.75, 11.5, ""),
|
| 187 |
+
"2024-03-11": (5.75, 14.75, ""),
|
| 188 |
+
"2024-03-12": (5.75, 14.75, ""),
|
| 189 |
+
},
|
| 190 |
+
"細田": {
|
| 191 |
+
"2024-03-01": (5.75, 11.5, ""),
|
| 192 |
+
"2024-03-02": (5.75, 11.5, ""),
|
| 193 |
+
"2024-03-04": (5.75, 11.5, ""),
|
| 194 |
+
"2024-03-05": (5.75, 14.75, ""),
|
| 195 |
+
"2024-03-08": (5.75, 14.75, ""),
|
| 196 |
+
"2024-03-09": (5.75, 11.5, ""),
|
| 197 |
+
"2024-03-10": (5.75, 11.5, ""),
|
| 198 |
+
"2024-03-11": (5.75, 11.5, ""),
|
| 199 |
+
"2024-03-13": (17.0, 23.0, ""), # ディナーにも入る
|
| 200 |
+
},
|
| 201 |
+
"アッスミタ": {
|
| 202 |
+
"2024-03-01": (6.0, 11.5, ""),
|
| 203 |
+
"2024-03-04": (6.0, 11.5, ""),
|
| 204 |
+
"2024-03-08": (6.0, 11.5, ""),
|
| 205 |
+
"2024-03-13": (6.0, 11.5, ""),
|
| 206 |
+
},
|
| 207 |
+
"マニス": {
|
| 208 |
+
"2024-03-02": (6.0, 11.5, ""),
|
| 209 |
+
"2024-03-05": (6.5, 11.5, ""),
|
| 210 |
+
"2024-03-09": (6.0, 11.5, ""),
|
| 211 |
+
},
|
| 212 |
+
"レジーナ": {
|
| 213 |
+
"2024-03-06": (6.0, 11.5, ""),
|
| 214 |
+
"2024-03-11": (6.0, 11.5, ""),
|
| 215 |
+
},
|
| 216 |
+
"ビルシャナ": {
|
| 217 |
+
"2024-03-07": (6.0, 11.5, ""),
|
| 218 |
+
"2024-03-12": (6.0, 11.5, ""),
|
| 219 |
+
},
|
| 220 |
+
"藤内": {
|
| 221 |
+
"2024-03-01": (5.75, 11.5, ""),
|
| 222 |
+
"2024-03-04": (5.75, 11.5, ""),
|
| 223 |
+
"2024-03-07": (5.75, 11.5, ""),
|
| 224 |
+
"2024-03-08": (5.75, 11.5, ""),
|
| 225 |
+
},
|
| 226 |
+
"上田": {
|
| 227 |
+
"2024-03-03": (5.75, 11.5, ""),
|
| 228 |
+
"2024-03-10": (5.75, 11.5, ""),
|
| 229 |
+
},
|
| 230 |
+
"津波古": {
|
| 231 |
+
"2024-03-02": (6.0, 11.5, ""),
|
| 232 |
+
"2024-03-11": (6.0, 11.5, ""),
|
| 233 |
+
},
|
| 234 |
+
"カテリナ": {
|
| 235 |
+
"2024-03-01": (6.0, 11.5, "朝初"),
|
| 236 |
+
"2024-03-02": (6.0, 11.5, ""),
|
| 237 |
+
"2024-03-08": (6.0, 11.5, ""),
|
| 238 |
+
"2024-03-10": (6.0, 11.5, ""),
|
| 239 |
+
},
|
| 240 |
+
"キム": {
|
| 241 |
+
"2024-03-09": (18.0, 22.5, "夜初"),
|
| 242 |
+
"2024-03-10": (18.0, 22.5, ""),
|
| 243 |
+
},
|
| 244 |
+
"齊藤": {
|
| 245 |
+
"2024-03-03": (6.0, 11.5, ""),
|
| 246 |
+
"2024-03-06": (6.0, 11.5, ""),
|
| 247 |
+
"2024-03-07": (6.0, 11.5, ""),
|
| 248 |
+
},
|
| 249 |
+
"藤畑": {
|
| 250 |
+
"2024-03-05": (6.0, 9.0, ""),
|
| 251 |
+
"2024-03-10": (6.0, 9.0, ""),
|
| 252 |
+
},
|
| 253 |
+
"田中": {
|
| 254 |
+
"2024-03-09": (6.5, 10.0, ""),
|
| 255 |
+
"2024-03-14": (6.5, 10.0, ""),
|
| 256 |
+
},
|
| 257 |
+
"島野": {
|
| 258 |
+
"2024-03-04": (6.0, 10.0, ""),
|
| 259 |
+
"2024-03-05": (6.0, 10.0, ""),
|
| 260 |
+
"2024-03-07": (6.0, 10.0, ""),
|
| 261 |
+
"2024-03-11": (6.5, 10.0, ""),
|
| 262 |
+
"2024-03-12": (6.0, 10.0, ""),
|
| 263 |
+
},
|
| 264 |
+
"チャー": {
|
| 265 |
+
"2024-03-02": (7.0, 11.0, ""),
|
| 266 |
+
"2024-03-07": (7.0, 11.0, ""),
|
| 267 |
+
"2024-03-09": (6.5, 10.0, ""),
|
| 268 |
+
"2024-03-12": (18.0, 22.5, ""), # たまにディナーも
|
| 269 |
+
},
|
| 270 |
+
"坂田": {
|
| 271 |
+
"2024-03-04": (6.0, 10.5, ""),
|
| 272 |
+
"2024-03-06": (6.5, 10.0, ""),
|
| 273 |
+
"2024-03-07": (6.0, 10.0, ""),
|
| 274 |
+
"2024-03-12": (6.5, 10.5, ""),
|
| 275 |
+
"2024-03-15": (17.5, 22.0, ""),
|
| 276 |
+
},
|
| 277 |
+
"北": {
|
| 278 |
+
"2024-03-03": (6.0, 10.0, ""),
|
| 279 |
+
"2024-03-08": (None, None, "有給"),
|
| 280 |
+
"2024-03-11": (6.0, 9.0, ""),
|
| 281 |
+
"2024-03-14": (6.0, 10.0, ""),
|
| 282 |
+
},
|
| 283 |
+
"南愛菜": {
|
| 284 |
+
"2024-03-01": (18.5, 23.0, "ホール兼任"),
|
| 285 |
+
"2024-03-09": (18.5, 23.0, "ホール兼任"),
|
| 286 |
+
"2024-03-10": (18.0, 23.0, "ホール兼任"),
|
| 287 |
+
},
|
| 288 |
+
"ドリアン": {
|
| 289 |
+
"2024-03-01": (17.0, 22.5, ""),
|
| 290 |
+
"2024-03-03": (17.0, 22.5, ""),
|
| 291 |
+
"2024-03-05": (17.0, 22.5, ""),
|
| 292 |
+
"2024-03-10": (17.0, 22.5, ""),
|
| 293 |
+
"2024-03-11": (17.0, 22.5, ""),
|
| 294 |
+
},
|
| 295 |
+
"中家": {
|
| 296 |
+
"2024-03-02": (17.0, 23.0, "夜初"),
|
| 297 |
+
"2024-03-04": (17.0, 23.0, ""),
|
| 298 |
+
"2024-03-11": (17.0, 23.0, ""),
|
| 299 |
+
},
|
| 300 |
+
"光久": {
|
| 301 |
+
"2024-03-11": (17.5, 22.5, "ホール兼任"),
|
| 302 |
+
},
|
| 303 |
+
"南志穂": {
|
| 304 |
+
"2024-03-06": (17.5, 23.0, ""),
|
| 305 |
+
},
|
| 306 |
+
"岡本": {
|
| 307 |
+
"2024-03-01": (17.5, 22.0, ""),
|
| 308 |
+
"2024-03-03": (18.0, 22.0, ""),
|
| 309 |
+
"2024-03-04": (18.0, 22.0, ""),
|
| 310 |
+
"2024-03-05": (18.0, 23.0, ""),
|
| 311 |
+
"2024-03-06": (17.5, 21.0, ""),
|
| 312 |
+
"2024-03-08": (17.5, 21.0, ""),
|
| 313 |
+
"2024-03-09": (18.75, 22.0, "キッチン兼任"),
|
| 314 |
+
"2024-03-11": (18.0, 23.0, ""),
|
| 315 |
+
},
|
| 316 |
+
"廣田": {
|
| 317 |
+
"2024-03-02": (18.0, 22.5, ""),
|
| 318 |
+
"2024-03-06": (18.5, 22.5, ""),
|
| 319 |
+
},
|
| 320 |
+
"リット": {
|
| 321 |
+
"2024-03-06": (18.0, 23.0, ""),
|
| 322 |
+
"2024-03-08": (18.5, 23.0, ""),
|
| 323 |
+
},
|
| 324 |
+
"鈴木": {
|
| 325 |
+
"2024-03-01": (6.5, 11.5, ""),
|
| 326 |
+
"2024-03-15": (18.0, 23.0, ""),
|
| 327 |
+
},
|
| 328 |
+
"名古": {
|
| 329 |
+
"2024-03-03": (17.5, 23.0, "キッチン"),
|
| 330 |
+
"2024-03-07": (18.0, 23.0, ""),
|
| 331 |
+
"2024-03-11": (18.0, 23.0, ""),
|
| 332 |
+
"2024-03-13": (17.0, 23.0, ""),
|
| 333 |
+
"2024-03-14": (18.0, 23.0, ""),
|
| 334 |
+
},
|
| 335 |
+
"坂本": {
|
| 336 |
+
"2024-03-06": (18.0, 21.5, "キッチン兼任"),
|
| 337 |
+
"2024-03-09": (18.0, 21.5, ""),
|
| 338 |
+
},
|
| 339 |
+
"井上": {}, # シフトなし
|
| 340 |
+
"アリャー": {
|
| 341 |
+
"2024-03-12": (18.0, 21.0, ""),
|
| 342 |
+
},
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 346 |
+
# ユーティリティ関数
|
| 347 |
+
# ═════════════��═════════════════════════════════════════════════════════
|
| 348 |
+
|
| 349 |
+
def dec_to_hhmm(dec: float) -> str:
|
| 350 |
+
"""小数時刻 (5.75) → 'HH:MM' ('05:45')"""
|
| 351 |
+
h = int(dec)
|
| 352 |
+
m = round((dec - h) * 60)
|
| 353 |
+
if m == 60:
|
| 354 |
+
h += 1
|
| 355 |
+
m = 0
|
| 356 |
+
return f"{h:02d}:{m:02d}"
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
def overlaps_slot(s: float, e: float, slot_s: float, slot_e: float) -> bool:
|
| 360 |
+
"""シフトがスロットと MIN_OVERLAP_H 時間以上重なるか"""
|
| 361 |
+
overlap = max(0.0, min(e, slot_e) - max(s, slot_s))
|
| 362 |
+
return overlap >= MIN_OVERLAP_H
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def get_timeslots(s: float, e: float) -> list[str]:
|
| 366 |
+
"""(start, end) が朝食・ディナーのどちらをカバーするか返す"""
|
| 367 |
+
slots = []
|
| 368 |
+
if overlaps_slot(s, e, BREAKFAST_START, BREAKFAST_END):
|
| 369 |
+
slots.append(TimeSlot.BREAKFAST.value)
|
| 370 |
+
if overlaps_slot(s, e, DINNER_START, DINNER_END):
|
| 371 |
+
slots.append(TimeSlot.DINNER.value)
|
| 372 |
+
return slots
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
def find_pattern_id(s: float, e: float) -> tuple[str, str | None, str | None]:
|
| 376 |
+
"""
|
| 377 |
+
(start, end) に最も近いパターンIDを返す。
|
| 378 |
+
閾値内に該当なければ "custom" を返す。
|
| 379 |
+
"""
|
| 380 |
+
THRESHOLD = 0.3 # 18分以内なら一致とみなす
|
| 381 |
+
best, best_diff = None, float("inf")
|
| 382 |
+
for p in ALL_PATTERNS:
|
| 383 |
+
if p.id in ("custom", "double") or not p.start or not p.end:
|
| 384 |
+
continue
|
| 385 |
+
diff = abs(p.start_hour() - s) + abs(p.end_hour() - e)
|
| 386 |
+
if diff < best_diff:
|
| 387 |
+
best_diff = diff
|
| 388 |
+
best = p
|
| 389 |
+
if best and best_diff <= THRESHOLD:
|
| 390 |
+
return best.id, None, None
|
| 391 |
+
return "custom", dec_to_hhmm(s), dec_to_hhmm(e)
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 395 |
+
# 希望シフトのバリエーション生成(確定前を模擬)
|
| 396 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 397 |
+
# 確定シフトと異なる「希望」を生成するためのルール:
|
| 398 |
+
# ① 確定シフトと同じ日 → 同じパターンで希望
|
| 399 |
+
# ② 一部の日は「余分に空きを入れる」(希望したが入れなかった日)
|
| 400 |
+
# ③ 正社員は希望=確定(ほぼ固定)
|
| 401 |
+
|
| 402 |
+
def _random_extra_dates(name: str, confirmed_dates: set, all_dates: list) -> set:
|
| 403 |
+
"""確定されなかった「余分の希望日」をランダムで追加(アルバイトのみ)"""
|
| 404 |
+
candidates = [d for d in all_dates if d not in confirmed_dates]
|
| 405 |
+
n_extra = random.randint(0, min(3, len(candidates)))
|
| 406 |
+
return set(random.sample(candidates, n_extra))
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
def build_requests(
|
| 410 |
+
emp: Employee,
|
| 411 |
+
confirmed: dict[str, tuple],
|
| 412 |
+
all_dates: list[str],
|
| 413 |
+
employment_type: str,
|
| 414 |
+
) -> list[ShiftRequest]:
|
| 415 |
+
"""ShiftRequest のリストを生成(確定前の希望シフト)"""
|
| 416 |
+
requests = []
|
| 417 |
+
confirmed_dates = set(confirmed.keys())
|
| 418 |
+
|
| 419 |
+
# アルバイト: 余分希望日を追加
|
| 420 |
+
if employment_type == "part_time":
|
| 421 |
+
extra = _random_extra_dates(emp.name, confirmed_dates, all_dates)
|
| 422 |
+
else:
|
| 423 |
+
extra = set()
|
| 424 |
+
|
| 425 |
+
for date_str in all_dates:
|
| 426 |
+
if date_str in confirmed:
|
| 427 |
+
s, e, note = confirmed[date_str]
|
| 428 |
+
if note == "有給":
|
| 429 |
+
# 有給は希望に "有給" ノートを入れる
|
| 430 |
+
req = ShiftRequest(
|
| 431 |
+
employee_id=emp.id,
|
| 432 |
+
date=date_str,
|
| 433 |
+
pattern_id=None,
|
| 434 |
+
note="有給",
|
| 435 |
+
)
|
| 436 |
+
elif s is None:
|
| 437 |
+
continue # 休みはリクエスト不要
|
| 438 |
+
else:
|
| 439 |
+
pid, cs, ce = find_pattern_id(s, e)
|
| 440 |
+
req = ShiftRequest(
|
| 441 |
+
employee_id=emp.id,
|
| 442 |
+
date=date_str,
|
| 443 |
+
pattern_id=pid,
|
| 444 |
+
custom_start=cs,
|
| 445 |
+
custom_end=ce,
|
| 446 |
+
note=note,
|
| 447 |
+
)
|
| 448 |
+
requests.append(req)
|
| 449 |
+
|
| 450 |
+
elif date_str in extra:
|
| 451 |
+
# 余分希望: 主に使うパターン帯を再現
|
| 452 |
+
# 確定シフトのパターンから代表的な時間帯を推定
|
| 453 |
+
if confirmed:
|
| 454 |
+
sample = [v for v in confirmed.values() if v[0] is not None]
|
| 455 |
+
if sample:
|
| 456 |
+
ss, se, _ = random.choice(sample)
|
| 457 |
+
pid, cs, ce = find_pattern_id(ss, se)
|
| 458 |
+
requests.append(ShiftRequest(
|
| 459 |
+
employee_id=emp.id,
|
| 460 |
+
date=date_str,
|
| 461 |
+
pattern_id=pid,
|
| 462 |
+
custom_start=cs,
|
| 463 |
+
custom_end=ce,
|
| 464 |
+
note="",
|
| 465 |
+
))
|
| 466 |
+
|
| 467 |
+
return requests
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
# ═��═════════════════════════════════════════════════════════════════════
|
| 471 |
+
# 確定アサイン生成
|
| 472 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 473 |
+
|
| 474 |
+
def build_assignments(
|
| 475 |
+
emp: Employee,
|
| 476 |
+
confirmed: dict[str, tuple],
|
| 477 |
+
default_pos: str,
|
| 478 |
+
period_id: int,
|
| 479 |
+
) -> list[ShiftAssignment]:
|
| 480 |
+
"""ShiftAssignment のリストを生成(確定シフト)"""
|
| 481 |
+
assignments = []
|
| 482 |
+
for date_str, (s, e, note) in confirmed.items():
|
| 483 |
+
if s is None:
|
| 484 |
+
continue # 有給・休み
|
| 485 |
+
slots = get_timeslots(s, e)
|
| 486 |
+
# 備考にポジション情報がある場合は優先
|
| 487 |
+
pos_str = default_pos
|
| 488 |
+
note_lower = note.lower()
|
| 489 |
+
if "ホール" in note:
|
| 490 |
+
pos_str = "hall"
|
| 491 |
+
elif "キッチン" in note:
|
| 492 |
+
pos_str = "kitchen"
|
| 493 |
+
|
| 494 |
+
for slot_str in slots:
|
| 495 |
+
assignments.append(ShiftAssignment(
|
| 496 |
+
employee_id=emp.id,
|
| 497 |
+
date=date_str,
|
| 498 |
+
time_slot=TimeSlot(slot_str),
|
| 499 |
+
position=Position(pos_str),
|
| 500 |
+
))
|
| 501 |
+
return assignments
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 505 |
+
# メイン処理
|
| 506 |
+
# ═══════════════════════════════════════════════════════════════════════
|
| 507 |
+
|
| 508 |
+
def reset_db():
|
| 509 |
+
"""全データを削除(テーブル構造は維持)"""
|
| 510 |
+
conn = get_connection()
|
| 511 |
+
conn.execute("DELETE FROM shift_assignments")
|
| 512 |
+
conn.execute("DELETE FROM shift_requests")
|
| 513 |
+
conn.execute("DELETE FROM schedule_periods")
|
| 514 |
+
conn.execute("DELETE FROM fixed_patterns")
|
| 515 |
+
conn.execute("DELETE FROM fixed_unavailable_dates")
|
| 516 |
+
conn.execute("DELETE FROM employees")
|
| 517 |
+
conn.commit()
|
| 518 |
+
conn.close()
|
| 519 |
+
print("✓ 既存データをリセットしました")
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def main():
|
| 523 |
+
parser = argparse.ArgumentParser(description="テストデータ生成")
|
| 524 |
+
parser.add_argument("--reset", action="store_true", help="既存データを全削除してから追加")
|
| 525 |
+
args = parser.parse_args()
|
| 526 |
+
|
| 527 |
+
initialize_db()
|
| 528 |
+
if args.reset:
|
| 529 |
+
reset_db()
|
| 530 |
+
|
| 531 |
+
# ── 従業員を登録 ──────────────────────────────────────────────────
|
| 532 |
+
print("従業員を登録中...")
|
| 533 |
+
emp_map: dict[str, Employee] = {}
|
| 534 |
+
|
| 535 |
+
for name, emp_type, hall_sk, kit_sk, _ in EMPLOYEE_MASTER:
|
| 536 |
+
emp = Employee(
|
| 537 |
+
id=None,
|
| 538 |
+
name=name,
|
| 539 |
+
employment_type=EmploymentType(emp_type),
|
| 540 |
+
hall_skill=SkillLevel(hall_sk),
|
| 541 |
+
kitchen_skill=SkillLevel(kit_sk),
|
| 542 |
+
)
|
| 543 |
+
saved = repo.save_employee(emp)
|
| 544 |
+
emp_map[name] = saved
|
| 545 |
+
|
| 546 |
+
print(f" → {len(emp_map)} 名を登録")
|
| 547 |
+
|
| 548 |
+
# ── 期間を登録 ──────────────────────────────────────────────────
|
| 549 |
+
period = repo.save_period(SchedulePeriod(
|
| 550 |
+
id=None,
|
| 551 |
+
start_date=PERIOD_START,
|
| 552 |
+
end_date=PERIOD_END,
|
| 553 |
+
status="draft",
|
| 554 |
+
))
|
| 555 |
+
print(f" → 期間 {PERIOD_START}〜{PERIOD_END} (id={period.id}) を登録")
|
| 556 |
+
|
| 557 |
+
from datetime import date, timedelta
|
| 558 |
+
start_d = date.fromisoformat(PERIOD_START)
|
| 559 |
+
end_d = date.fromisoformat(PERIOD_END)
|
| 560 |
+
all_dates = []
|
| 561 |
+
cur = start_d
|
| 562 |
+
while cur <= end_d:
|
| 563 |
+
all_dates.append(cur.isoformat())
|
| 564 |
+
cur += timedelta(days=1)
|
| 565 |
+
|
| 566 |
+
# ── 希望シフトを登録 ──────────────────────────────────────────────
|
| 567 |
+
print("希望シフト(確定前)を登録中...")
|
| 568 |
+
pos_map = {name: pos for name, _, _, _, pos in EMPLOYEE_MASTER}
|
| 569 |
+
total_req = 0
|
| 570 |
+
for name, emp in emp_map.items():
|
| 571 |
+
confirmed = CONFIRMED_SHIFTS.get(name, {})
|
| 572 |
+
emp_type = next(t for n, t, _, _, _ in EMPLOYEE_MASTER if n == name)
|
| 573 |
+
requests = build_requests(emp, confirmed, all_dates, emp_type)
|
| 574 |
+
if requests:
|
| 575 |
+
repo.save_shift_requests(period.id, requests)
|
| 576 |
+
total_req += len(requests)
|
| 577 |
+
print(f" → {total_req} 件の希望シフトを登録")
|
| 578 |
+
|
| 579 |
+
# ── 確定シフトアサインを登録 ──────────────────────────────────────
|
| 580 |
+
print("確定シフト(アサイン)を登録中...")
|
| 581 |
+
all_assignments: list[ShiftAssignment] = []
|
| 582 |
+
for name, emp in emp_map.items():
|
| 583 |
+
confirmed = CONFIRMED_SHIFTS.get(name, {})
|
| 584 |
+
default_pos = pos_map.get(name, "hall")
|
| 585 |
+
assignments = build_assignments(emp, confirmed, default_pos, period.id)
|
| 586 |
+
all_assignments.extend(assignments)
|
| 587 |
+
repo.save_assignments(period.id, all_assignments)
|
| 588 |
+
print(f" → {len(all_assignments)} 件のアサインを登録")
|
| 589 |
+
|
| 590 |
+
# ── 制約チェックサマリ ────────────────────────────────────────────
|
| 591 |
+
print("\n=== 日別制約チェック (朝食/ディナー) ===")
|
| 592 |
+
from collections import defaultdict
|
| 593 |
+
from utils.constants import SHIFT_CONSTRAINTS
|
| 594 |
+
assign_map = defaultdict(int)
|
| 595 |
+
for a in all_assignments:
|
| 596 |
+
assign_map[(a.date, a.time_slot.value, a.position.value)] += 1
|
| 597 |
+
|
| 598 |
+
violations = 0
|
| 599 |
+
for ds in all_dates:
|
| 600 |
+
d = date.fromisoformat(ds)
|
| 601 |
+
issues = []
|
| 602 |
+
for (slot, pos), c in SHIFT_CONSTRAINTS.items():
|
| 603 |
+
cnt = assign_map[(ds, slot.value, pos.value)]
|
| 604 |
+
if cnt < c["min"]:
|
| 605 |
+
issues.append(
|
| 606 |
+
f" ❌ {slot.short_label()}{pos.label()}: {cnt}名 < min{c['min']}"
|
| 607 |
+
)
|
| 608 |
+
violations += 1
|
| 609 |
+
if issues:
|
| 610 |
+
dow = ["月","火","水","木","金","土","日"][d.weekday()]
|
| 611 |
+
print(f" {d.month}/{d.day}({dow})")
|
| 612 |
+
for msg in issues:
|
| 613 |
+
print(msg)
|
| 614 |
+
|
| 615 |
+
if violations == 0:
|
| 616 |
+
print(" 全日程で人員制約クリア ✓")
|
| 617 |
+
else:
|
| 618 |
+
print(f"\n ⚠ {violations}件の制約違反(実際のシフト表を忠実に再現した結果)")
|
| 619 |
+
print(" ※ テスト用データのため、一部日程でスタッフが少ない場合があります")
|
| 620 |
+
|
| 621 |
+
print("\n✅ テストデータの生成が完了しました")
|
| 622 |
+
print(f" 期間ID: {period.id}")
|
| 623 |
+
print(f" 従業員: {len(emp_map)} 名")
|
| 624 |
+
print(f" 希望シフト: {total_req} 件")
|
| 625 |
+
print(f" 確定アサイン: {len(all_assignments)} 件")
|
| 626 |
+
print("\nアプリを起動して「シフト表 確認・編集」画面で確認できます。")
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
if __name__ == "__main__":
|
| 630 |
+
main()
|