import json import glob import sys files = sorted(glob.glob('/home/hoon/kis_bot/logs/optuna_web_jobs/import_optuna_scalp_*.json'), reverse=True)[:5] files += sorted(glob.glob('/home/hoon/kis_bot/kis_trader/backtest/results/optuna_scalp_tpe_*.json'), reverse=True)[:5] for fpath in files: try: with open(fpath) as f: data = json.load(f) # import 된 잡 (웹 UI 용) 일 경우: trials = data.get('trials', []) or data.get('optuna_trials', []) for tr in trials: # optuna_web_jobs/ 에 있는 json의 경우 tr 구조가 다름. (t, p, s, attrs) if 't' in tr: # trial number is 't' if tr.get('t') == 198 or tr.get('attrs', {}).get('trades') == 361: print(f"Found in {fpath}: Trial {tr.get('t')} with {tr.get('attrs', {}).get('trades')} trades") print(json.dumps(tr.get('p', {}), indent=2, ensure_ascii=False)) sys.exit(0) elif 'number' in tr: if tr.get('number') == 198 or tr.get('user_attrs', {}).get('trades') == 361: print(f"Found in {fpath}: Trial {tr.get('number')} with {tr.get('user_attrs', {}).get('trades')} trades") print(json.dumps(tr.get('params', {}), indent=2, ensure_ascii=False)) sys.exit(0) except Exception as e: pass print("Not found")