Skip to content

Commit 11fac08

Browse files
committed
fix: serialize_fft_result handle dict format from optimized analyzers
1 parent 3a6992e commit 11fac08

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎smarttune/services/serialize.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,36 @@ def serialize_pid_result(
171171

172172

173173
def serialize_fft_result(
174-
result: FFTAnalysisResult,
174+
result,
175175
adapter: Optional[PlatformAdapter] = None,
176176
max_recommendations: int = 20,
177177
) -> Dict[str, Any]:
178178
"""Serialize FFT analysis result (no raw spectrum data)."""
179+
# Handle both dataclass (old) and dict (new optimized) formats
180+
if isinstance(result, dict):
181+
# Dict format from optimized analyzers
182+
peaks_raw = result.get("peaks", [])
183+
peaks = [
184+
{
185+
"frequency_hz": _safe_float(p.get("freq", p.get("frequency_hz", 0))),
186+
"amplitude": _safe_float(p.get("power_db", p.get("amplitude", 0))),
187+
"source_guess": p.get("source", p.get("source_guess", "")),
188+
}
189+
for p in peaks_raw[:20]
190+
]
191+
recs_raw = result.get("recommendations", [])
192+
recs = [
193+
serialize_param_recommendation(r, adapter)
194+
for r in recs_raw[:max_recommendations]
195+
] if isinstance(recs_raw, list) else []
196+
return {
197+
"vibration_level": result.get("vibration_level", ""),
198+
"noise_floor": _safe_float(result.get("noise_floor", 0)),
199+
"peaks": peaks,
200+
"recommendations": recs,
201+
}
202+
203+
# Dataclass format (original)
179204
peaks = [
180205
{
181206
"frequency_hz": _safe_float(p.frequency_hz),

0 commit comments

Comments
 (0)