Commit ·
4139434
1
Parent(s): 6ceaebb
feat: Google Forms 設計をスタッフ向けUX重視に改訂
Browse files- 名前欄をプルダウンに変更(登録スタッフ名を選択肢として自動生成)
- 日付質問を「選択式グリッド」(週単位)に変更(最大31問→2〜3問に削減)
- カスタム時刻のパース幅を拡大(全角→半角正規化、.区切り、en/emダッシュ対応)
- 全設問を必須→任意に変更(未回答=スキップ)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ui/forms_import_dialog.py +1 -1
- utils/forms_csv_parser.py +97 -19
ui/forms_import_dialog.py
CHANGED
|
@@ -155,7 +155,7 @@ class FormsImportDialog(QDialog):
|
|
| 155 |
|
| 156 |
def _build_guide_text(self) -> str:
|
| 157 |
from utils.forms_csv_parser import build_form_guide
|
| 158 |
-
return build_form_guide(self._period)
|
| 159 |
|
| 160 |
def _copy_guide(self):
|
| 161 |
from PyQt6.QtWidgets import QApplication
|
|
|
|
| 155 |
|
| 156 |
def _build_guide_text(self) -> str:
|
| 157 |
from utils.forms_csv_parser import build_form_guide
|
| 158 |
+
return build_form_guide(self._period, self._employees)
|
| 159 |
|
| 160 |
def _copy_guide(self):
|
| 161 |
from PyQt6.QtWidgets import QApplication
|
utils/forms_csv_parser.py
CHANGED
|
@@ -59,12 +59,23 @@ def _parse_custom_times(raw: str, period: SchedulePeriod) -> dict[str, tuple[str
|
|
| 59 |
対応フォーマット:
|
| 60 |
- 4/1: 10:00〜16:00
|
| 61 |
- 4月1日: 10:00〜16:00
|
|
|
|
| 62 |
- 4/1 10:00-16:00
|
| 63 |
- 4/1 10:00~16:00
|
|
|
|
|
|
|
| 64 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
result: dict[str, tuple[str, str]] = {}
|
| 66 |
pattern = re.findall(
|
| 67 |
-
r'(\d{1,2})[/月](\d{1,2})[日]?
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
raw,
|
| 69 |
)
|
| 70 |
for month_s, day_s, start, end in pattern:
|
|
@@ -216,9 +227,14 @@ def parse_forms_csv(
|
|
| 216 |
# Google Forms 設問テンプレート文字列
|
| 217 |
# ─────────────────────────────────────────────────────────────────────────────
|
| 218 |
|
| 219 |
-
def build_form_guide(period: SchedulePeriod) -> str:
|
| 220 |
"""
|
| 221 |
指定期間用の Google Forms 設問テンプレートを人間が読める文字列で返す。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
"""
|
| 223 |
from utils.constants import DAY_OF_WEEK_LABELS
|
| 224 |
|
|
@@ -227,35 +243,97 @@ def build_form_guide(period: SchedulePeriod) -> str:
|
|
| 227 |
f" Google Forms テンプレート (対象期間: {period.start_date} ~ {period.end_date})",
|
| 228 |
"═══════════════════════════════════════════════════════",
|
| 229 |
"",
|
| 230 |
-
"
|
| 231 |
-
"
|
| 232 |
-
"",
|
| 233 |
-
"
|
|
|
|
| 234 |
]
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
|
| 240 |
lines += [
|
|
|
|
|
|
|
|
|
|
| 241 |
"",
|
| 242 |
-
" ↑ 全日付の選択肢(この文字列をそのままコピー):",
|
| 243 |
-
" 休み(出勤不可)",
|
| 244 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
for p in ALL_PATTERNS:
|
| 246 |
if p.id != "custom":
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
lines += [
|
| 249 |
-
"
|
| 250 |
-
"",
|
| 251 |
-
"
|
| 252 |
-
"
|
| 253 |
-
"
|
|
|
|
|
|
|
|
|
|
| 254 |
"",
|
| 255 |
-
"
|
|
|
|
|
|
|
|
|
|
| 256 |
"",
|
| 257 |
"═══════════════════════════════════════════════════════",
|
| 258 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
"═══════════════════════════════════════════════════════",
|
| 260 |
]
|
| 261 |
return "\n".join(lines)
|
|
|
|
| 59 |
対応フォーマット:
|
| 60 |
- 4/1: 10:00〜16:00
|
| 61 |
- 4月1日: 10:00〜16:00
|
| 62 |
+
- 4.1 10:00〜16:00
|
| 63 |
- 4/1 10:00-16:00
|
| 64 |
- 4/1 10:00~16:00
|
| 65 |
+
- 4/1 10:00–16:00 (en dash)
|
| 66 |
+
- 全角数字・全角コロン(自動で半角に変換)
|
| 67 |
"""
|
| 68 |
+
import unicodedata
|
| 69 |
+
# 全角英数記号を半角に統一(1→1、:→: など)
|
| 70 |
+
raw = unicodedata.normalize('NFKC', raw)
|
| 71 |
+
|
| 72 |
result: dict[str, tuple[str, str]] = {}
|
| 73 |
pattern = re.findall(
|
| 74 |
+
r'(\d{1,2})[/月.\-](\d{1,2})[日]?' # 日付: 4/1 4月1日 4.1 4-1
|
| 75 |
+
r'[\s::]*' # 区切り (コロン・スペース・なし)
|
| 76 |
+
r'(\d{1,2}:\d{2})' # 開始時刻
|
| 77 |
+
r'\s*[〜~~\-–—]+\s*' # 範囲記号
|
| 78 |
+
r'(\d{1,2}:\d{2})', # 終了時刻
|
| 79 |
raw,
|
| 80 |
)
|
| 81 |
for month_s, day_s, start, end in pattern:
|
|
|
|
| 227 |
# Google Forms 設問テンプレート文字列
|
| 228 |
# ─────────────────────────────────────────────────────────────────────────────
|
| 229 |
|
| 230 |
+
def build_form_guide(period: SchedulePeriod, employees=None) -> str:
|
| 231 |
"""
|
| 232 |
指定期間用の Google Forms 設問テンプレートを人間が読める文字列で返す。
|
| 233 |
+
|
| 234 |
+
Parameters
|
| 235 |
+
----------
|
| 236 |
+
period : 対象シフト期間
|
| 237 |
+
employees : 登録済みスタッフ一覧(Noneの場合は「登録済みスタッフ名」と表記)
|
| 238 |
"""
|
| 239 |
from utils.constants import DAY_OF_WEEK_LABELS
|
| 240 |
|
|
|
|
| 243 |
f" Google Forms テンプレート (対象期間: {period.start_date} ~ {period.end_date})",
|
| 244 |
"═══════════════════════════════════════════════════════",
|
| 245 |
"",
|
| 246 |
+
"┌─────────────────────────────────────────────────────",
|
| 247 |
+
"│ 【Q1】お名前 ← プルダウン(任意)",
|
| 248 |
+
"│",
|
| 249 |
+
"│ 作成手順: 「プルダウン」を選択 → 選択肢に以下を追加",
|
| 250 |
+
"│",
|
| 251 |
]
|
| 252 |
|
| 253 |
+
if employees:
|
| 254 |
+
for emp in employees:
|
| 255 |
+
lines.append(f"│ {emp.name}")
|
| 256 |
+
else:
|
| 257 |
+
lines.append("│ (登録済みスタッフ名を1名ずつ追加してください)")
|
| 258 |
|
| 259 |
lines += [
|
| 260 |
+
"│",
|
| 261 |
+
"│ ※ 「必須」はオフ(未回答 = スキップ扱い)",
|
| 262 |
+
"└─────────────────────────────────────────────────────",
|
| 263 |
"",
|
|
|
|
|
|
|
| 264 |
]
|
| 265 |
+
|
| 266 |
+
# 日付を週ごとに分割
|
| 267 |
+
all_dates = list(period.date_range())
|
| 268 |
+
weeks: list[list] = []
|
| 269 |
+
chunk: list = []
|
| 270 |
+
for d in all_dates:
|
| 271 |
+
chunk.append(d)
|
| 272 |
+
if d.weekday() == 6 or d == all_dates[-1]: # 日曜 or 最終日
|
| 273 |
+
weeks.append(chunk)
|
| 274 |
+
chunk = []
|
| 275 |
+
|
| 276 |
+
# 選択肢(グリッドの列)
|
| 277 |
+
choice_lines = [" 休み(出勤不可)"]
|
| 278 |
for p in ALL_PATTERNS:
|
| 279 |
if p.id != "custom":
|
| 280 |
+
choice_lines.append(f" {p.label}")
|
| 281 |
+
choice_lines.append(" カスタム(備考に時刻を記入)")
|
| 282 |
+
|
| 283 |
+
for week_idx, week_dates in enumerate(weeks):
|
| 284 |
+
start_d = week_dates[0]
|
| 285 |
+
end_d = week_dates[-1]
|
| 286 |
+
label = f"第{week_idx+1}週({start_d.month}/{start_d.day}〜{end_d.month}/{end_d.day})の出勤希望"
|
| 287 |
+
|
| 288 |
+
lines += [
|
| 289 |
+
"┌─────────────────────────────────────────────────────",
|
| 290 |
+
f"│ 【グリッドQ{week_idx+2}】{label}",
|
| 291 |
+
"│ ← 選択式グリッド(任意)",
|
| 292 |
+
"│",
|
| 293 |
+
"│ 作成手順:",
|
| 294 |
+
"│ 1. 「選択式グリッド」を選択",
|
| 295 |
+
f"│ 2. 質問文: 「{label}」",
|
| 296 |
+
"│ 3. 「各行に回答を必須にする」は オフ",
|
| 297 |
+
"│",
|
| 298 |
+
"│ ▼ 行(日付)をこの順に追加:",
|
| 299 |
+
]
|
| 300 |
+
for d in week_dates:
|
| 301 |
+
dow = DAY_OF_WEEK_LABELS[d.weekday()]
|
| 302 |
+
lines.append(f"│ {d.month}月{d.day}日({dow})")
|
| 303 |
+
|
| 304 |
+
lines += [
|
| 305 |
+
"│",
|
| 306 |
+
"│ ▼ 列(シフト選択肢)をこの順に追加:",
|
| 307 |
+
]
|
| 308 |
+
lines += [f"│ {c}" for c in choice_lines]
|
| 309 |
+
lines += [
|
| 310 |
+
"│",
|
| 311 |
+
"│ ※ グリッドの列選択肢は全週で共通(コピー&ペーストで作成可)",
|
| 312 |
+
"└─────────────────────────────────────────────────────",
|
| 313 |
+
"",
|
| 314 |
+
]
|
| 315 |
+
|
| 316 |
lines += [
|
| 317 |
+
"┌─────────────────────────────────────────────────────",
|
| 318 |
+
"│ 【最終Q】カスタム入力の時刻 ← 記述式(長文)・任意",
|
| 319 |
+
"│",
|
| 320 |
+
"│ 質問文: 「カスタムを選んだ日の時刻を入力してください」",
|
| 321 |
+
"│ 説明文: 「日付と時刻をセットで記入してください",
|
| 322 |
+
"│ 例: 4/1 10:00〜16:00 4/5 13:00〜22:00",
|
| 323 |
+
"│ (カンマ・改行・スペース区切り、どれでも可)」",
|
| 324 |
+
"└─────────────────────────────────────────────────────",
|
| 325 |
"",
|
| 326 |
+
"┌─────────────────────────────────────────────────────",
|
| 327 |
+
"│ 【任意Q】その他備考 ← 記述式(長文)・任意",
|
| 328 |
+
"│ 質問文: 「その他、シフトに関する連絡事項があれば記入してください」",
|
| 329 |
+
"└─────────────────────────────────────────────────────",
|
| 330 |
"",
|
| 331 |
"═══════════════════════════════════════════════════════",
|
| 332 |
+
" 【CSV 取り込み手順】",
|
| 333 |
+
" 1. フォームの回答タブ → スプレッドシートにリンク",
|
| 334 |
+
" 2. スプレッドシートを開く",
|
| 335 |
+
" 3. ファイル → ダウンロード → CSV(.csv)",
|
| 336 |
+
" 4. このアプリの「希望シフト入力」画面で「Google Forms CSV をインポート」",
|
| 337 |
"═══════════════════════════════════════════════════════",
|
| 338 |
]
|
| 339 |
return "\n".join(lines)
|