feat: Add CSV report viewing functionality to technical scanner page
This commit is contained in:
parent
e001d2e766
commit
099c8b353e
@ -18,6 +18,30 @@ def init_session_state():
|
|||||||
if 'page' not in st.session_state:
|
if 'page' not in st.session_state:
|
||||||
st.session_state.page = 'Trading Journal'
|
st.session_state.page = 'Trading Journal'
|
||||||
|
|
||||||
|
def load_scanner_reports():
|
||||||
|
"""Load and return available scanner reports"""
|
||||||
|
import os
|
||||||
|
import pandas as pd
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
reports = []
|
||||||
|
reports_dir = "scanner_results"
|
||||||
|
|
||||||
|
if os.path.exists(reports_dir):
|
||||||
|
for file in os.listdir(reports_dir):
|
||||||
|
if file.endswith(".csv"):
|
||||||
|
file_path = os.path.join(reports_dir, file)
|
||||||
|
# Get file creation time
|
||||||
|
created = datetime.fromtimestamp(os.path.getctime(file_path))
|
||||||
|
reports.append({
|
||||||
|
'name': file,
|
||||||
|
'path': file_path,
|
||||||
|
'created': created
|
||||||
|
})
|
||||||
|
|
||||||
|
# Sort by creation time, newest first
|
||||||
|
return sorted(reports, key=lambda x: x['created'], reverse=True)
|
||||||
|
|
||||||
def format_datetime(dt):
|
def format_datetime(dt):
|
||||||
"""Format datetime for display"""
|
"""Format datetime for display"""
|
||||||
if dt:
|
if dt:
|
||||||
@ -269,6 +293,10 @@ def trading_journal_page():
|
|||||||
def technical_scanner_page():
|
def technical_scanner_page():
|
||||||
st.header("Technical Scanner")
|
st.header("Technical Scanner")
|
||||||
|
|
||||||
|
# Create tabs for scanner and reports
|
||||||
|
scanner_tab, reports_tab = st.tabs(["Run Scanner", "View Reports"])
|
||||||
|
|
||||||
|
with scanner_tab:
|
||||||
scanner_type = st.selectbox(
|
scanner_type = st.selectbox(
|
||||||
"Select Scanner",
|
"Select Scanner",
|
||||||
["SunnyBands", "ATR-EMA", "ATR-EMA v2"]
|
["SunnyBands", "ATR-EMA", "ATR-EMA v2"]
|
||||||
@ -305,6 +333,39 @@ def technical_scanner_page():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error running scanner: {str(e)}")
|
st.error(f"Error running scanner: {str(e)}")
|
||||||
|
|
||||||
|
with reports_tab:
|
||||||
|
st.subheader("Scanner Reports")
|
||||||
|
|
||||||
|
reports = load_scanner_reports()
|
||||||
|
if reports:
|
||||||
|
# Create a selectbox to choose the report
|
||||||
|
selected_report = st.selectbox(
|
||||||
|
"Select Report",
|
||||||
|
options=reports,
|
||||||
|
format_func=lambda x: f"{x['name']} ({x['created'].strftime('%Y-%m-%d %H:%M')})"
|
||||||
|
)
|
||||||
|
|
||||||
|
if selected_report:
|
||||||
|
try:
|
||||||
|
# Load and display the CSV
|
||||||
|
df = pd.read_csv(selected_report['path'])
|
||||||
|
|
||||||
|
# Add download button
|
||||||
|
st.download_button(
|
||||||
|
label="Download Report",
|
||||||
|
data=df.to_csv(index=False),
|
||||||
|
file_name=selected_report['name'],
|
||||||
|
mime='text/csv'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Display the dataframe
|
||||||
|
st.dataframe(df)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
st.error(f"Error loading report: {str(e)}")
|
||||||
|
else:
|
||||||
|
st.info("No scanner reports found")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
st.set_page_config(page_title="Trading System", layout="wide")
|
st.set_page_config(page_title="Trading System", layout="wide")
|
||||||
init_session_state()
|
init_session_state()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user