Skip to content

Commit 69e6881

Browse files
Ken LippoldKen Lippold
authored andcommitted
Updated fields included in SensorThings properties.
1 parent 8e9c096 commit 69e6881

File tree

12 files changed

+78
-4
lines changed

12 files changed

+78
-4
lines changed

iam/models/workspace.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class Workspace(models.Model):
4747

4848
objects = WorkspaceQueryset.as_manager()
4949

50+
@property
51+
def link(self):
52+
return f"{settings.PROXY_BASE_URL}/api/auth/workspaces/{self.id}"
53+
5054
@property
5155
def transfer_details(self):
5256
return getattr(self, "transfer_confirmation", None)

sta/schemas/sensorthings/datastream.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Optional, Literal
55
from sensorthings.components.datastreams.schemas import (DatastreamGetResponse as DefaultDatastreamGetResponse,
66
DatastreamListResponse as DefaultDatastreamListResponse)
7+
from .workspace import WorkspaceProperties
78

89

910
class DatastreamProperties(Schema):
@@ -18,6 +19,7 @@ class DatastreamProperties(Schema):
1819
aggregation_statistic: Optional[str] = None
1920
time_aggregation_interval: float
2021
time_aggregation_interval_unit_of_measurement: Literal["seconds", "minutes", "hours", "days"]
22+
workspace: WorkspaceProperties
2123

2224
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)
2325

sta/schemas/sensorthings/location.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime
66
from sensorthings.components.locations.schemas import (LocationGetResponse as DefaultLocationGetResponse,
77
LocationListResponse as DefaultLocationListResponse)
8+
from .workspace import WorkspaceProperties
89

910

1011
class LocationProperties(Schema):
@@ -13,6 +14,7 @@ class LocationProperties(Schema):
1314
elevation_m: Optional[float] = Field(None, alias="elevation_m")
1415
elevation_datum: Optional[str] = None
1516
last_updated: Optional[datetime] = None
17+
workspace: WorkspaceProperties
1618

1719
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)
1820

sta/schemas/sensorthings/observed_property.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
from ninja import Schema
22
from pydantic import ConfigDict
33
from pydantic.alias_generators import to_camel
4+
from typing import Optional
45
from sensorthings.components.observedproperties.schemas import (ObservedPropertyGetResponse as
56
DefaultObservedPropertyGetResponse,
67
ObservedPropertyListResponse as
78
DefaultObservedPropertyListResponse)
9+
from .workspace import WorkspaceProperties
810

911

1012
class ObservedPropertyProperties(Schema):
1113
variable_code: str
1214
variable_type: str
15+
workspace: Optional[WorkspaceProperties] = None
1316

1417
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)
1518

sta/schemas/sensorthings/sensor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sensorthings.types import AnyHttpUrlString
66
from sensorthings.components.sensors.schemas import (SensorGetResponse as DefaultSensorGetResponse,
77
SensorListResponse as DefaultSensorListResponse)
8+
from .workspace import WorkspaceProperties
89

910

1011
class SensorModel(Schema):
@@ -23,7 +24,7 @@ class SensorModel(Schema):
2324
]
2425

2526

26-
class SensorProperties(Schema):
27+
class SensorMetadata(Schema):
2728
method_code: Optional[str] = None
2829
method_type: str
2930
method_link: Optional[AnyHttpUrlString] = None
@@ -32,9 +33,14 @@ class SensorProperties(Schema):
3233
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)
3334

3435

36+
class SensorProperties(Schema):
37+
workspace: Optional[WorkspaceProperties] = None
38+
39+
3540
class SensorGetResponse(DefaultSensorGetResponse):
3641
encoding_type: sensorEncodingTypes
37-
sensor_metadata: SensorProperties = Field(..., alias="metadata")
42+
sensor_metadata: SensorMetadata = Field(..., alias="metadata")
43+
properties: SensorProperties
3844

3945
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)
4046

sta/schemas/sensorthings/thing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
from ninja import Schema
22
from pydantic import ConfigDict
33
from pydantic.alias_generators import to_camel
4+
from typing import Optional
5+
from sensorthings.types import AnyHttpUrlString
46
from sensorthings.components.things.schemas import (ThingGetResponse as DefaultThingGetResponse,
57
ThingListResponse as DefaultThingListResponse)
8+
from .workspace import WorkspaceProperties
69

710

811
class ThingProperties(Schema):
912
sampling_feature_type: str
1013
sampling_feature_code: str
1114
site_type: str
15+
data_disclaimer: Optional[str] = None
16+
is_private: bool
17+
workspace: WorkspaceProperties
18+
photos: list[AnyHttpUrlString]
19+
tags: dict[str, str]
1220

1321
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)
1422

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from ninja import Schema
2+
from pydantic import ConfigDict
3+
from pydantic.alias_generators import to_camel
4+
from uuid import UUID
5+
from sensorthings.types import AnyHttpUrlString
6+
7+
8+
class WorkspaceProperties(Schema):
9+
id: UUID
10+
name: str
11+
link: AnyHttpUrlString
12+
is_private: bool
13+
14+
model_config = ConfigDict(populate_by_name=True, str_strip_whitespace=True, alias_generator=to_camel)

sta/services/sensorthings/datastream.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ def get_datastreams(
122122
"aggregation_statistic": datastream.aggregation_statistic,
123123
"time_aggregation_interval": datastream.time_aggregation_interval,
124124
"time_aggregation_interval_unit_of_measurement": datastream.time_aggregation_interval_unit,
125+
"workspace": {
126+
"id": datastream.thing.workspace.id,
127+
"name": datastream.thing.workspace.name,
128+
"link": datastream.thing.workspace.link,
129+
"is_private": datastream.thing.workspace.is_private
130+
}
125131
}
126132
} for datastream in datastreams
127133
}, count

sta/services/sensorthings/location.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def get_locations(
8484
"elevation_datum": location.elevation_datum,
8585
"state": location.state,
8686
"county": location.county,
87+
"workspace": {
88+
"id": location.thing.workspace.id,
89+
"name": location.thing.workspace.name,
90+
"link": location.thing.workspace.link,
91+
"is_private": location.thing.workspace.is_private
92+
}
8793
},
8894
"thing_ids": [location.thing_id]
8995
} for location in locations

sta/services/sensorthings/observed_property.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ def get_observed_properties(
6565
"properties": {
6666
"variable_code": observed_property.code,
6767
"variable_type": observed_property.observed_property_type,
68+
"workspace": {
69+
"id": observed_property.workspace.id,
70+
"name": observed_property.workspace.name,
71+
"link": observed_property.workspace.link,
72+
"is_private": observed_property.workspace.is_private
73+
} if observed_property.workspace else None
6874
}
6975
} for observed_property in observed_properties
7076
}, count

0 commit comments

Comments
 (0)