# {py:mod}`haniwers.v1.threshold.writer`

```{py:module} haniwers.v1.threshold.writer
```

```{autodoc2-docstring} haniwers.v1.threshold.writer
:allowtitles:
```

## Module Contents

### Classes

````{list-table}
:class: autosummary longtable
:align: left

* - {py:obj}`ThresholdResult <haniwers.v1.threshold.writer.ThresholdResult>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.ThresholdResult
    :summary:
    ```
````

### Functions

````{list-table}
:class: autosummary longtable
:align: left

* - {py:obj}`write_threshold <haniwers.v1.threshold.writer.write_threshold>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.write_threshold
    :summary:
    ```
* - {py:obj}`write_threshold_with_retry <haniwers.v1.threshold.writer.write_threshold_with_retry>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.write_threshold_with_retry
    :summary:
    ```
* - {py:obj}`log_threshold_operation <haniwers.v1.threshold.writer.log_threshold_operation>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.log_threshold_operation
    :summary:
    ```
* - {py:obj}`load_thresholds_from_csv <haniwers.v1.threshold.writer.load_thresholds_from_csv>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.load_thresholds_from_csv
    :summary:
    ```
* - {py:obj}`apply_threshold <haniwers.v1.threshold.writer.apply_threshold>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.apply_threshold
    :summary:
    ```
* - {py:obj}`apply_thresholds <haniwers.v1.threshold.writer.apply_thresholds>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.apply_thresholds
    :summary:
    ```
* - {py:obj}`set_threshold <haniwers.v1.threshold.writer.set_threshold>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.set_threshold
    :summary:
    ```
* - {py:obj}`set_thresholds_from_csv <haniwers.v1.threshold.writer.set_thresholds_from_csv>`
  - ```{autodoc2-docstring} haniwers.v1.threshold.writer.set_thresholds_from_csv
    :summary:
    ```
````

### API

`````{py:class} ThresholdResult
:canonical: haniwers.v1.threshold.writer.ThresholdResult

Bases: {py:obj}`typing.NamedTuple`

```{autodoc2-docstring} haniwers.v1.threshold.writer.ThresholdResult
```

````{py:attribute} id
:canonical: haniwers.v1.threshold.writer.ThresholdResult.id
:type: int
:value: >
   None

```{autodoc2-docstring} haniwers.v1.threshold.writer.ThresholdResult.id
```

````

````{py:attribute} vth
:canonical: haniwers.v1.threshold.writer.ThresholdResult.vth
:type: int
:value: >
   None

```{autodoc2-docstring} haniwers.v1.threshold.writer.ThresholdResult.vth
```

````

````{py:attribute} success
:canonical: haniwers.v1.threshold.writer.ThresholdResult.success
:type: bool
:value: >
   None

```{autodoc2-docstring} haniwers.v1.threshold.writer.ThresholdResult.success
```

````

````{py:attribute} attempts
:canonical: haniwers.v1.threshold.writer.ThresholdResult.attempts
:type: int
:value: >
   None

```{autodoc2-docstring} haniwers.v1.threshold.writer.ThresholdResult.attempts
```

````

`````

````{py:function} write_threshold(device: haniwers.v1.daq.device.Device, ch: int, vth: int) -> bool
:canonical: haniwers.v1.threshold.writer.write_threshold

```{autodoc2-docstring} haniwers.v1.threshold.writer.write_threshold
```
````

````{py:function} write_threshold_with_retry(device: haniwers.v1.daq.device.Device, ch: int, vth: int, max_retry: int = 3) -> haniwers.v1.threshold.writer.ThresholdResult
:canonical: haniwers.v1.threshold.writer.write_threshold_with_retry

```{autodoc2-docstring} haniwers.v1.threshold.writer.write_threshold_with_retry
```
````

````{py:function} log_threshold_operation(log_path: pathlib.Path, ch: int, vth: int, success: bool) -> None
:canonical: haniwers.v1.threshold.writer.log_threshold_operation

```{autodoc2-docstring} haniwers.v1.threshold.writer.log_threshold_operation
```
````

````{py:function} load_thresholds_from_csv(csv_path: pathlib.Path) -> dict[int, int]
:canonical: haniwers.v1.threshold.writer.load_thresholds_from_csv

```{autodoc2-docstring} haniwers.v1.threshold.writer.load_thresholds_from_csv
```
````

````{py:function} apply_threshold(device: haniwers.v1.daq.device.Device, sensor: haniwers.v1.config.model.SensorConfig, max_retry: int = 3, history_path: pathlib.Path | None = None) -> haniwers.v1.threshold.writer.ThresholdResult
:canonical: haniwers.v1.threshold.writer.apply_threshold

```{autodoc2-docstring} haniwers.v1.threshold.writer.apply_threshold
```
````

````{py:function} apply_thresholds(device: haniwers.v1.daq.device.Device, sensors: list[haniwers.v1.config.model.SensorConfig], max_retry: int = 3, history_path: pathlib.Path | None = None) -> list[haniwers.v1.threshold.writer.ThresholdResult]
:canonical: haniwers.v1.threshold.writer.apply_thresholds

```{autodoc2-docstring} haniwers.v1.threshold.writer.apply_thresholds
```
````

````{py:function} set_threshold(device: haniwers.v1.daq.device.Device, ch: int, vth: int, max_retry: int = 3, log_path: pathlib.Path | None = None) -> bool
:canonical: haniwers.v1.threshold.writer.set_threshold

```{autodoc2-docstring} haniwers.v1.threshold.writer.set_threshold
```
````

````{py:function} set_thresholds_from_csv(device: haniwers.v1.daq.device.Device, csv_path: pathlib.Path, max_retry: int = 3, log_path: pathlib.Path | None = None) -> dict[int, bool]
:canonical: haniwers.v1.threshold.writer.set_thresholds_from_csv

```{autodoc2-docstring} haniwers.v1.threshold.writer.set_thresholds_from_csv
```
````
