Update page_files/Categorized_Search.py
Browse files- page_files/Categorized_Search.py +127 -31
page_files/Categorized_Search.py
CHANGED
|
@@ -6,6 +6,8 @@ import pandas as pd
|
|
| 6 |
import streamlit as st
|
| 7 |
from PIL import Image
|
| 8 |
|
|
|
|
|
|
|
| 9 |
from data_loader import get_all_sections, load_material_data
|
| 10 |
import streamlit.components.v1 as components
|
| 11 |
def clear_search():
|
|
@@ -429,6 +431,7 @@ defaults = {
|
|
| 429 |
"inspect_section": None,
|
| 430 |
"inspect_property": None,
|
| 431 |
"_reset_prop_checks": False,
|
|
|
|
| 432 |
}
|
| 433 |
|
| 434 |
for key, value in defaults.items():
|
|
@@ -749,6 +752,15 @@ with right_col:
|
|
| 749 |
"Fibers": "🟠 FIBER",
|
| 750 |
}
|
| 751 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
if not page_meta.empty:
|
| 753 |
table_df = page_meta.copy()
|
| 754 |
|
|
@@ -942,6 +954,88 @@ with right_col:
|
|
| 942 |
)
|
| 943 |
st.session_state.inspect_section = section_choice
|
| 944 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 945 |
properties_df = (
|
| 946 |
material_df[material_df["section"] == section_choice][
|
| 947 |
["property_name", "section"]
|
|
@@ -949,39 +1043,35 @@ with right_col:
|
|
| 949 |
.drop_duplicates()
|
| 950 |
.reset_index(drop=True)
|
| 951 |
)
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 957 |
)
|
| 958 |
-
st.markdown(f"""
|
| 959 |
-
<div style='border:1px solid #edf2f7;border-radius:8px;overflow:hidden;max-height:240px;overflow-y:auto;'>
|
| 960 |
-
<table style='width:100%;border-collapse:collapse;'>
|
| 961 |
-
<thead>
|
| 962 |
-
<tr style='background:#f8fafc;'>
|
| 963 |
-
<th style='padding:8px 12px;font-size:0.64rem;font-weight:700;letter-spacing:1px;color:#94a3b8;text-align:left;border-bottom:1px solid #edf2f7;'>PROPERTY NAME</th>
|
| 964 |
-
<th style='padding:8px 12px;font-size:0.64rem;font-weight:700;letter-spacing:1px;color:#94a3b8;text-align:left;border-bottom:1px solid #edf2f7;'>SECTION</th>
|
| 965 |
-
</tr>
|
| 966 |
-
</thead>
|
| 967 |
-
<tbody>{rows_html}</tbody>
|
| 968 |
-
</table>
|
| 969 |
-
</div>
|
| 970 |
-
""", unsafe_allow_html=True)
|
| 971 |
-
property_options = properties_df["property_name"].dropna().tolist()
|
| 972 |
-
if property_options:
|
| 973 |
-
if st.session_state.inspect_property not in property_options:
|
| 974 |
-
st.session_state.inspect_property = property_options[0]
|
| 975 |
-
|
| 976 |
-
property_choice = st.selectbox(
|
| 977 |
-
"Property",
|
| 978 |
-
property_options,
|
| 979 |
-
index=property_options.index(st.session_state.inspect_property),
|
| 980 |
-
key="inspect_property_select",
|
| 981 |
-
)
|
| 982 |
-
st.session_state.inspect_property = property_choice
|
| 983 |
|
| 984 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 985 |
result = all_data[
|
| 986 |
(all_data["material_abbreviation"] == selected_abbr)
|
| 987 |
& (all_data["property_name"] == property_choice)
|
|
@@ -1002,6 +1092,12 @@ with right_col:
|
|
| 1002 |
else:
|
| 1003 |
st.caption("No plot image available for this material-property pair.")
|
| 1004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
+
from streamlit_scroll_to_top import scroll_to_here
|
| 10 |
+
|
| 11 |
from data_loader import get_all_sections, load_material_data
|
| 12 |
import streamlit.components.v1 as components
|
| 13 |
def clear_search():
|
|
|
|
| 431 |
"inspect_section": None,
|
| 432 |
"inspect_property": None,
|
| 433 |
"_reset_prop_checks": False,
|
| 434 |
+
"_scroll_to_results": False,
|
| 435 |
}
|
| 436 |
|
| 437 |
for key, value in defaults.items():
|
|
|
|
| 752 |
"Fibers": "🟠 FIBER",
|
| 753 |
}
|
| 754 |
|
| 755 |
+
matrix_fiber_filtered = (
|
| 756 |
+
"Composites" in st.session_state.active_classes
|
| 757 |
+
and (st.session_state.selected_matrix != "All" or st.session_state.selected_fiber != "All")
|
| 758 |
+
)
|
| 759 |
+
|
| 760 |
+
if page_meta.empty and matrix_fiber_filtered:
|
| 761 |
+
st.info("There's no such material with this combination of Matrix and Fiber.")
|
| 762 |
+
|
| 763 |
+
|
| 764 |
if not page_meta.empty:
|
| 765 |
table_df = page_meta.copy()
|
| 766 |
|
|
|
|
| 954 |
)
|
| 955 |
st.session_state.inspect_section = section_choice
|
| 956 |
|
| 957 |
+
# properties_df = (
|
| 958 |
+
# material_df[material_df["section"] == section_choice][
|
| 959 |
+
# ["property_name", "section"]
|
| 960 |
+
# ]
|
| 961 |
+
# .drop_duplicates()
|
| 962 |
+
# .reset_index(drop=True)
|
| 963 |
+
# )
|
| 964 |
+
# #st.dataframe(properties_df, use_container_width=True, hide_index=True, height=240)
|
| 965 |
+
# rows_html = "".join(
|
| 966 |
+
# f"<tr><td style='padding:8px 12px;font-size:0.82rem;color:#111827;border-bottom:1px solid #f8fafc;'>{row['property_name']}</td>"
|
| 967 |
+
# f"<td style='padding:8px 12px;font-size:0.82rem;color:#64748b;border-bottom:1px solid #f8fafc;'>{row['section']}</td></tr>"
|
| 968 |
+
# for _, row in properties_df.iterrows()
|
| 969 |
+
# )
|
| 970 |
+
# st.markdown(f"""
|
| 971 |
+
# <div style='border:1px solid #edf2f7;border-radius:8px;overflow:hidden;max-height:240px;overflow-y:auto;'>
|
| 972 |
+
# <table style='width:100%;border-collapse:collapse;'>
|
| 973 |
+
# <thead>
|
| 974 |
+
# <tr style='background:#f8fafc;'>
|
| 975 |
+
# <th style='padding:8px 12px;font-size:0.64rem;font-weight:700;letter-spacing:1px;color:#94a3b8;text-align:left;border-bottom:1px solid #edf2f7;'>PROPERTY NAME</th>
|
| 976 |
+
# <th style='padding:8px 12px;font-size:0.64rem;font-weight:700;letter-spacing:1px;color:#94a3b8;text-align:left;border-bottom:1px solid #edf2f7;'>SECTION</th>
|
| 977 |
+
# </tr>
|
| 978 |
+
# </thead>
|
| 979 |
+
# <tbody>{rows_html}</tbody>
|
| 980 |
+
# </table>
|
| 981 |
+
# </div>
|
| 982 |
+
# """, unsafe_allow_html=True)
|
| 983 |
+
# property_options = properties_df["property_name"].dropna().tolist()
|
| 984 |
+
# if property_options:
|
| 985 |
+
# if st.session_state.inspect_property not in property_options:
|
| 986 |
+
# st.session_state.inspect_property = property_options[0]
|
| 987 |
+
|
| 988 |
+
# property_choice = st.selectbox(
|
| 989 |
+
# "Property",
|
| 990 |
+
# property_options,
|
| 991 |
+
# index=property_options.index(st.session_state.inspect_property),
|
| 992 |
+
# key="inspect_property_select",
|
| 993 |
+
# )
|
| 994 |
+
# st.session_state.inspect_property = property_choice
|
| 995 |
+
|
| 996 |
+
# # if st.button("Display", key="inspect_search", type="primary"):
|
| 997 |
+
# # result = all_data[
|
| 998 |
+
# # (all_data["material_abbreviation"] == selected_abbr)
|
| 999 |
+
# # & (all_data["property_name"] == property_choice)
|
| 1000 |
+
# # & (all_data["value"].notna())
|
| 1001 |
+
# # ]
|
| 1002 |
+
|
| 1003 |
+
# # if result.empty:
|
| 1004 |
+
# # st.warning("No data found for this material-property combination")
|
| 1005 |
+
# # else:
|
| 1006 |
+
# # st.subheader("Property Data")
|
| 1007 |
+
# # st.dataframe(result.T, use_container_width=True)
|
| 1008 |
+
|
| 1009 |
+
# # st.subheader("Property Graph")
|
| 1010 |
+
# # image_path = Path("images") / f"{selected_abbr}_{property_choice}.png"
|
| 1011 |
+
# # if image_path.exists():
|
| 1012 |
+
# # image = Image.open(image_path)
|
| 1013 |
+
# # st.image(image, use_container_width=True, caption="Stress strain curve")
|
| 1014 |
+
# # else:
|
| 1015 |
+
# # st.caption("No plot image available for this material-property pair.")
|
| 1016 |
+
|
| 1017 |
+
# if st.button("Display", key="inspect_search", type="primary"):
|
| 1018 |
+
# result = all_data[
|
| 1019 |
+
# (all_data["material_abbreviation"] == selected_abbr)
|
| 1020 |
+
# & (all_data["property_name"] == property_choice)
|
| 1021 |
+
# & (all_data["value"].notna())
|
| 1022 |
+
# ]
|
| 1023 |
+
|
| 1024 |
+
# if result.empty:
|
| 1025 |
+
# st.warning("No data found for this material-property combination")
|
| 1026 |
+
# else:
|
| 1027 |
+
# st.subheader("Property Data")
|
| 1028 |
+
# st.dataframe(result.T, use_container_width=True)
|
| 1029 |
+
|
| 1030 |
+
# st.subheader("Property Graph")
|
| 1031 |
+
# image_path = Path("images") / f"{selected_abbr}_{property_choice}.png"
|
| 1032 |
+
# if image_path.exists():
|
| 1033 |
+
# image = Image.open(image_path)
|
| 1034 |
+
# st.image(image, use_container_width=True, caption="Stress strain curve")
|
| 1035 |
+
# else:
|
| 1036 |
+
# st.caption("No plot image available for this material-property pair.")
|
| 1037 |
+
|
| 1038 |
+
# st.session_state._scroll_to_results = True
|
| 1039 |
properties_df = (
|
| 1040 |
material_df[material_df["section"] == section_choice][
|
| 1041 |
["property_name", "section"]
|
|
|
|
| 1043 |
.drop_duplicates()
|
| 1044 |
.reset_index(drop=True)
|
| 1045 |
)
|
| 1046 |
+
|
| 1047 |
+
property_event = st.dataframe(
|
| 1048 |
+
properties_df,
|
| 1049 |
+
use_container_width=True,
|
| 1050 |
+
hide_index=True,
|
| 1051 |
+
height=240,
|
| 1052 |
+
on_select="rerun",
|
| 1053 |
+
selection_mode="single-row",
|
| 1054 |
+
key="inspect_properties_table",
|
| 1055 |
+
column_config={
|
| 1056 |
+
"property_name": st.column_config.TextColumn("PROPERTY NAME"),
|
| 1057 |
+
"section": st.column_config.TextColumn("SECTION"),
|
| 1058 |
+
},
|
| 1059 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1060 |
|
| 1061 |
+
selected_indices = property_event.selection.rows if property_event and property_event.selection else []
|
| 1062 |
+
|
| 1063 |
+
if selected_indices:
|
| 1064 |
+
property_choice = properties_df.iloc[selected_indices[0]]["property_name"]
|
| 1065 |
+
st.session_state.inspect_property = property_choice
|
| 1066 |
+
elif st.session_state.inspect_property in properties_df["property_name"].tolist():
|
| 1067 |
+
property_choice = st.session_state.inspect_property
|
| 1068 |
+
else:
|
| 1069 |
+
property_choice = None
|
| 1070 |
+
|
| 1071 |
+
if st.button("Display", key="inspect_search", type="primary"):
|
| 1072 |
+
if not property_choice:
|
| 1073 |
+
st.warning("Please select a property from the property table!")
|
| 1074 |
+
else:
|
| 1075 |
result = all_data[
|
| 1076 |
(all_data["material_abbreviation"] == selected_abbr)
|
| 1077 |
& (all_data["property_name"] == property_choice)
|
|
|
|
| 1092 |
else:
|
| 1093 |
st.caption("No plot image available for this material-property pair.")
|
| 1094 |
|
| 1095 |
+
st.session_state._scroll_to_results = True
|
| 1096 |
+
|
| 1097 |
+
if st.session_state._scroll_to_results:
|
| 1098 |
+
scroll_to_here(0, key="inspect_results_scroll")
|
| 1099 |
+
st.session_state._scroll_to_results = False
|
| 1100 |
+
|
| 1101 |
|
| 1102 |
|
| 1103 |
|