Skip to content

qc#

Quality-control checks, measurement history, and trend tracking.

add_metric #

add_metric(
    config_name: str,
    metric_type: str,
    name: str | None = None,
    unit: str = "",
    lower_limit: float | None = None,
    upper_limit: float | None = None,
    target_value: float | None = None,
    peak_index: int | None = None,
    region_start_hz: float | None = None,
    region_end_hz: float | None = None,
) -> bool

Add a metric to an existing configuration.

Parameters:

Name Type Description Default
config_name str

Name of the configuration to modify.

required
metric_type str

Type of metric ("snr", "linewidth_hz", etc.).

required
name str | None

Display name (defaults to metric_type if not provided).

None
unit str

Unit string.

''
lower_limit float | None

Minimum acceptable value.

None
upper_limit float | None

Maximum acceptable value.

None
target_value float | None

Expected nominal value.

None
peak_index int | None

For peak-specific metrics.

None
region_start_hz float | None

Start of integration region (for integral).

None
region_end_hz float | None

End of integration region (for integral).

None

Returns:

Type Description
bool

True if successful, False if configuration not found.

clear_history #

clear_history(config_name: str | None = None) -> int

Clear QC history.

Parameters:

Name Type Description Default
config_name str | None

Clear only for this config (None for all).

None

Returns:

Type Description
int

Number of records deleted.

create_configuration #

create_configuration(
    name: str,
    reference_sample: str = "",
    metrics: list[dict[str, Any]] | None = None,
    sequence_preset: str | None = None,
    enabled: bool = True,
) -> dict[str, Any]

Create a new QC configuration.

Each metric dict may set: type ("snr", "linewidth_hz", "peak_position_hz", "peak_position_ppm", "integral", "baseline_rms", "custom"), name, unit, lower_limit, upper_limit, target_value, peak_index, region_start_hz, region_end_hz.

Returns:

Type Description
dict[str, Any]

Summary dict with keys: name, reference_sample, metrics_count, enabled.

delete_configuration #

delete_configuration(name: str) -> bool

Delete a QC configuration.

Parameters:

Name Type Description Default
name str

Configuration name to delete.

required

Returns:

Type Description
bool

True if deleted, False if not found.

generate_chart #

generate_chart(
    config_name: str,
    metric_name: str,
    days: int = 30,
    width: int = 800,
    height: int = 400,
    scale: float = 2.0,
    title: str | None = None,
) -> str | None

Generate a QC control chart image.

Returns:

Type Description
str | None

Base64-encoded PNG image string, or None if no data/error.

generate_chart_html #

generate_chart_html(
    config_name: str,
    metric_name: str,
    days: int = 30,
    width: int = 800,
    height: int = 400,
    scale: float = 2.0,
    title: str | None = None,
) -> str

Generate a QC control chart as an HTML img tag.

Returns:

Type Description
str

HTML img tag with embedded base64 image, or error message.

get_configuration #

get_configuration(name: str) -> dict[str, Any] | None

Get a QC configuration by name.

Parameters:

Name Type Description Default
name str

Configuration name.

required

Returns:

Type Description
dict[str, Any] | None

The configuration as a dictionary, or None if not found. Keys:

dict[str, Any] | None

name, reference_sample, sequence_preset, enabled, and

dict[str, Any] | None

metrics (a list of metric definitions, each with type,

dict[str, Any] | None

name, unit, lower_limit, upper_limit, target_value,

dict[str, Any] | None

peak_index, region_start_hz, region_end_hz).

get_history #

get_history(
    config_name: str | None = None, limit: int = 100
) -> list[dict[str, Any]]

Get QC measurement history.

Parameters:

Name Type Description Default
config_name str | None

Filter by configuration (None for all).

None
limit int

Maximum records to return.

100

Returns:

Name Type Description
list[dict[str, Any]]

A list of past measurement records, newest first. Each record has

keys list[dict[str, Any]]

id, config_name, timestamp, overall_pass, and

list[dict[str, Any]]

measurements (a list of {name, value, passed} per metric).

get_statistics #

get_statistics(
    config_name: str, metric_name: str, days: int = 30
) -> dict[str, Any] | None

Get statistics for a specific metric.

Parameters:

Name Type Description Default
config_name str

QC configuration name.

required
metric_name str

Metric to analyze.

required
days int

Number of days of history.

30

Returns:

Type Description
dict[str, Any] | None

Statistics dictionary or None if no data:

dict[str, Any] | None
  • count: Number of measurements
dict[str, Any] | None
  • mean: Average value
dict[str, Any] | None
  • std: Standard deviation
dict[str, Any] | None
  • min: Minimum value
dict[str, Any] | None
  • max: Maximum value
dict[str, Any] | None
  • pass_rate: Fraction of measurements that passed (0-1)
dict[str, Any] | None
  • last_value: Most recent value
dict[str, Any] | None
  • last_passed: Whether most recent passed

get_trend #

get_trend(
    config_name: str, metric_name: str, days: int = 30
) -> list[dict[str, Any]]

Get trend data for a specific metric.

Parameters:

Name Type Description Default
config_name str

QC configuration name.

required
metric_name str

Metric to get trend for.

required
days int

Number of days of history.

30

Returns:

Type Description
list[dict[str, Any]]

List of {timestamp, value, passed} dicts.

list_configurations #

list_configurations() -> list[str]

List all QC configuration names.

Returns:

Type Description
list[str]

List of configuration names.

measure #

measure(
    config_name: str,
    spectrum: Spectrum1D | None = None,
    scan_id: str | None = None,
    notes: str = "",
    dry_run: bool = False,
) -> dict[str, Any]

Run QC measurement using the current or provided spectrum.

If dry_run is True, metrics are computed but not saved to history.

Returns:

Type Description
dict[str, Any]

Dict with keys: id, overall_pass, measurements, timestamp, dry_run.

set_report_options #

set_report_options(
    config_name: str | None = None,
    days: int = 30,
    width: int = 800,
    height: int = 400,
    scale: float = 2.0,
    include_charts: bool = True,
) -> None

Set options for QC data shown via the {{qc}} template variable in reports.

config_name of None includes all configurations.