STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
results_csv.py
Go to the documentation of this file.
1"""Layer 2/3 optimizer results as the pressure-curve CSV the UI downloads.
2
3Used to be built in the browser (Layer2Optimization / Layer3Optimization
4``downloadCSV``), so nothing but an open tab could produce it. Now the backend
5writes it (GET /api/optimizer/layer{2,3}/results.csv) and the UI's button fetches
6that, so the file is the same whoever asks -- the design-tools MCP included.
7
8The format is unchanged: ``Time (s),LOX Pressure (Pa),Fuel Pressure (Pa)``, one
9row per time, numbers written the way JavaScript's ``String(n)`` writes them
10(``5`` not ``5.0``, stardesign.jsformat), since that is what the file has always held.
11"""
12
13from __future__ import annotations
14
15from typing import Any, Iterable
16
17from stardesign.jsformat import js_number
18
19HEADER = "Time (s),LOX Pressure (Pa),Fuel Pressure (Pa)\n"
20
21
22def pressure_curves_csv(results: dict[str, Any]) -> str:
23 t: Iterable[Any] = results.get("time_array") or []
24 lox = results.get("lox_pressure") or []
25 fuel = results.get("fuel_pressure") or []
26 rows = [HEADER]
27 for i, ti in enumerate(t):
28 lo = lox[i] if i < len(lox) else None
29 fu = fuel[i] if i < len(fuel) else None
30 # The browser wrote `undefined` past the end of a short array; say nothing instead.
31 rows.append(f"{js_number(ti)},{'' if lo is None else js_number(lo)},{'' if fu is None else js_number(fu)}\n")
32 return "".join(rows)
str pressure_curves_csv(dict[str, Any] results)