Commit 63bf502
feat(transducer): publish and range-delete for corrected hydrographs
The hydrograph corrector in OcotilloUI could only download its corrected
series as CSV -- there was no POST for transducer observations at all. This
adds the two write endpoints its upload contract specifies.
POST /observation/transducer-groundwater-level/block publishes one corrected
logger file as one block plus all of its readings, in one transaction. The
block's span is derived from the measurements rather than sent: nothing links
the observation table to the block table, so the reader pairs them by time and
a client-supplied span wider than the data would make the block claim readings
it does not contain. `deployment_id` is optional and resolved from the
deployments covering that span; zero or more than one match is a 422 rather
than a guess, because guessing attributes readings to hardware that did not
record them.
An existing block sharing any instant with the new one is a 409 listing the
collisions. `?replace_overlapping=true` deletes those blocks and their
readings. The readings have to go with the block -- keeping them would leave
rows the reader cannot show that still occupy the deployment/parameter/instant
the new series is about to claim, so a "replace" that kept them would fail on
the very insert it was asked to make room for. Readings orphaned by a
hand-deleted block are caught separately and reported with the earliest
colliding timestamp, rather than letting the insert abort on a constraint name.
Overlap is inclusive on both bounds, unlike TransducerObservationBlock.overlaps,
which is half-open. The reader matches with `start <= t <= end`, so two blocks
sharing an endpoint both claim a reading at that instant -- exactly the
ambiguity the check exists to prevent.
DELETE /observation/transducer-groundwater-level removes every reading for a
well inside a closed range and reconciles the blocks that covered them: one
left empty is deleted, one left partial has its span narrowed to the survivors.
All three parameters are required; there is deliberately no unbounded form.
Scope matches the GET on the same path, so the set a client previews is the set
this removes.
Schema changes: provenance on the block (source_file, source_kind, and an
ordered corrections list), and a per-reading `note` set only where a correction
moved the value, so NULL reads as "as measured" rather than "unknown". A
corrected block is derived data, and a reviewer who cannot see that a series
was snapped to a manual measurement cannot review it. The block time-order
check is relaxed to `end >= start`: a block covering a single instant is
legitimate, either published that way or narrowed to it by a delete.
Both write routes are gated on AMP.Staging, a standalone group -- AMPAdmin does
not satisfy it and it satisfies nothing else -- so they ship dark while the
workbench is validated against real logger files.
Two bugs fixed in passing:
- The read route called get_transducer_observations positionally, and the
helper's fourth positional parameter is `sensor_id`. `start_time` landed in
`sensor_id` (unused, dropped), `end_time` landed in `start_time`, and
`end_time` was never set, so a requested upper bound was ignored and the
lower bound came from the wrong argument.
- `sort`/`order` on that route were accepted and ignored. They now work over a
whitelist; an unrecognised field is a 422 rather than a silently differently
ordered page.
Wellntel support from the contract is deferred: both the readings proxy and the
sensor_type filter on /thing are blocked on where the API key and the
wellname/PointID mapping should live.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent ef38ef2 commit 63bf502
13 files changed
Lines changed: 1988 additions & 15 deletions
File tree
- alembic/versions
- api
- core
- db
- docs
- domain
- schemas
- services
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
167 | 173 | | |
168 | 174 | | |
169 | 175 | | |
| |||
Lines changed: 116 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
57 | 83 | | |
58 | 84 | | |
59 | 85 | | |
| |||
88 | 114 | | |
89 | 115 | | |
90 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
91 | 144 | | |
92 | 145 | | |
93 | 146 | | |
| |||
155 | 208 | | |
156 | 209 | | |
157 | 210 | | |
| 211 | + | |
| 212 | + | |
158 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
159 | 217 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
167 | 227 | | |
168 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
169 | 235 | | |
170 | 236 | | |
171 | 237 | | |
| |||
302 | 368 | | |
303 | 369 | | |
304 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
305 | 405 | | |
306 | 406 | | |
307 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
| |||
89 | 104 | | |
90 | 105 | | |
91 | 106 | | |
| 107 | + | |
| 108 | + | |
92 | 109 | | |
93 | 110 | | |
0 commit comments