import json
with open(r'j:\Softwareprojekte\PolytraderSharp\PolyTraderSharp\bin\Debug\net8.0-windows7.0\PolyTraderDB\closed_trades.json', 'r', encoding='utf-8') as f:
    trades = [json.loads(line) for line in f]

wins = sum(1 for t in trades if t.get('RealizedPnl', 0) > 0)
losses = sum(1 for t in trades if t.get('RealizedPnl', 0) < 0)
pnl = sum(t.get('RealizedPnl', 0) for t in trades)

print(f'Total Trades: {len(trades)}')
print(f'Wins: {wins}, Losses: {losses}')
print(f'Total PnL: {pnl:.2f}')

reasons = {}
for t in trades:
    r = t.get('ExitReason', 'None')
    p = t.get('RealizedPnl', 0)
    if r not in reasons: reasons[r] = {'count': 0, 'pnl': 0}
    reasons[r]['count'] += 1
    reasons[r]['pnl'] += p

print('--- By Reason ---')
for r, d in reasons.items():
    print(r + ': ' + str(d['count']) + ' trades, PnL: ' + str(round(d['pnl'], 2)))
