server/fgs/model.py

49 lines
1.6 KiB
Python
Raw Normal View History

2020-02-01 14:29:56 -08:00
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')
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)
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)
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)