1
0
Fork 0
A REST-API built with Flask and Python. Its main purpose is to receive the readings from the light meters welding booths in the Ritherdon factory and make them available for consumption by the relay-controllers in the gallery.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

50 lines
1.6 KiB

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