Skip to content

Commit 5bd2ca8

Browse files
committed
fix type for history
1 parent ea3d9bc commit 5bd2ca8

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

api/handlers_fields.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func enrichFieldWithLatestReport(ctx context.Context, a *App, f *models.Field) {
114114
CloudcoverPct: toFloatPtr(it["cloudcover_pct"]),
115115
WindSpeedMps: toFloatPtr(it["wind_speed_mps"]),
116116
ClarityPct: toFloatPtr(it["clarity_pct"]),
117+
Type: int(it["type"].(int32)),
117118
}
118119
h = append(h, entry)
119120
}
@@ -124,7 +125,7 @@ func enrichFieldWithLatestReport(ctx context.Context, a *App, f *models.Field) {
124125

125126
if doc.Forecast != nil && len(doc.Forecast) > 0 {
126127
ff := &models.ReportForecast{
127-
Model: "eurustic",
128+
YieldModel: "eurustic",
128129
}
129130
// year
130131
if y, ok := doc.Forecast["year"].(int32); ok {
@@ -144,9 +145,9 @@ func enrichFieldWithLatestReport(ctx context.Context, a *App, f *models.Field) {
144145
ff.NDVIPeak = toFloatPtr(doc.Forecast["ndviPeak"])
145146
ff.NDVIPeakAt = parseRFC3339Ptr(doc.Forecast["ndviPeakAt"])
146147
if m, ok := doc.Forecast["model"].(string); ok && m != "" {
147-
ff.Model = m
148+
ff.YieldModel = m
148149
}
149-
ff.Confidence = toFloatPtr(doc.Forecast["confidence"])
150+
ff.YieldConfidence = toFloatPtr(doc.Forecast["confidence"])
150151

151152
f.Forecast = ff
152153
}

api/models/report.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Report struct {
2929
// ReportDaily — one daily observation as written by the processor.
3030
type ReportDaily struct {
3131
Date time.Time `bson:"date" json:"date"` // RFC3339 stored as time in Go
32+
Type int `bson:"type,omitempty" json:"type"` // 0: actual, 1: forecast
3233
NDVI *float64 `bson:"ndvi,omitempty" json:"ndvi,omitempty"`
3334
CloudCover *int `bson:"cloud_cover,omitempty" json:"cloud_cover,omitempty"` // HLS cloud mask (0..100?)
3435
Collection string `bson:"collection,omitempty" json:"collection,omitempty"` // e.g., "HLSS30_2.0"
@@ -37,16 +38,18 @@ type ReportDaily struct {
3738
CloudcoverPct *float64 `bson:"cloudcover_pct,omitempty" json:"cloudcover_pct,omitempty"`
3839
WindSpeedMps *float64 `bson:"wind_speed_mps,omitempty" json:"wind_speed_mps,omitempty"`
3940
ClarityPct *float64 `bson:"clarity_pct,omitempty" json:"clarity_pct,omitempty"`
40-
41-
Type int `bson:"type,omitempty" json:"type,omitempty"` // 0: actual, 1: forecast
4241
}
4342

4443
// ReportForecast — forecast section produced by the processor.
4544
type ReportForecast struct {
46-
Year int `bson:"year" json:"year"`
47-
YieldTph *float64 `bson:"yieldTph,omitempty" json:"yieldTph,omitempty"`
48-
NDVIPeak *float64 `bson:"ndviPeak,omitempty" json:"ndviPeak,omitempty"`
49-
NDVIPeakAt *time.Time `bson:"ndviPeakAt,omitempty" json:"ndviPeakAt,omitempty"`
50-
Model string `bson:"model,omitempty" json:"model,omitempty"`
51-
Confidence *float64 `bson:"confidence,omitempty" json:"confidence,omitempty"`
45+
Year int `bson:"year" json:"year"`
46+
YieldTph *float64 `bson:"yieldTph,omitempty" json:"yieldTph,omitempty"`
47+
YieldModel string `bson:"yieldModel,omitempty" json:"yieldModel,omitempty"`
48+
YieldConfidence *float64 `bson:"yieldConfidence,omitempty" json:"yieldConfidence,omitempty"`
49+
NDVIPeak *float64 `bson:"ndviPeak,omitempty" json:"ndviPeak,omitempty"`
50+
NDVIPeakAt *time.Time `bson:"ndviPeakAt,omitempty" json:"ndviPeakAt,omitempty"`
51+
NDVIStartAt *time.Time `bson:"ndviStartAt,omitempty" json:"ndviStartAt,omitempty"`
52+
NDVIEndAt *time.Time `bson:"ndviEndAt,omitempty" json:"ndviEndAt,omitempty"`
53+
NDVIModel string `bson:"ndviModel,omitempty" json:"ndviModel,omitempty"`
54+
NDVIConfidence *float64 `bson:"ndviConfidence,omitempty" json:"ndviConfidence,omitempty"`
5255
}

api/openapi.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ components:
7373
type: string
7474
format: date-time
7575
description: RFC3339 timestamp
76+
type:
77+
type: integer
78+
description: 0 = actual, 1 = forecast
7679
ndvi:
7780
type: number
7881
format: float
@@ -175,6 +178,23 @@ components:
175178
items:
176179
$ref: '#/components/schemas/YieldEntry'
177180

181+
UpdateFieldReq:
182+
type: object
183+
description: Partial update; no required fields. Any provided field will be updated.
184+
properties:
185+
name: { type: string }
186+
geometry:
187+
type: object
188+
description: GeoJSON Polygon or MultiPolygon (raw JSON)
189+
areaHa: { type: number, format: float }
190+
notes: { type: string }
191+
crop: { type: string }
192+
photo: { type: string }
193+
yields:
194+
type: array
195+
items:
196+
$ref: '#/components/schemas/YieldEntry'
197+
178198
ProcessorReportReq:
179199
type: object
180200
properties:
@@ -304,7 +324,7 @@ paths:
304324
content:
305325
application/json:
306326
schema:
307-
$ref: '#/components/schemas/CreateFieldReq'
327+
$ref: '#/components/schemas/UpdateFieldReq'
308328
responses:
309329
'200':
310330
description: Updated field

0 commit comments

Comments
 (0)