Skip to content

Commit 765ebfa

Browse files
Ken LippoldKen Lippold
authored andcommitted
Updated data products API and added run methods to service layer.
1 parent f7a0be4 commit 765ebfa

41 files changed

Lines changed: 3346 additions & 1685 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

django/core/sta/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ def delete_observations(self, request, queryset):
153153
datastream_id=datastream.id
154154
)
155155
observations.delete()
156+
datastream.phenomenon_begin_time = None
157+
datastream.phenomenon_end_time = None
158+
datastream.result_begin_time = None
159+
datastream.result_end_time = None
160+
datastream.value_count = 0
161+
datastream.save()
156162
self.message_user(request, "Observations deleted successfully.")
157163
else:
158164
self.message_user(
Lines changed: 27 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import uuid
22
from datetime import datetime
3-
from typing import Optional, Literal, Union
3+
from typing import Optional, Literal
44

55
from ninja import Field, Query
66

@@ -15,7 +15,8 @@
1515
)
1616

1717

18-
WindowUnits = Literal["minutes", "hours", "days"]
18+
WindowIntervalUnits = Literal["minutes", "hours", "days"]
19+
RuleType = Literal["range", "rate_of_change", "persistence", "missing_data"]
1920

2021

2122
class MonitoringRuleOrderBy(OrderByField):
@@ -36,123 +37,48 @@ class MonitoringRuleQueryParameters(CollectionQueryParameters):
3637
)
3738

3839

39-
# --- Per-type response schemas ---
40-
41-
class RangeRuleResponse(BaseGetResponse):
42-
rule_type: Literal["range"] = Field(alias="type")
40+
class MonitoringRuleResponse(BaseGetResponse):
41+
id: uuid.UUID
42+
datastream: DatastreamSummaryResponse
43+
rule_type: RuleType
44+
last_checked_at: Optional[datetime] = None
4345
min_value: Optional[float] = None
4446
max_value: Optional[float] = None
47+
window_interval: Optional[int] = None
48+
window_interval_units: Optional[WindowIntervalUnits] = None
4549

50+
@staticmethod
51+
def resolve_datastream(obj):
52+
return obj.datastream
4653

47-
class RateOfChangeRuleResponse(BaseGetResponse):
48-
rule_type: Literal["rate_of_change"] = Field(alias="type")
49-
max_change: float
50-
window: int
51-
window_units: WindowUnits
52-
53-
54-
class PersistenceRuleResponse(BaseGetResponse):
55-
rule_type: Literal["persistence"] = Field(alias="type")
56-
persist_value: Optional[float] = None
57-
window: int
58-
window_units: WindowUnits
59-
60-
61-
class MissingDataRuleResponse(BaseGetResponse):
62-
rule_type: Literal["missing_data"] = Field(alias="type")
63-
window: int
64-
window_units: WindowUnits
65-
66-
67-
# --- Per-type post body schemas ---
68-
69-
class RangeRulePostBody(BasePostBody, RangeRuleResponse):
70-
...
71-
72-
73-
class RateOfChangeRulePostBody(BasePostBody, RateOfChangeRuleResponse):
74-
...
75-
76-
77-
class PersistenceRulePostBody(BasePostBody, PersistenceRuleResponse):
78-
...
79-
80-
81-
class MissingDataRulePostBody(BasePostBody, MissingDataRuleResponse):
82-
...
83-
84-
85-
# --- Per-type patch body schemas ---
86-
87-
class RangeRulePatchBody(BasePatchBody, RangeRuleResponse):
88-
...
89-
90-
91-
class RateOfChangeRulePatchBody(BasePatchBody, RateOfChangeRuleResponse):
92-
...
93-
94-
95-
class PersistenceRulePatchBody(BasePatchBody, PersistenceRuleResponse):
96-
...
97-
98-
99-
class MissingDataRulePatchBody(BasePatchBody, MissingDataRuleResponse):
100-
...
101-
102-
103-
# --- Shared resolve_rule helper ---
104-
105-
def _resolve_rule(obj) -> dict:
106-
return {
107-
"rule_type": obj.rule_type,
108-
"min_value": obj.min_value,
109-
"max_value": obj.max_value,
110-
"max_change": obj.max_change,
111-
"persist_value": obj.persist_value,
112-
"window": obj.window,
113-
"window_units": obj.window_units,
114-
}
115-
116-
117-
# --- Top-level rule schemas ---
11854

11955
class MonitoringRuleDetailResponse(BaseGetResponse):
120-
"""Rule details without the datastream — used when nested under a MonitoredDatastreamResponse."""
12156
id: uuid.UUID
57+
rule_type: RuleType
12258
last_checked_at: Optional[datetime] = None
123-
rule: Union[RangeRuleResponse, RateOfChangeRuleResponse, PersistenceRuleResponse, MissingDataRuleResponse]
124-
125-
@staticmethod
126-
def resolve_rule(obj):
127-
return _resolve_rule(obj)
59+
min_value: Optional[float] = None
60+
max_value: Optional[float] = None
61+
window_interval: Optional[int] = None
62+
window_interval_units: Optional[WindowIntervalUnits] = None
12863

12964

13065
class MonitoredDatastreamResponse(BaseGetResponse):
131-
"""A datastream and all its rules for a given monitoring task."""
13266
datastream: DatastreamSummaryResponse
13367
rules: list[MonitoringRuleDetailResponse]
13468

13569

136-
class MonitoringRuleResponse(BaseGetResponse):
137-
id: uuid.UUID
138-
datastream: DatastreamSummaryResponse
139-
last_checked_at: Optional[datetime] = None
140-
rule: Union[RangeRuleResponse, RateOfChangeRuleResponse, PersistenceRuleResponse, MissingDataRuleResponse]
141-
142-
@staticmethod
143-
def resolve_datastream(obj):
144-
return obj.datastream
145-
146-
@staticmethod
147-
def resolve_rule(obj):
148-
return _resolve_rule(obj)
149-
150-
15170
class MonitoringRulePostBody(BasePostBody):
15271
uid: uuid.UUID | Unset = Field(Unset, alias="id")
15372
datastream_id: uuid.UUID
154-
rule: Union[RangeRulePostBody, RateOfChangeRulePostBody, PersistenceRulePostBody, MissingDataRulePostBody]
73+
rule_type: RuleType
74+
min_value: Optional[float] = None
75+
max_value: Optional[float] = None
76+
window_interval: Optional[int] = None
77+
window_interval_units: Optional[WindowIntervalUnits] = None
15578

15679

15780
class MonitoringRulePatchBody(BasePatchBody):
158-
rule: Union[RangeRulePatchBody, RateOfChangeRulePatchBody, PersistenceRulePatchBody, MissingDataRulePatchBody]
81+
min_value: Optional[float]
82+
max_value: Optional[float]
83+
window_interval: Optional[int]
84+
window_interval_units: Optional[WindowIntervalUnits]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from interfaces.api.schemas.products.rating_curve import (
2+
RatingCurveSummaryResponse, RatingCurveResponse,
3+
RatingCurvePostBody, RatingCurvePatchBody,
4+
RatingCurveQueryParameters,
5+
)
6+
from interfaces.api.schemas.products.task import (
7+
DataProductTaskResponse,
8+
DataProductTaskPostBody,
9+
DataProductTaskPatchBody,
10+
DataProductTaskQueryParameters,
11+
)

django/interfaces/api/schemas/products/expression.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

django/interfaces/api/schemas/products/rating_curve.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515

16-
FittingMethod = Literal["linear", "power_law", "polynomial", "spline"]
16+
FittingMethod = Literal["linear", "power_law", "polynomial"]
1717

1818

1919
class RatingCurveOrderBy(OrderByField):
@@ -37,13 +37,19 @@ class RatingCurveQueryParameters(CollectionQueryParameters):
3737
)
3838

3939

40+
class RatingCurveSummaryResponse(BaseGetResponse):
41+
id: uuid.UUID
42+
name: str
43+
fitting_method: FittingMethod
44+
45+
4046
class RatingCurveResponse(BaseGetResponse):
4147
id: uuid.UUID
4248
name: str
4349
description: Optional[str] = None
4450
fitting_method: FittingMethod
4551
thing: ThingSummaryResponse
46-
points: list[tuple[float, Optional[float]]]
52+
points: list[tuple[float, float]]
4753

4854
@staticmethod
4955
def resolve_points(obj):
@@ -56,11 +62,11 @@ class RatingCurvePostBody(BasePostBody):
5662
description: Optional[str] = None
5763
fitting_method: FittingMethod
5864
thing_id: uuid.UUID
59-
points: list[tuple[float, Optional[float]]] = []
65+
points: list[tuple[float, float]] = []
6066

6167

6268
class RatingCurvePatchBody(BasePatchBody):
6369
name: str
6470
description: Optional[str] = None
6571
fitting_method: FittingMethod
66-
points: list[tuple[float, Optional[float]]] = []
72+
points: list[tuple[float, float]]

0 commit comments

Comments
 (0)