Add project files: decks, scripts, and collection data
This commit is contained in:
72
scripts/deck_report.py
Normal file
72
scripts/deck_report.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate a deck upgrade report comparing collection to existing decks.
|
||||
Usage:
|
||||
python deck_report.py --collection collection_hydrated/deck.json --decks-dir decks/ --output report.md
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def load_collection(path: str) -> dict:
|
||||
with open(path, 'r') as f:
|
||||
cards = json.load(f)
|
||||
return {c['name']: c for c in cards}
|
||||
|
||||
|
||||
def load_deck(path: str) -> dict:
|
||||
with open(path, 'r') as f:
|
||||
data = json.load(f)
|
||||
if 'cards' in data:
|
||||
return data
|
||||
return {'cards': data, 'name': Path(path).stem}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Generate deck upgrade report')
|
||||
parser.add_argument('--collection', '-c', required=True)
|
||||
parser.add_argument('--decks-dir', '-d', required=True)
|
||||
parser.add_argument('--output', '-o', required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
collection = load_collection(args.collection)
|
||||
decks = []
|
||||
for path in Path(args.decks_dir).glob('*.json'):
|
||||
decks.append(load_deck(str(path)))
|
||||
|
||||
# Find all cards in decks
|
||||
all_deck_cards = set()
|
||||
for deck in decks:
|
||||
all_deck_cards.update(deck['cards'].keys())
|
||||
|
||||
available = set(collection.keys()) - all_deck_cards
|
||||
|
||||
report = []
|
||||
report.append("# Deck Upgrade Report\n")
|
||||
report.append(f"Collection size: {len(collection)} cards")
|
||||
report.append(f"Cards in decks: {len(all_deck_cards)}")
|
||||
report.append(f"Available for upgrades: {len(available)}\n")
|
||||
|
||||
for deck in decks:
|
||||
deck_name = deck.get('name', 'Unknown')
|
||||
deck_cards = deck['cards']
|
||||
deck_colors = set()
|
||||
for name in deck_cards:
|
||||
card = collection.get(name, {})
|
||||
ci = card.get('color_identity', [])
|
||||
deck_colors.update(ci)
|
||||
|
||||
report.append(f"\n---\n## {deck_name}\n")
|
||||
report.append(f"**Colors:** {''.join(sorted(deck_colors))}")
|
||||
report.append(f"**Total cards:** {sum(deck_cards.values())}")
|
||||
report.append(f"**Unique cards:** {len(deck_cards)}\n")
|
||||
|
||||
with open(args.output, 'w') as f:
|
||||
f.write('\n'.join(report))
|
||||
print(f"Report saved to {args.output}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user