|
|
import ast
|
|
|
|
|
|
import pandas as pd
|
|
|
|
|
|
import streamlit as st
|
|
|
|
|
|
FILE_MAP = {
|
|
|
"Tag Scores": "data/tag_summary.csv",
|
|
|
"Context Level Scores": "data/context_summary.csv"
|
|
|
}
|
|
|
|
|
|
|
|
|
def render_mi_table(df, level0_cols):
|
|
|
|
|
|
table_style = """
|
|
|
<style>
|
|
|
table {
|
|
|
width: 100%;
|
|
|
border-collapse: collapse;
|
|
|
}
|
|
|
th, td {
|
|
|
border: 1px solid black;
|
|
|
text-align: center;
|
|
|
padding: 8px;
|
|
|
}
|
|
|
th {
|
|
|
background-color: #262730;
|
|
|
}
|
|
|
</style>
|
|
|
"""
|
|
|
|
|
|
|
|
|
header_html = "<tr>"
|
|
|
for col in level0_cols:
|
|
|
colspan = len(df.xs(col, axis=1, level=0).columns) if col else 1
|
|
|
header_html += f'<th colspan="{colspan}" style="text-align: center;">{col if col else ""}</th>'
|
|
|
header_html += "</tr>"
|
|
|
|
|
|
|
|
|
sub_header_html = "<tr>"
|
|
|
for col in df.columns:
|
|
|
sub_header_html += f"<th style='text-align: center;'>{col[1] if len(col) > 1 else col[0]}</th>"
|
|
|
sub_header_html += "</tr>"
|
|
|
|
|
|
|
|
|
def map_val(value):
|
|
|
try:
|
|
|
value = f"{float(value):.1f}"
|
|
|
except:
|
|
|
value = value
|
|
|
return value
|
|
|
|
|
|
rows_html = ""
|
|
|
for _, row in df.iterrows():
|
|
|
|
|
|
rows_html += "<tr>" + "".join(f"<td>{map_val(value)}</td>" for value in row) + "</tr>"
|
|
|
|
|
|
|
|
|
table_html = f"""
|
|
|
{table_style}
|
|
|
<table>
|
|
|
{header_html}
|
|
|
{sub_header_html}
|
|
|
{rows_html}
|
|
|
</table>
|
|
|
"""
|
|
|
return table_html
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
st.title("Interface")
|
|
|
|
|
|
selected = st.selectbox("Select a results data:", list(FILE_MAP.keys()))
|
|
|
df = pd.read_csv(FILE_MAP[selected])
|
|
|
df.columns = pd.MultiIndex.from_tuples([ast.literal_eval(col) for col in df.columns])
|
|
|
level0_cols = []
|
|
|
for col in df.columns:
|
|
|
if col[0] not in level0_cols:
|
|
|
level0_cols.append(col[0])
|
|
|
|
|
|
st.markdown(render_mi_table(df, level0_cols), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main()
|
|
|
|