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
3
Used to be built in the browser (Layer2Optimization / Layer3Optimization
4
``downloadCSV``), so nothing but an open tab could produce it. Now the backend
5
writes it (GET /api/optimizer/layer{2,3}/results.csv) and the UI's button fetches
6
that, so the file is the same whoever asks -- the design-tools MCP included.
7
8
The format is unchanged: ``Time (s),LOX Pressure (Pa),Fuel Pressure (Pa)``, one
9
row 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
13
from
__future__
import
annotations
14
15
from
typing
import
Any, Iterable
16
17
from
stardesign.jsformat
import
js_number
18
19
HEADER =
"Time (s),LOX Pressure (Pa),Fuel Pressure (Pa)\n"
20
21
22
def
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)
backend.results_csv.pressure_curves_csv
str pressure_curves_csv(dict[str, Any] results)
Definition
results_csv.py:22
stardesign.jsformat
Definition
jsformat.py:1
EngineDesign
backend
results_csv.py
Generated by
1.15.0