class Housekeeping(db.Model): __tablename__ = 'housekeeping' id = db.Column(db.Integer, primary_key=True, autoincrement=True) satellite_mode = db.Column(db.String(32)) battery_voltage = db.Column(db.Float) current_in = db.Column(db.Float) current_out = db.Column(db.Float) no_MCU_resets = db.Column(db.Integer) last_beacon_time = db.Column(db.DateTime, nullable=False) watchdog_1 = db.Column(db.Integer) # 3 watchdogs watchdog_2 = db.Column(db.Integer) watchdog_3 = db.Column(db.Integer) panel_1_current = db.Column(db.Float) # 6 solar panel currents panel_2_current = db.Column(db.Float) panel_3_current = db.Column(db.Float) panel_4_current = db.Column(db.Float) panel_5_current = db.Column(db.Float) panel_6_current = db.Column(db.Float) temp_1 = db.Column(db.Float) # 6 temperatures at diff locations temp_2 = db.Column(db.Float) temp_3 = db.Column(db.Float) temp_4 = db.Column(db.Float) temp_5 = db.Column(db.Float) temp_6 = db.Column(db.Float) # Power channels (probably 24 exactly in a HK log) channels = db.relationship('PowerChannels', backref='housekeeping', lazy=True, cascade='all') def to_json(self): """Returns a dictionary of some selected model attributes """ return { 'id': self.id, 'satellite_mode': self.satellite_mode, 'battery_voltage': self.battery_voltage, 'current_in': self.current_in, 'current_out': self.current_out, 'no_MCU_resets': self.no_MCU_resets, 'last_beacon_time': str(self.last_beacon_time), 'watchdog_1': self.watchdog_1, 'watchdog_2': self.watchdog_2, 'watchdog_3': self.watchdog_3, 'panel_1_current': self.panel_1_current, 'panel_2_current': self.panel_2_current, 'panel_3_current': self.panel_3_current, 'panel_4_current': self.panel_4_current, 'panel_5_current': self.panel_5_current, 'panel_6_current': self.panel_6_current, 'temp_1': self.temp_1, 'temp_2': self.temp_2, 'temp_3': self.temp_3, 'temp_4': self.temp_4, 'temp_5': self.temp_5, 'temp_6': self.temp_6, 'channels': [channel.to_json() for channel in self.channels] }
class FlightSchedules(db.Model): __tablename__ = 'flightschedules' id = db.Column(db.Integer, primary_key=True, autoincrement=True) creation_date = db.Column(db.DateTime, default=datetime.datetime.utcnow) upload_date = db.Column(db.DateTime) execution_time = db.Column(db.DateTime) # status is an integer, where 1=queued, 2=draft, 3=uploaded status = db.Column(db.Integer) commands = db.relationship('FlightScheduleCommands', backref='flightschedule', lazy=True, cascade='all') def to_json(self): """Returns a dictionary of some selected model attributes """ return { 'flightschedule_id': self.id, 'creation_date': str(self.creation_date), 'upload_date': str(self.upload_date), 'status': self.status, 'execution_time': self.execution_time.isoformat(), 'commands': [command.to_json() for command in self.commands] }
class FlightScheduleCommands(db.Model): __tablename__ = 'flightschedulecommands' id = db.Column(db.Integer, primary_key=True, autoincrement=True) command_id = db.Column(db.Integer, db.ForeignKey('telecommands.id'), nullable=False) timestamp = db.Column(db.DateTime) flightschedule_id = db.Column(db.Integer, db.ForeignKey('flightschedules.id'), nullable=False) arguments = db.relationship('FlightScheduleCommandsArgs', backref='flightschedulecommand', lazy=True, cascade='all, delete-orphan') def to_json(self): """Returns a dictionary of some selected model attributes """ return { 'flightschedule_command_id': self.id, 'timestamp': str(self.timestamp), 'command': self.command.to_json(), 'args': [arg.to_json() for arg in self.arguments] }
class Telecommands(db.Model): __tablename__ = 'telecommands' id = db.Column(db.Integer, primary_key=True, autoincrement=True) command_name = db.Column(db.String(64)) num_arguments = db.Column(db.Integer) flightschedulecommands = db.relationship('FlightScheduleCommands', backref='command', lazy=True) is_dangerous = db.Column(db.Boolean) def to_json(self): """Returns a dictionary of some selected model attributes """ return { 'command_id': self.id, 'command_name': self.command_name, 'num_arguments': self.num_arguments, 'is_dangerous': self.is_dangerous }