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 devices is six. They must keep their info. separate from each other. This means a table in the database for each device. 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 devices it uses, this will probably need to be refactored. ''' class Device1(db.Model): __tablename__ = "device1" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow) status = db.Column(db.String) class Device1Schema(ma.ModelSchema): class Meta: model = Device1 sqla_session = db.session class Device2(db.Model): __tablename__ = "device2" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow) status = db.Column(db.String) class Device2Schema(ma.ModelSchema): class Meta: model = Device2 sqla_session = db.session class Device3(db.Model): __tablename__ = "device3" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow) status = db.Column(db.String) class Device3Schema(ma.ModelSchema): class Meta: model = Device3 sqla_session = db.session class Device4(db.Model): __tablename__ = "device4" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow) status = db.Column(db.String) class Device4Schema(ma.ModelSchema): class Meta: model = Device4 sqla_session = db.session class Device5(db.Model): __tablename__ = "device5" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow) status = db.Column(db.String) class Device5Schema(ma.ModelSchema): class Meta: model = Device5 sqla_session = db.session class Device6(db.Model): __tablename__ = "device6" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow) status = db.Column(db.String) class Device6Schema(ma.ModelSchema): class Meta: model = Device6 sqla_session = db.session