41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""分析京东账单数据"""
|
|
import json
|
|
import sys
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
with open('../jd_bills.json', 'r', encoding='utf-8') as f:
|
|
d = json.load(f)
|
|
|
|
bills = [b for b in d['data']['bills'] if b['bill_type'] == 'jd']
|
|
print(f'Total JD bills: {len(bills)}')
|
|
print()
|
|
|
|
# Review level distribution
|
|
review_levels = {}
|
|
for b in bills:
|
|
lvl = b['review_level'] or 'NONE'
|
|
review_levels[lvl] = review_levels.get(lvl, 0) + 1
|
|
print('Review level distribution:')
|
|
for lvl, cnt in sorted(review_levels.items()):
|
|
print(f' {lvl}: {cnt}')
|
|
print()
|
|
|
|
# Category distribution
|
|
categories = {}
|
|
for b in bills:
|
|
cat = b['category']
|
|
categories[cat] = categories.get(cat, 0) + 1
|
|
print('Category distribution:')
|
|
for cat, cnt in sorted(categories.items(), key=lambda x: -x[1]):
|
|
print(f' {cat}: {cnt}')
|
|
print()
|
|
|
|
# Show bills that need review
|
|
print('Bills needing review:')
|
|
print(f"{'Level':<5} | {'Category':<12} | {'Merchant':<20} | Description")
|
|
print('-' * 70)
|
|
for b in bills:
|
|
if b['review_level']:
|
|
print(f"{b['review_level']:<5} | {b['category']:<12} | {b['merchant'][:20]:<20} | {b['description'][:30]}")
|