64 lines
3.5 KiB
Python
64 lines
3.5 KiB
Python
import re
|
|
|
|
path = 'templates/backtest.html'
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
html = f.read()
|
|
|
|
prefixes = ['bt', 'tl', 'bo', 'mom', 'usmom']
|
|
|
|
for prefix in prefixes:
|
|
# 1. find the eod_enabled div
|
|
regex_enabled = re.compile(
|
|
r'(\s*<div class="col-auto d-flex align-items-end">\s*<div class="form-check mb-2">\s*<input class="form-check-input" type="checkbox" id="' + prefix + r'_eod_enabled"[^>]*>\s*<label[^>]*>EOD청산</label>\s*</div>\s*</div>)',
|
|
re.DOTALL
|
|
)
|
|
# 2. find the eod_hm div
|
|
regex_hm = re.compile(
|
|
r'(\s*<div class="col-auto">\s*<label[^>]*>EOD시각.*?</label>\s*<input type="text" class="form-control" id="' + prefix + r'_eod_hm"[^>]*>\s*</div>)',
|
|
re.DOTALL
|
|
)
|
|
# fallback for bt_eod_hm which uses col-4 col-md-1
|
|
regex_hm2 = re.compile(
|
|
r'(\s*<div class="col-4 col-md-1">\s*<label[^>]*>EOD시각.*?</label>\s*<input type="text" class="form-control" id="' + prefix + r'_eod_hm"[^>]*>\s*</div>)',
|
|
re.DOTALL
|
|
)
|
|
|
|
enabled_match = regex_enabled.search(html)
|
|
hm_match = regex_hm.search(html) or regex_hm2.search(html)
|
|
|
|
if not enabled_match or not hm_match:
|
|
print(f"Failed to match {prefix}")
|
|
continue
|
|
|
|
enabled_str = enabled_match.group(1)
|
|
hm_str = hm_match.group(1)
|
|
|
|
# Remove from html
|
|
html = html.replace(enabled_str, '')
|
|
html = html.replace(hm_str, '')
|
|
|
|
# We want to insert the new EOD block after the closing </div> of the row.
|
|
# To do this robustly, we will insert it right before the next "<!-- TRIGGER" or "<div class=\"row"
|
|
# But wait, it's easier to just find the exact text where we want to insert.
|
|
# Let's just find the next </div>\s*<!-- TRIGGER for bt, tl, bo.
|
|
|
|
new_block = f"""
|
|
<div class="row g-2 align-items-center mt-2 p-2 rounded" style="background:#161b22;border:1px solid #30363d">
|
|
<div class="col-12"><span class="text-muted" style="font-size:11px"><b style="color:#79c0ff">EOD 장마감 청산</b></span></div>{enabled_str}{hm_str}
|
|
</div>"""
|
|
|
|
if prefix == 'bt':
|
|
html = html.replace('<!-- TRIGGER (SCAN vs TRIGGER — tail·모멘텀 탭과 동일 패턴) -->', new_block + '\n <!-- TRIGGER (SCAN vs TRIGGER — tail·모멘텀 탭과 동일 패턴) -->')
|
|
elif prefix == 'tl':
|
|
html = html.replace('<!-- TRIGGER 플래그 (SCAN vs TRIGGER — 실매·백테·저장 동일) -->', new_block + '\n <!-- TRIGGER 플래그 (SCAN vs TRIGGER — 실매·백테·저장 동일) -->')
|
|
elif prefix == 'bo':
|
|
html = html.replace('<!-- TRIGGER 필터 (모멘텀·스캘핑과 유사) -->', new_block + '\n <!-- TRIGGER 필터 (모멘텀·스캘핑과 유사) -->')
|
|
elif prefix == 'mom':
|
|
html = html.replace(' <div class="row g-2 align-items-end mt-1">\n <div class="col-12 col-md-2">\n <label class="form-label param-row" title="OFF면 진입 방어', new_block + '\n <div class="row g-2 align-items-end mt-1">\n <div class="col-12 col-md-2">\n <label class="form-label param-row" title="OFF면 진입 방어')
|
|
elif prefix == 'usmom':
|
|
html = html.replace(' <div class="row g-2 align-items-end mt-1">\n <div class="col-12 col-md-2">\n <label class="form-label param-row">방어로직', new_block + '\n <div class="row g-2 align-items-end mt-1">\n <div class="col-12 col-md-2">\n <label class="form-label param-row">방어로직')
|
|
|
|
with open(path, 'w', encoding='utf-8') as f:
|
|
f.write(html)
|
|
print("refactored")
|