-
Notifications
You must be signed in to change notification settings - Fork 14
/
models.py
194 lines (147 loc) · 6.65 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from django.db import models
import uuid
from django.utils import timezone
class GFConfig(models.Model):
"""
Grafana configs
"""
gf_name = models.CharField(max_length=64)
gf_host = models.CharField(max_length=128)
gf_token = models.CharField(
max_length=256
) # token only, without the prefix "Bearer "
gf_dashboard_uid = models.CharField(max_length=64)
gf_db_host = models.CharField(max_length=128)
gf_db_grafana_name = models.CharField(max_length=64)
gf_db_name = models.CharField(max_length=64)
gf_db_username = models.CharField(max_length=64)
gf_db_pw = models.CharField(max_length=256)
gf_current = models.BooleanField(default=False, blank=True)
class AGEvent(models.Model):
"""This model stores the information about events. When a new event is created,
a UUID4-typed event_uuid will be assigned to this event and also store the current
date for this event. """
event_uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
event_name = models.CharField(max_length=40, blank=True)
event_date = models.DateTimeField(default=timezone.now)
event_description = models.CharField(max_length=100, null=False, blank=True)
event_location = models.CharField(max_length=100, null=False, blank=True)
class TemperatureSensor(models.Model):
"""This model represents the Temperature sensor that we expect to
be potentially available in the future in the NYU Motorsports
Racing vehicle."""
created_at = models.DateTimeField()
# Oil temperature panel, measured in fahrenheit degrees
temperature = models.FloatField(default=0)
def __str__(self): # pragma: no cover
return TemperatureSensor.__name__
class AccelerationSensor(models.Model):
"""This model represents the Acceleration sensors that we expect to
be potentially available in the future in the NYU Motorsports
Racing vehicle."""
created_at = models.DateTimeField()
# Acceleration Panel, measured in meters/second
acceleration_x = models.FloatField(default=0)
acceleration_y = models.FloatField(default=0)
acceleration_z = models.FloatField(default=0)
def __str__(self): # pragma: no cover
return AccelerationSensor.__name__
class WheelSpeedSensor(models.Model):
"""This model represents the Wheel Speed sensors that we expect to
be potentially available in the future in the NYU Motorsports
Racing vehicle."""
created_at = models.DateTimeField()
# Wheel Speed Panel for each of the four wheels
# measured in meters/second
wheel_speed_fr = models.FloatField(default=0)
wheel_speed_fl = models.FloatField(default=0)
wheel_speed_br = models.FloatField(default=0)
wheel_speed_bl = models.FloatField(default=0)
def __str__(self): # pragma: no cover
return WheelSpeedSensor.__name__
class SuspensionSensor(models.Model):
"""This model represents the Suspension sensors that we expect to
be potentially available in the future in the NYU Motorsports
Racing vehicle."""
created_at = models.DateTimeField()
# Suspension/Compression Panel for each of the four wheels
# measured in centimeters
suspension_fr = models.FloatField(default=0)
suspension_fl = models.FloatField(default=0)
suspension_br = models.FloatField(default=0)
suspension_bl = models.FloatField(default=0)
def __str__(self): # pragma: no cover
return SuspensionSensor.__name__
class FuelLevelSensor(models.Model):
"""This model represents the Fuel Level sensor that we expect to
be potentially available in the future in the NYU Motorsports
Racing vehicle."""
created_at = models.DateTimeField()
# Fuel Supply Panel
# measured in liters
current_fuel_level = models.FloatField(default=0)
def __str__(self): # pragma: no cover
return FuelLevelSensor.__name__
class EventCodeAccess(models.Model):
"""This model stores the information about events. When an event is
ongoing, if a new event_code is added and the enabled property is
True, then use of the Telemetry app will be restricted to those
that know the event_code."""
event_code = models.CharField(max_length=8)
enabled = models.BooleanField()
def __str__(self): # pragma: no cover
return EventCodeAccess.__name__
class Events(models.Model):
"""This model stores the information about events. When a new event is created,
an auto-incremented event_id will be assigned to this event and also store the current
date and location for this event. """
event_id = models.AutoField(primary_key=True)
event_name = models.CharField(max_length=40, unique=True, null=False, blank=False)
event_date = models.DateTimeField()
event_loc_lat = models.FloatField(default=0, blank=True)
event_loc_lon = models.FloatField(default=0, blank=True)
event_description = models.CharField(max_length=100, null=True, blank=True)
def __str__(self):
return Events.__name__
class Sensor(models.Model):
"""This model stores the information about sensor. When a new sensor is created,
an auto-incremented sensor_id will be assigned to this event and also store the name
and description for this sensor . """
sensor_id = models.AutoField(primary_key=True)
sensor_name = models.CharField(max_length=40, unique=True, null=False, blank=False)
sensor_description = models.CharField(max_length=100, null=True, blank=True)
def __str__(self):
return Sensor.__name__
class Field(models.Model):
"""This model stores the information about fields of sensors. """
field_id = models.IntegerField(unique=True)
sensor_id = models.ForeignKey(
Sensor,
related_name="sensor_field",
to_field="sensor_id",
on_delete=models.CASCADE,
)
field_name = models.CharField(max_length=40, null=False, blank=False)
class Meta:
unique_together = (("field_id", "sensor_id"),)
def __str__(self):
return Field.__name__
class General_data(models.Model):
event_id = models.OneToOneField(
Events, related_name="event_data", on_delete=models.CASCADE, to_field="event_id"
)
sensor_id = models.OneToOneField(
Sensor,
related_name="sensor_data",
on_delete=models.CASCADE,
to_field="sensor_id",
)
field_id = models.OneToOneField(
Field, related_name="field_data", on_delete=models.CASCADE, to_field="field_id"
)
stored_at_time = models.DateTimeField() # index
data_value = models.FloatField(default=0)
class Meta:
unique_together = (("event_id", "sensor_id", "field_id"),)
def __str__(self):
return General_data.__name__