refuse to update spooldb with negative total or filament weights
This commit is contained in:
@@ -36,9 +36,6 @@ func trace(op string) func() {
|
||||
// top bar) from being misread as a 1 on this kind of LCD.
|
||||
const weightPrompt = `This photo shows a 3D printer filament spool sitting on a digital kitchen scale. ` +
|
||||
`Read the weight on the scale's digital display, digit by digit, exactly as shown. ` +
|
||||
`Note: the top edge of the display housing can come close to obscuring the TOPS of the digits, ` +
|
||||
`so a digit that really has a top horizontal bar (like a 7) can momentarily look like a 1 — ` +
|
||||
`look carefully for a faint top bar before deciding. ` +
|
||||
`Report the unit shown on the display (g, kg, lb, or oz), and rate your own confidence ` +
|
||||
`in the reading as "low", "medium", or "high". ` +
|
||||
`Reason briefly, then on the LAST line output ONLY JSON: ` +
|
||||
|
||||
@@ -217,6 +217,10 @@ func processImg(img image.Image, name string, auth claude.Auth, dryRun bool) res
|
||||
r.Error = fmt.Sprintf("scale is set to imperial units (%s); switch it to grams", reading.Unit)
|
||||
return r
|
||||
}
|
||||
if reading.Weight < 0 {
|
||||
r.Error = fmt.Sprintf("scale read a negative weight (%g g); refusing to update", reading.Weight)
|
||||
return r
|
||||
}
|
||||
r.Unit = reading.Unit
|
||||
r.Confidence = ptr(reading.Confidence)
|
||||
r.VoteWeights = reading.Weights
|
||||
@@ -228,6 +232,10 @@ func processImg(img image.Image, name string, auth claude.Auth, dryRun bool) res
|
||||
if info != nil {
|
||||
r.NewWeight.Spool = ptr(info.EmptySpoolGrams)
|
||||
r.NewWeight.Filament = ptr(reading.Weight - info.EmptySpoolGrams)
|
||||
if reading.Weight-info.EmptySpoolGrams < 0 {
|
||||
r.Error = fmt.Sprintf("measured total %g g is below the empty-spool weight %g g (negative filament); refusing to update", reading.Weight, info.EmptySpoolGrams)
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
// Write the measured total back when it differs from the site's total — the
|
||||
|
||||
Reference in New Issue
Block a user