-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
51 lines (39 loc) · 1.16 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import datetime
from tortoise.models import Model
from tortoise import fields
from pydantic import BaseModel
class GeigerCounter(Model):
"""
A geiger counter.
"""
id = fields.IntField(pk=True)
geigerc_id = fields.CharField(max_length=255)
owner_id = fields.CharField(max_length=255)
class Meta:
unique_together = (("geigerc_id", "owner_id"),)
def __str__(self):
return f"{self.owner_id}-{self.counter_id}"
class Measurement(Model):
"""
One measurement made by a geiger counter
"""
id = fields.IntField(pk=True)
counter = fields.ForeignKeyField(
"models.GeigerCounter", related_name="measurements"
)
cpm = fields.IntField(description="counts per minute")
acpm = fields.IntField(description="Average counts per minute")
usv = fields.FloatField(description="Value in micro sieverts")
time = fields.DatetimeField(
auto_now_add=True, description="Date of the measurement"
)
class ApiMeasurement(BaseModel):
"""
pydantic model for measurement
"""
class Config:
orm_mode = True
cpm: int
acpm: int
usv: float
time: datetime.datetime