|
1
|
|
|
""" |
|
2
|
|
|
Model for section correlation to sensor levels. |
|
3
|
|
|
""" |
|
4
|
|
|
from flask import url_for |
|
5
|
|
|
|
|
6
|
|
|
from app.database import db |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class Correlation(db.Model): |
|
10
|
|
|
""" |
|
11
|
|
|
Connects sections to sensors with extra data about values and how fast they |
|
12
|
|
|
should change. |
|
13
|
|
|
|
|
14
|
|
|
Arguments: |
|
15
|
|
|
section_id (int): ``Section``.id for the ``Section`` that this correlation is for |
|
16
|
|
|
section: gives a ``Section`` object from the section_id |
|
17
|
|
|
sensor_id (int): ``Sensor``.id for the ``Sensor`` that is correlation is for |
|
18
|
|
|
sensor: gives a ``Sensor`` object from the sensor_id |
|
19
|
|
|
minimum (float): The minimum level according to the Sensor that can float a boat |
|
20
|
|
|
low (float): A normal sane low level. Below this is ELF territory. |
|
21
|
|
|
medium (float): The low end of a medium level. |
|
22
|
|
|
high (float): The top of a medium level, and starting to get padded out. |
|
23
|
|
|
huge (float): The difference between high and scary. |
|
24
|
|
|
trend_slope (float): How fast should the sensor be changing in order for us to be interested? |
|
25
|
|
|
trend_samples (int): How many samples should it be changing over for us to be interested? |
|
26
|
|
|
description (text): At some point in the future will probably display \ |
|
27
|
|
|
the description on the section page with the correlation. \ |
|
28
|
|
|
Can contain HTML or Markdown within reason. |
|
29
|
|
|
backend_notes (text): Admin/Gage Manager information about the gage |
|
30
|
|
|
|
|
31
|
|
|
""" |
|
32
|
|
|
# Needed to be an http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#association-object |
|
33
|
|
|
__tablename__ = 'correlations' |
|
34
|
|
|
section_id = db.Column(db.Integer, db.ForeignKey('sections.id'), primary_key=True, index=True) |
|
35
|
|
|
section = db.relationship('Section', backref='correlations') |
|
36
|
|
|
|
|
37
|
|
|
sensor_id = db.Column(db.Integer, db.ForeignKey('sensors.id'), primary_key=True, index=True) |
|
38
|
|
|
sensor = db.relationship('Sensor', backref='correlations') |
|
39
|
|
|
|
|
40
|
|
|
minimum = db.Column(db.Float) |
|
41
|
|
|
low = db.Column(db.Float) |
|
42
|
|
|
medium = db.Column(db.Float) |
|
43
|
|
|
high = db.Column(db.Float) |
|
44
|
|
|
huge = db.Column(db.Float) |
|
45
|
|
|
trend_slope = db.Column(db.Float) |
|
46
|
|
|
trend_samples = db.Column(db.Integer) |
|
47
|
|
|
description = db.Column(db.Text) |
|
48
|
|
|
backend_notes = db.Column(db.Text) |
|
49
|
|
|
|
|
50
|
|
|
def section_json(self): |
|
51
|
|
|
""" |
|
52
|
|
|
Returns a json object |
|
53
|
|
|
""" |
|
54
|
|
|
return { |
|
55
|
|
|
'gage_html': url_for('main.gagepage', |
|
56
|
|
|
slug=self.sensor.gage.slug, |
|
57
|
|
|
_external=True), |
|
58
|
|
|
'sensor': self.sensor.to_gage_json(), |
|
59
|
|
|
'gage_name': self.sensor.gage.name |
|
60
|
|
|
} |