refactor: enhance Optuna backtesting framework, optimize orderbook filtering, and update database management utilities.
This commit is contained in:
28
scratch/refactor_html.py
Normal file
28
scratch/refactor_html.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import re
|
||||
|
||||
html_path = 'templates/backtest.html'
|
||||
with open(html_path, 'r', encoding='utf-8') as f:
|
||||
html = f.read()
|
||||
|
||||
# Pattern for EOD block
|
||||
# 1. <div class="col-auto d-flex align-items-end"> ... id="PREFIX_eod_enabled" ... </div>
|
||||
# 2. <div class="..."> ... id="PREFIX_eod_hm" ... </div>
|
||||
|
||||
regex = 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="([a-z]+)_eod_enabled"[^>]*>\s*<label[^>]*for="\2_eod_enabled"[^>]*>EOD청산</label>\s*</div>\s*</div>\s*<div class="[^"]*">\s*<label class="form-label param-row"[^>]*>EOD시각.*?</label>\s*<input type="text" class="form-control" id="\2_eod_hm"[^>]*>\s*</div>)',
|
||||
re.DOTALL
|
||||
)
|
||||
|
||||
def replacer(match):
|
||||
original_text = match.group(1)
|
||||
prefix = match.group(2)
|
||||
# We will remove it from its original place and append it after the row closes, but wait, the regex matches it exactly.
|
||||
# It's better to just return empty string, and insert the new block after the end of the current .row.
|
||||
# But wait, how do we insert it after the row?
|
||||
return f"<!-- EOD_BLOCK_{prefix} -->" + original_text
|
||||
|
||||
html = regex.sub(replacer, html)
|
||||
|
||||
with open(html_path, 'w', encoding='utf-8') as f:
|
||||
f.write(html)
|
||||
print("done")
|
||||
Reference in New Issue
Block a user