fix(devices): use the nearest valid measurement of a key

DataSequence.key_to_value took the record nearest in time and returned
the key from it, even when that record did not hold the key. Feeders
write measurement keys one at a time, seconds apart, and every write
creates its own record. A battery temperature written at 10:00:00 and a
SoC written at 10:00:01 then gave no temperature for a lookup at 10:01,
so battery temperature, SoC factor, charge/discharge power and the
inverter temperature fell back to the reference operating point (25 degC,
SoC 0.5, 45 degC). Profiles with a temperature or SoC dependent charge
limit were evaluated there, e.g. with too high a charge power for a cold
battery.

key_to_value now returns the nearest value of the key itself: records
where the key is None or NaN are skipped, as dropna does for the other
key accessors. The search window and its bounds are unchanged; without
a window only an exact match counts.

Additional changes
Developer docs describe key_to_value as the nearest valid value of a key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
Christin
2026-11-28 08:08:37 +01:00
committed by Bobby Noelte
co-authored by Claude Opus 5.5
parent 12527597b1
commit b2c5820925
4 changed files with 94 additions and 6 deletions
+1 -1
View File
@@ -137,7 +137,7 @@ These methods do not modify sequence state and require no locking:
| `key_to_lists(key, ...)` | Extract parallel date and value lists. |
| `key_to_series(key, ...)` | Extract a `pd.Series` indexed by datetime. |
| `key_to_array(key, ...)` | Extract a resampled `np.ndarray` at a fixed interval. |
| `key_to_value(key, dt)` | Scalar lookup nearest to a datetime. |
| `key_to_value(key, dt)` | Nearest valid value of a key to a datetime (records without the key are skipped). |
| `to_dataframe(...)` | Convert all records to a `pd.DataFrame`. |
| `delete_by_datetime(...)` | Delete records within a datetime range. |
| `key_delete_by_datetime(key, ...)` | Set a field to `None` across a datetime range. |