You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
3 years ago
|
from datetime import datetime
|
||
|
from config import db, ma
|
||
|
|
||
|
'''
|
||
|
Note on Duplication Levels
|
||
|
======================================================================
|
||
|
While the code in this file seems very duplicated, it is just the
|
||
|
result of using SQL-Alchemy (ORM) and the repetitive nature of the
|
||
|
project as a whole. At the time of writing, the expected amount of
|
||
|
light meters is three and each one must take their own readings.
|
||
|
But, they must keep their readings separate from each other. This
|
||
|
means a table in the database for each meter. This is the main cause
|
||
|
for the repetitive/duplicated code.
|
||
|
Because this project has fixed requirements, the hard-coded nature is
|
||
|
a trade-off because of this. If the project increases the amount of
|
||
|
light meters it uses, this will probably need to be refactored.
|
||
|
'''
|
||
|
|
||
|
class Meter1(db.Model):
|
||
|
__tablename__ = "meter1"
|
||
|
id = db.Column(db.Integer, primary_key=True)
|
||
|
time = db.Column(db.DateTime, default=datetime.utcnow)
|
||
|
reading = db.Column(db.Integer)
|
||
|
|
||
|
class Meter1Schema(ma.ModelSchema):
|
||
|
class Meta:
|
||
|
model = Meter1
|
||
|
sqla_session = db.session
|
||
|
|
||
|
class Meter2(db.Model):
|
||
|
__tablename__ = "meter2"
|
||
|
id = db.Column(db.Integer, primary_key=True)
|
||
|
time = db.Column(db.DateTime)
|
||
|
reading = db.Column(db.Integer)
|
||
|
|
||
|
class Meter2Schema(ma.ModelSchema):
|
||
|
class Meta:
|
||
|
model = Meter2
|
||
|
sqla_session = db.session
|
||
|
|
||
|
class Meter3(db.Model):
|
||
|
__tablename__ = "meter3"
|
||
|
id = db.Column(db.Integer, primary_key=True)
|
||
|
time = db.Column(db.DateTime)
|
||
|
reading = db.Column(db.Integer)
|
||
|
|
||
|
class Meter3Schema(ma.ModelSchema):
|
||
|
class Meta:
|
||
|
model = Meter3
|
||
|
sqla_session = db.session
|