Spaces:
Running
Running
devjas1
commited on
Commit
·
345529d
1
Parent(s):
503f867
FEAT(analyzer): Add method to retrieve spectrum data for selected file; enhance visual diagnostics rendering
Browse files- modules/analyzer.py +1 -3
- utils/results_manager.py +27 -0
modules/analyzer.py
CHANGED
@@ -349,9 +349,7 @@ class BatchAnalysis:
|
|
349 |
|
350 |
# Only render if a file has been selected in the current session
|
351 |
if selected_file:
|
352 |
-
with st.expander(
|
353 |
-
f"🔬 View Spectrum for: **{selected_file}**", expanded=True
|
354 |
-
):
|
355 |
# Retrieve the full, detailed record for the selected file
|
356 |
spectrum_data = ResultsManager.get_spectrum_data_for_file(selected_file)
|
357 |
|
|
|
349 |
|
350 |
# Only render if a file has been selected in the current session
|
351 |
if selected_file:
|
352 |
+
with st.expander(f"View Spectrum for: **{selected_file}**", expanded=True):
|
|
|
|
|
353 |
# Retrieve the full, detailed record for the selected file
|
354 |
spectrum_data = ResultsManager.get_spectrum_data_for_file(selected_file)
|
355 |
|
utils/results_manager.py
CHANGED
@@ -6,6 +6,7 @@ import pandas as pd
|
|
6 |
import json
|
7 |
from datetime import datetime
|
8 |
from typing import Dict, List, Any, Optional
|
|
|
9 |
from pathlib import Path
|
10 |
import io
|
11 |
|
@@ -72,6 +73,32 @@ class ResultsManager:
|
|
72 |
"""Clear all stored results"""
|
73 |
st.session_state[ResultsManager.RESULTS_KEY] = []
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
@staticmethod
|
76 |
def get_results_dataframe() -> pd.DataFrame:
|
77 |
"""Convert results to pandas DataFrame for display and export"""
|
|
|
6 |
import json
|
7 |
from datetime import datetime
|
8 |
from typing import Dict, List, Any, Optional
|
9 |
+
import numpy as np
|
10 |
from pathlib import Path
|
11 |
import io
|
12 |
|
|
|
73 |
"""Clear all stored results"""
|
74 |
st.session_state[ResultsManager.RESULTS_KEY] = []
|
75 |
|
76 |
+
@staticmethod
|
77 |
+
def get_spectrum_data_for_file(filename: str) -> Optional[Dict[str, np.ndarray]]:
|
78 |
+
"""
|
79 |
+
Retrieves raw and resampled spectrum data for a given filename.
|
80 |
+
Returns None if no data is found for the filename or if data is incomplete.
|
81 |
+
"""
|
82 |
+
results = ResultsManager.get_results()
|
83 |
+
for r in results:
|
84 |
+
if r["filename"] == filename:
|
85 |
+
# Ensure all required keys are present and not None
|
86 |
+
if all(
|
87 |
+
r.get(k) is not None
|
88 |
+
for k in ["x_raw", "y_raw", "x_resampled", "y_resampled"]
|
89 |
+
):
|
90 |
+
return {
|
91 |
+
"x_raw": r["x_raw"],
|
92 |
+
"y_raw": r["y_raw"],
|
93 |
+
"x_resampled": r["x_resampled"],
|
94 |
+
"y_resampled": r["y_resampled"],
|
95 |
+
}
|
96 |
+
else:
|
97 |
+
# If the metadata exists but spectrum data is missing for this entry,
|
98 |
+
# it means it was processed before we started storing spectrums.
|
99 |
+
return None
|
100 |
+
return None # Return None if filename not found
|
101 |
+
|
102 |
@staticmethod
|
103 |
def get_results_dataframe() -> pd.DataFrame:
|
104 |
"""Convert results to pandas DataFrame for display and export"""
|