server/fgs/model.py

78 lines
2.8 KiB
Python

from . import db
import bcrypt
class Collar(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
active = db.Column(db.Boolean)
data_points = db.relationship('DataPoint')
boundary = db.relationship("BoundingBox", uselist=False)
class DataPoint(db.Model):
id = db.Column(db.Integer, primary_key=True)
collar_id = db.Column(db.Integer, db.ForeignKey('collar.id'))
longitude = db.Column(db.Float(precision=10))
latitude = db.Column(db.Float(precision=10))
battery_level = db.Column(db.Integer)
datetime = db.Column(db.DateTime)
outside = db.Column(db.Boolean)
def to_dict(self):
return {'longitude': self.longitude,
'latitude': self.latitude,
'battery_level': self.battery_level,
'datetime': self.datetime,
'outside': self.outside
}
class StimulusActivation(db.Model):
id = db.Column(db.Integer, primary_key=True)
collar_id = db.Column(db.Integer, db.ForeignKey('collar.id'))
longitude = db.Column(db.Float(precision=10))
latitude = db.Column(db.Float(precision=10))
volume_level = db.Column(db.Integer)
voltage_level = db.Column(db.Integer)
datetime = db.Column(db.DateTime)
class BoundingBox(db.Model):
id = db.Column(db.Integer, primary_key=True)
collar_id = db.Column(db.Integer, db.ForeignKey('collar.id'))
num_points = db.Column(db.Integer)
coord0x = db.Column(db.Float(precision=10))
coord0y = db.Column(db.Float(precision=10))
coord1x = db.Column(db.Float(precision=10))
coord1y = db.Column(db.Float(precision=10))
coord2x = db.Column(db.Float(precision=10))
coord2y = db.Column(db.Float(precision=10))
coord3x = db.Column(db.Float(precision=10))
coord3y = db.Column(db.Float(precision=10))
coord4x = db.Column(db.Float(precision=10))
coord4y = db.Column(db.Float(precision=10))
coord5x = db.Column(db.Float(precision=10))
coord5y = db.Column(db.Float(precision=10))
coord6x = db.Column(db.Float(precision=10))
coord6y = db.Column(db.Float(precision=10))
coord7x = db.Column(db.Float(precision=10))
coord7y = db.Column(db.Float(precision=10))
coord8x = db.Column(db.Float(precision=10))
coord8y = db.Column(db.Float(precision=10))
coord9x = db.Column(db.Float(precision=10))
coord9y = db.Column(db.Float(precision=10))
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String)
password_hash = db.Column(db.String)
def get_password(self):
return self.password_hash
def set_password(self, password):
self.password_hash = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
def check_password(self, password):
return bcrypt.checkpw(password.encode(), self.password_hash)
password = property(get_password, set_password)