claude-configs/skills/paper-dynasty/scripts/generate_summary.py
Cal Corum 0fa8486e93 Sync: update agents, paper-dynasty skills, sessions
- agents: issue-worker.md and pr-reviewer.md updated for standard
  branch naming (issue/<number>-<slug> instead of ai/<repo>#<number>)
- paper-dynasty: updated SKILL.md, generate_summary, smoke_test,
  validate_database scripts; added ecosystem_status.sh and plan/
- plugins: updated marketplace submodules and blocklist
- sessions: rotate session files, add session-analysis/
- settings: updated settings.json

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 23:03:10 -05:00

150 lines
4.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Generate summary report for Paper Dynasty card update
Collects statistics and notable changes for release notes.
Uses the Paper Dynasty API instead of direct database access.
Usage:
python generate_summary.py [--cardset-id 24] [--env prod]
"""
import sys
import argparse
from pathlib import Path
from datetime import datetime
from typing import List, Dict, Tuple
sys.path.insert(0, str(Path(__file__).parent.parent))
from api_client import PaperDynastyAPI
def get_card_counts(api: PaperDynastyAPI, cardset_id: int) -> Dict[str, int]:
"""Get total card counts from the API"""
batting = api.get("battingcards", params=[("cardset_id", cardset_id)])
pitching = api.get("pitchingcards", params=[("cardset_id", cardset_id)])
b_count = batting.get("count", 0)
p_count = pitching.get("count", 0)
return {"batting": b_count, "pitching": p_count, "total": b_count + p_count}
def get_player_count(api: PaperDynastyAPI, cardset_id: int) -> int:
"""Get total player count for the cardset from the API"""
try:
players = api.list_players(cardset_id=cardset_id)
return len(players)
except Exception:
return 0
def get_date_range(card_creation_dir: Path) -> Tuple[str, str]:
"""Extract date range from retrosheet_data.py"""
retrosheet_file = card_creation_dir / "retrosheet_data.py"
if not retrosheet_file.exists():
return "Unknown", "Unknown"
content = retrosheet_file.read_text()
start_date = "Unknown"
end_date = "Unknown"
for line in content.split('\n'):
if 'START_DATE' in line and '=' in line:
start_date = line.split('=')[1].strip().strip('"\'')
elif 'END_DATE' in line and '=' in line:
end_date = line.split('=')[1].strip().strip('"\'')
return start_date, end_date
def generate_markdown_summary(
counts: Dict[str, int],
player_count: int,
date_range: Tuple[str, str],
csv_files: List[str],
cardset_id: int,
env: str,
) -> str:
"""Generate markdown summary report"""
today = datetime.now().strftime('%Y-%m-%d')
start_date, end_date = date_range
lines = [
f"# Paper Dynasty Card Update - {today}",
"",
"## Overview",
f"- **Total Cards**: {counts['batting']} batting, {counts['pitching']} pitching",
f"- **Total Players**: {player_count}",
f"- **Data Range**: {start_date} to {end_date}",
f"- **Cardset ID**: {cardset_id} ({env})",
"",
"## Files Generated",
"- ✅ Card images uploaded to S3",
"- ✅ Scouting CSVs transferred to database server",
]
for csv_file in csv_files:
lines.append(f" - {csv_file}")
lines.extend([
"",
"## Validation",
"- ✅ No negative groundball_b values",
"- ✅ All required fields populated",
"- ✅ Database integrity checks passed",
"",
"---",
"Generated by Claude Code - Paper Dynasty Cards Skill",
])
return "\n".join(lines)
def main():
parser = argparse.ArgumentParser(
description="Generate summary report for Paper Dynasty card update"
)
parser.add_argument(
"--cardset-id", type=int, default=24,
help="Cardset ID to summarize (default: 24, the live cardset)"
)
parser.add_argument(
"--env", choices=["prod", "dev"], default="prod",
help="API environment (default: prod)"
)
args = parser.parse_args()
api = PaperDynastyAPI(environment=args.env)
# Collect data from API
counts = get_card_counts(api, args.cardset_id)
player_count = get_player_count(api, args.cardset_id)
# Get date range from retrosheet_data.py if present
card_creation_dir = Path("/mnt/NV2/Development/paper-dynasty/card-creation")
date_range = get_date_range(card_creation_dir)
# Get CSV files from scouting directory
scouting_dir = card_creation_dir / "scouting"
csv_files = sorted([f.name for f in scouting_dir.glob("*.csv")]) if scouting_dir.exists() else []
# Generate summary
summary = generate_markdown_summary(
counts, player_count, date_range, csv_files, args.cardset_id, args.env
)
# Print to stdout
print(summary)
# Save to file
output_file = Path.home() / ".claude" / "scratchpad" / f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_card_update_summary.md"
output_file.parent.mkdir(parents=True, exist_ok=True)
output_file.write_text(summary)
print(f"\n✅ Summary saved to: {output_file}", file=sys.stderr)
if __name__ == "__main__":
main()