Skip to content

Commit 6f78b5f

Browse files
committed
Merge branch 'master' of https://github.com/rinatmini/DemeterEye
2 parents 8495ab7 + e59ea2b commit 6f78b5f

7 files changed

Lines changed: 352 additions & 150 deletions

File tree

api/handlers_fields.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ func enrichFieldWithLatestReport(ctx context.Context, a *App, f *models.Field) {
115115
WindSpeedMps: toFloatPtr(it["wind_speed_mps"]),
116116
ClarityPct: toFloatPtr(it["clarity_pct"]),
117117
}
118+
119+
// Populate point type for the UI safely: 0 = actual, 1 = forecast
120+
if tv, ok := it["type"]; ok && tv != nil {
121+
switch t := tv.(type) {
122+
case int:
123+
entry.Type = t
124+
case int32:
125+
entry.Type = int(t)
126+
case int64:
127+
entry.Type = int(t)
128+
case float64:
129+
entry.Type = int(math.Round(t))
130+
default:
131+
entry.Type = 0
132+
}
133+
} else if isFc, ok := it["isForecast"].(bool); ok && isFc {
134+
entry.Type = 1
135+
} else if isFc2, ok := it["isForcast"].(bool); ok && isFc2 {
136+
entry.Type = 1
137+
} else {
138+
entry.Type = 0
139+
}
118140
h = append(h, entry)
119141
}
120142
if len(h) > 0 {
@@ -124,7 +146,7 @@ func enrichFieldWithLatestReport(ctx context.Context, a *App, f *models.Field) {
124146

125147
if doc.Forecast != nil && len(doc.Forecast) > 0 {
126148
ff := &models.ReportForecast{
127-
Model: "eurustic",
149+
YieldModel: "eurustic",
128150
}
129151
// year
130152
if y, ok := doc.Forecast["year"].(int32); ok {
@@ -144,9 +166,9 @@ func enrichFieldWithLatestReport(ctx context.Context, a *App, f *models.Field) {
144166
ff.NDVIPeak = toFloatPtr(doc.Forecast["ndviPeak"])
145167
ff.NDVIPeakAt = parseRFC3339Ptr(doc.Forecast["ndviPeakAt"])
146168
if m, ok := doc.Forecast["model"].(string); ok && m != "" {
147-
ff.Model = m
169+
ff.YieldModel = m
148170
}
149-
ff.Confidence = toFloatPtr(doc.Forecast["confidence"])
171+
ff.YieldConfidence = toFloatPtr(doc.Forecast["confidence"])
150172

151173
f.Forecast = ff
152174
}

api/models/report.go

Lines changed: 11 additions & 6 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"
@@ -41,10 +42,14 @@ type ReportDaily struct {
4142

4243
// ReportForecast — forecast section produced by the processor.
4344
type ReportForecast struct {
44-
Year int `bson:"year" json:"year"`
45-
YieldTph *float64 `bson:"yieldTph,omitempty" json:"yieldTph,omitempty"`
46-
NDVIPeak *float64 `bson:"ndviPeak,omitempty" json:"ndviPeak,omitempty"`
47-
NDVIPeakAt *time.Time `bson:"ndviPeakAt,omitempty" json:"ndviPeakAt,omitempty"`
48-
Model string `bson:"model,omitempty" json:"model,omitempty"`
49-
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"`
5055
}

api/openapi.yaml

Lines changed: 37 additions & 3 deletions
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
@@ -123,9 +126,23 @@ components:
123126
type: string
124127
format: date-time
125128
nullable: true
126-
model:
129+
yieldModel:
130+
type: string
131+
yieldConfidence:
132+
type: number
133+
format: float
134+
nullable: true
135+
ndviStartAt:
136+
type: string
137+
format: date-time
138+
nullable: true
139+
ndviEndAt:
140+
type: string
141+
format: date-time
142+
nullable: true
143+
ndviModel:
127144
type: string
128-
confidence:
145+
ndviConfidence:
129146
type: number
130147
format: float
131148
nullable: true
@@ -175,6 +192,23 @@ components:
175192
items:
176193
$ref: '#/components/schemas/YieldEntry'
177194

195+
UpdateFieldReq:
196+
type: object
197+
description: Partial update; no required fields. Any provided field will be updated.
198+
properties:
199+
name: { type: string }
200+
geometry:
201+
type: object
202+
description: GeoJSON Polygon or MultiPolygon (raw JSON)
203+
areaHa: { type: number, format: float }
204+
notes: { type: string }
205+
crop: { type: string }
206+
photo: { type: string }
207+
yields:
208+
type: array
209+
items:
210+
$ref: '#/components/schemas/YieldEntry'
211+
178212
ProcessorReportReq:
179213
type: object
180214
properties:
@@ -304,7 +338,7 @@ paths:
304338
content:
305339
application/json:
306340
schema:
307-
$ref: '#/components/schemas/CreateFieldReq'
341+
$ref: '#/components/schemas/UpdateFieldReq'
308342
responses:
309343
'200':
310344
description: Updated field

0 commit comments

Comments
 (0)