STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
backend.main Namespace Reference

Functions

list[str] _parse_components (str|None components)
str _time_source (str value)
 api_runs ()
 api_set_description (str run_id, str text=Body(..., embed=True, max_length=4000))
 api_summary (str run_id)
 api_components (str run_id)
 api_index (str run_id)
 api_config (str run_id)
 api_series (str run_id, str components=Query(...), float|None start=None, float|None end=None, int max_points=4000, str time_source="sensor")
 api_download (str run_id, str|None components=None, float|None start=None, float|None end=None, str time_source="sensor")
 api_run_video (str run_id)
 api_video_file (str recording, str stream)
 lifespan (FastAPI app)
str _sentence (str text)
str _one_problem (dict err)
str validation_sentence (list errors)
JSONResponse _validation_as_sentence (Request request, RequestValidationError exc)
JSONResponse _unhandled_as_sentence (Request request, Exception exc)
 root ()
 health ()

Variables

 app = FastAPI(title="Elodin Past-Run Viewer")
 allow_origins
 allow_methods
 allow_headers
str VIDEO_CACHE_CONTROL = "private, max-age=86400"
str _dist = Path(__file__).resolve().parent.parent / "frontend" / "dist"
 name
 project_root = Path(__file__).resolve().parents[1]
dict _optional_routers = {}
 router_module = __import__(f'backend.routers.{router_name}', fromlist=[router_name])
 allow_credentials

Detailed Description

FastAPI app: browse past Elodin runs, list sensors, plot, and export CSV.

Run (dev):   uvicorn backend.main:app --reload --port 8000
Prod-ish:    build the frontend to frontend/dist and this process serves it too.
FastAPI application for Pintle Engine Design.

Run with:
    cd /home/adnan/EngineDesign
    uvicorn backend.main:app --reload --port 8000

Function Documentation

◆ _one_problem()

str backend.main._one_problem ( dict err)
protected

Definition at line 80 of file main.py.

Referenced by validation_sentence().

◆ _parse_components()

list[str] backend.main._parse_components ( str | None components)
protected

Definition at line 30 of file main.py.

Referenced by api_download(), and api_series().

◆ _sentence()

str backend.main._sentence ( str text)
protected

Definition at line 72 of file main.py.

References split().

Referenced by validation_sentence().

◆ _time_source()

str backend.main._time_source ( str value)
protected
Which clock the x-axis is. Defaults to the sensor clock; see series.py.

Definition at line 36 of file main.py.

Referenced by api_download(), and api_series().

◆ _unhandled_as_sentence()

JSONResponse backend.main._unhandled_as_sentence ( Request request,
Exception exc )
protected

Definition at line 113 of file main.py.

◆ _validation_as_sentence()

JSONResponse backend.main._validation_as_sentence ( Request request,
RequestValidationError exc )
protected

Definition at line 99 of file main.py.

References validation_sentence().

◆ api_components()

backend.main.api_components ( str run_id)
The component index. Only for an already-indexed run: selecting a run must not
cost a multi-second export, so building one is POST /index, an explicit action.

Definition at line 80 of file main.py.

◆ api_config()

backend.main.api_config ( str run_id)
The config snapshot taken beside this run's DB when the session started.

Served verbatim — it is the record of what actually ran, so it is never reformatted
or re-serialised. Runs recorded before the snapshot existed simply have no file.

Definition at line 112 of file main.py.

◆ api_download()

backend.main.api_download ( str run_id,
str | None components = None,
float | None start = None,
float | None end = None,
str time_source = "sensor" )
CSV export.

- With `components` (a plot selection): a **wide** CSV — one column per
  channel aligned on a shared time grid. Bounded by the selection, ideal for
  analysis of a few channels.
- Without `components` (whole run): a **long/tidy** CSV (`time,component,
  value`) over every primary channel. Streams at constant memory; a wide
  whole-run frame would blow up to millions of rows × hundreds of columns.

Definition at line 157 of file main.py.

References _parse_components(), and _time_source().

◆ api_index()

backend.main.api_index ( str run_id)
Export the run to parquet and build its index — the expensive step, run only when
asked for. Synchronous: tens of seconds on a multi-GB run, and the caller shows a
busy state for the duration. Concurrent callers share one export (export_cache holds
a per-run lock), so a double click costs nothing extra.

Definition at line 96 of file main.py.

◆ api_run_video()

backend.main.api_run_video ( str run_id)
The video clips that overlap this run, on the epoch-seconds axis the plot uses.

Matched against the run's whole extent on either clock, so switching the plot to
DB write time never hides a clip. Needs the index (that is where the extent lives);
an un-indexed run has no plot to put video on anyway. `available` is false when no
recordings folder is mounted: the page then shows no video panel at all.

Definition at line 197 of file main.py.

References max, and min.

◆ api_runs()

backend.main.api_runs ( )

Definition at line 44 of file main.py.

◆ api_series()

backend.main.api_series ( str run_id,
str components = Query(...),
float | None start = None,
float | None end = None,
int max_points = 4000,
str time_source = "sensor" )

Definition at line 133 of file main.py.

References _parse_components(), _time_source(), max, and min.

◆ api_set_description()

backend.main.api_set_description ( str run_id,
str text = Body(..., embed=True, max_length=4000) )
Set (or clear, with empty text) this run's shared one-line description.

Unowned on purpose: there is no login on this viewer, so anyone who can see a run can
label it and everyone else sees that label. Last write wins.

Definition at line 49 of file main.py.

◆ api_summary()

backend.main.api_summary ( str run_id)
What is knowable about a run without exporting it — size, component count and an
approximate duration. Sub-second; safe to call on every run selection.

Definition at line 69 of file main.py.

◆ api_video_file()

backend.main.api_video_file ( str recording,
str stream )
One clip's file, with HTTP Range (Starlette's FileResponse answers 206) so the
browser can seek without downloading the whole recording.

Definition at line 230 of file main.py.

◆ health()

backend.main.health ( )
Health check endpoint.

A liveness probe with no user context, so it no longer reports config_loaded
(that is a per-user fact now -- see GET /api/config).

Definition at line 168 of file main.py.

◆ lifespan()

backend.main.lifespan ( FastAPI app)
Application lifespan.

Live state is per-user now (backend/session.py), so there is no global config
to load at boot: each user's session loads configs/default.yaml on creation,
the first time that user hits the API. Nothing to do here.

Definition at line 54 of file main.py.

◆ root()

backend.main.root ( )
Root endpoint - API info.

Definition at line 158 of file main.py.

◆ validation_sentence()

str backend.main.validation_sentence ( list errors)
FastAPI's request-validation list ([{loc, msg, type}, ...]) as the one plain sentence every
error response carries (``{"detail": "<sentence>"}``). Every problem, each named by its field,
joined with '; ' -- as feed-twin's backend/errors.validation_sentence does. A sentence that
names only the first leaves the person fixing one field per round trip.

Definition at line 87 of file main.py.

References _one_problem(), and _sentence().

Referenced by _validation_as_sentence().

Variable Documentation

◆ _dist

str backend.main._dist = Path(__file__).resolve().parent.parent / "frontend" / "dist"
protected

Definition at line 241 of file main.py.

◆ _optional_routers

dict backend.main._optional_routers = {}
protected

Definition at line 45 of file main.py.

◆ allow_credentials

backend.main.allow_credentials

Definition at line 134 of file main.py.

◆ allow_headers

backend.main.allow_headers

Definition at line 26 of file main.py.

◆ allow_methods

backend.main.allow_methods

Definition at line 25 of file main.py.

◆ allow_origins

backend.main.allow_origins

Definition at line 24 of file main.py.

◆ app

backend.main.app = FastAPI(title="Elodin Past-Run Viewer")

Definition at line 18 of file main.py.

◆ name

backend.main.name

Definition at line 243 of file main.py.

◆ project_root

backend.main.project_root = Path(__file__).resolve().parents[1]

Definition at line 19 of file main.py.

◆ router_module

backend.main.router_module = __import__(f'backend.routers.{router_name}', fromlist=[router_name])

Definition at line 48 of file main.py.

◆ VIDEO_CACHE_CONTROL

str backend.main.VIDEO_CACHE_CONTROL = "private, max-age=86400"

Definition at line 226 of file main.py.