84 lines
3.7 KiB
Python
84 lines
3.7 KiB
Python
"""One pass over a finished tester run: log counts, report headline, journal rows."""
|
|
import collections
|
|
import glob
|
|
import html
|
|
import os
|
|
import re
|
|
import sqlite3
|
|
import sys
|
|
|
|
STAMP = sys.argv[1] if len(sys.argv) > 1 else '12:07'
|
|
REPORT = sys.argv[2] if len(sys.argv) > 2 else 'WarriorIBG_SP500_2022'
|
|
TERM = r'C:\Users\admin\AppData\Roaming\MetaQuotes\Terminal\10CE948A1DFC9A8C27E56E827008EBD4'
|
|
TESTER = r'C:\Users\admin\AppData\Roaming\MetaQuotes\Tester\10CE948A1DFC9A8C27E56E827008EBD4'
|
|
COMMON = r'C:\Users\admin\AppData\Roaming\MetaQuotes\Terminal\Common\Files\Warrior_EA'
|
|
|
|
# --- the agent log that carries this build's run
|
|
seg = None
|
|
for p in glob.glob(os.path.join(TESTER, 'Agent-*', 'logs', '20260906.log')):
|
|
t = open(p, 'rb').read().decode('utf-16', 'ignore').split('\n')
|
|
idx = [k for k, l in enumerate(t) if 'COMPILED 2026.09.06 ' + STAMP in l]
|
|
if idx:
|
|
seg = t[idx[-1]:]
|
|
print('agent log:', p, 'lines', len(seg))
|
|
break
|
|
if seg is None:
|
|
print('no agent log carries build', STAMP)
|
|
sys.exit(1)
|
|
c = collections.Counter()
|
|
keys = {'fired': 'gap-up fired', 'nn_declined': 'DECLINED by the network', 'shaped': 'order shaped by setup',
|
|
'buy_stop_sent': 'buy stop', 'deals': 'deal #', 'buys': ' buy ', 'time_stops': 'time stop -',
|
|
'refused': 'REFUSED', 'withheld': 'withheld', 'lot_reject': 'invalid computed lot',
|
|
'no_history': 'not enough history', 'expired': 'expired', 'thread_finished': 'thread finished'}
|
|
for l in seg:
|
|
for k, pat in keys.items():
|
|
if pat in l and 'ChartSaveTemplate' not in l:
|
|
if k == 'buys' and 'deal #' not in l:
|
|
continue
|
|
c[k] += 1
|
|
print('counts:', dict(c))
|
|
shown = 0
|
|
for l in seg:
|
|
if ('order shaped by setup' in l or 'buy stop' in l and ('Trade\t' in l or 'OrderSend' in l)
|
|
or 'time stop -' in l or 'deal #' in l):
|
|
print(' ' + l.replace('CS\t0\t', '')[:210])
|
|
shown += 1
|
|
if shown >= 14:
|
|
break
|
|
# --- the report
|
|
rep = os.path.join(TERM, REPORT + '.htm')
|
|
if os.path.exists(rep):
|
|
raw = open(rep, 'rb').read()
|
|
try:
|
|
tx = raw.decode('utf-16')
|
|
except Exception:
|
|
tx = raw.decode('utf-8', 'ignore')
|
|
tx = re.sub(r'<[^>]+>', ' ', tx)
|
|
tx = html.unescape(tx)
|
|
tx = re.sub(r'\s+', ' ', tx)
|
|
print('report:', rep)
|
|
for k in ['Initial Deposit', 'Total Net Profit', 'Profit Factor', 'Expected Payoff', 'Total Trades',
|
|
'Profit Trades', 'Loss Trades', 'Balance Drawdown Maximal', 'Equity Drawdown Maximal',
|
|
'Largest profit trade', 'Largest loss trade', 'Sharpe Ratio', 'Recovery Factor']:
|
|
i = tx.find(k)
|
|
if i >= 0:
|
|
print(' ' + tx[i:i + 70])
|
|
else:
|
|
print('no report at', rep)
|
|
# --- the journal rows this run wrote
|
|
dbs = sorted(glob.glob(os.path.join(COMMON, 'Databases', 'Signals', 'SP500_16385_*.db')),
|
|
key=os.path.getmtime)
|
|
for db in dbs[-2:]:
|
|
con = sqlite3.connect(db)
|
|
try:
|
|
cols = [r[1] for r in con.execute('PRAGMA table_info(TradeJournal)')]
|
|
n = con.execute('SELECT COUNT(*) FROM TradeJournal').fetchone()[0]
|
|
nctx = con.execute("SELECT COUNT(*) FROM TradeJournal WHERE context IS NOT NULL AND context <> ''").fetchone()[0] if 'context' in cols else -1
|
|
print(f'journal {os.path.basename(db)}: {n} rows, {nctx} with context; has context={("context" in cols)} passages={("passages" in cols)}')
|
|
if nctx > 0:
|
|
for r in con.execute("SELECT context, passages FROM TradeJournal WHERE context <> '' ORDER BY rowid DESC LIMIT 2"):
|
|
print(' ctx:', r[0][:230])
|
|
print(' pas:', (r[1] or '')[:160])
|
|
except Exception as e:
|
|
print('journal', db, 'error', e)
|
|
con.close()
|