Esempio n. 1
0
class User(UserMixin, db.Model):
    __tablename__ = "users"
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(), unique=True, nullable=False)
    password = db.Column(db.LargeBinary(255))
    display_name = db.Column(db.String(), unique=True, nullable=False)

    @staticmethod
    def get_user_by_email(email):
        return User.query.filter_by(email=email).first()

    @staticmethod
    def get_user_by_id(id):
        return User.query.filter_by(id=id).first()

    def __init__(self, email, password, display_name):
        self.email = email
        self.password = bcrypt.generate_password_hash(password)
        self.display_name = display_name
        # for v1.0, set all houses to Godric's.
        self.house_id = House.query.first().id

    def __repr__(self):
        return "User({0}:{1})".format(self.id, self.display_name)

    def set_password(self, password):
        self.password = bcrypt.generate_password_hash(password)

    def check_password(self, password):
        return bcrypt.check_password_hash(self.password, password)
Esempio n. 2
0
class Session(db.Model):
    __tablename__ = 'session'

    id = db.Column(db.Integer, primary_key=True)
    owner = db.Column(db.String())
    repo = db.Column(db.String())
    branch = db.Column(db.String())
    sha = db.Column(db.String())
    project_id = db.Column(db.Integer, db.ForeignKey('project.id'))
    activemembers = db.Column(pg.ARRAY(db.String))

    def addMember(self, member):
        self.activemembers.append(member)

    def removeMember(self, member):
        if member in self.activemembers:
            self.activemembers.remove(member)

    def hasMember(self, member):
        return member in self.activemembers

    def __init__(self, owner, repo, branch, sha, project_id, activemembers):
        self.owner = owner,
        self.repo = repo,
        self.branch = branch,
        self.sha = sha,
        self.project_id = project_id,
        self.activemembers = activemembers

    def __repr__(self):
        return '<id {}>'.format(self.id)

    def serialize(self):
        return {'id': self.id, 'message': self.message, 'author': self.author}
Esempio n. 3
0
class Project(db.Model):
    __tablename__ = 'project'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    description = db.Column(db.String())
    created_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    owner = db.Column(db.String())
    repo = db.Column(db.String())
    branch = db.Column(db.String())
    write_access_users = db.Column(pg.ARRAY(db.String))

    def __init__(self, name, description, owner, repo, branch,
                 write_access_users):
        self.name = name
        self.description = description
        self.owner = owner
        self.repo = repo
        self.branch = branch
        self.write_access_users = write_access_users

    def __repr__(self):
        return '<id {}>'.format(self.id)

    def serialize(self):
        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            # 'created_date': self.created_date,
            'owner': self.owner,
            'repo': self.repo,
            'branch': self.branch,
            'write_access_users': self.write_access_users
        }
Esempio n. 4
0
class HealthData(db.Model):
    __tablename__ = 'healthdata'

    id = db.Column(db.Integer, primary_key=True)
    timestamp = db.Column(db.String())
    userName = db.Column(db.String())
    device_name = db.Column(db.String())
    detail_results = db.Column(JSON)
    result = db.Column(db.String())

    # result_no_stop_words = db.Column(JSON)

    def __init__(self, timestamp, userName, device_name, detail_results):
        self.timestamp = timestamp
        self.userName = userName
        self.device_name = device_name
        self.detail_results = detail_results

    def __repr__(self):
        return '<id {}, timestamp {}, userName, {}, device_name {},\
        detail_results {} >'.format(self.id, self.timestamp, self.userName,
                                    self.device_name, self.detail_results)

    def serialize(self):
        return {
            'id': self.id,
            'timestamp': self.timestamp,
            'userName': self.userName,
            'device_name': self.device_name,
            'detail_results': self.detail_results
        }


# print("End of models")
class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(), unique=True)
    password = db.Column(db.LargeBinary(255))

    @staticmethod
    def get_user_by_email(email):
        return User.query.filter_by(email=email).first()

    @staticmethod
    def get_user_by_id(id):
        return User.query.filter_by(id=id).first()

    def __init__(self, email, password):
        self.email = email
        self.password = bcrypt.generate_password_hash(password)

    def __repr__(self):
        return '<USER:email- {}>'.format(self.email)

    def set_password(self, password):
        self.password = bcrypt.generate_password_hash(password)

    def check_password(self, password):
        return bcrypt.check_password_hash(self.password, password)
Esempio n. 6
0
class Book(db.Model):
    __tablename__ = "books"
    id = db.Column(db.Integer, primary_key=True)
    google_books_id = db.Column(db.String(),
                                index=True,
                                unique=True,
                                nullable=False)
    title = db.Column(db.String(), nullable=False)
    authors = db.Column(db.String())
    thumbnail_link = db.Column(db.String())

    def __repr__(self):
        return "Book({0}:{1})".format(self.id, self.title)

    @staticmethod
    def get_all_books():
        return Book.query.order_by(Book.title).all()

    @staticmethod
    def get_from_google_books_id(google_books_id):
        """
        Returns the Book matching the given google_book_id.
        If none exists, returns None.
        """
        return Book.query.filter_by(google_books_id=google_books_id).first()

    @staticmethod
    def create(**book_params):
        """
        Creates a new Book using the provided **book_params,
        and commits it to the db.
        :returns: The newly-created book
        """
        book = Book(**book_params)
        db.session.add(book)
        db.session.commit()
        return book
Esempio n. 7
0
class Rule(db.Model):
    __tablename__ = 'rules'

    id = db.Column(db.Integer, primary_key=True)
    device_name = db.Column(db.String())
    parameter = db.Column(db.String())
    condition = db.Column(db.String())
    threshold_value = db.Column(db.String())
    result = db.Column(db.String())

    # result_no_stop_words = db.Column(JSON)

    def __init__(self, device_name, parameter, condition, threshold_value,
                 result):
        self.device_name = device_name
        self.parameter = parameter
        self.condition = condition
        self.threshold_value = threshold_value
        self.result = result

    def __repr__(self):
        return '<id {}, device_name {}, parameter, {}, condition {},\
        threshold_value {}, result= {} >'.format(self.id, self.device_name,
                                                 self.parameter,
                                                 self.condition,
                                                 self.threshold_value,
                                                 self.result)

    def serialize(self):
        return {
            'id': self.id,
            'device_name': self.device_name,
            'parameter': self.parameter,
            'condition': self.condition,
            'threshold_value': self.threshold_value,
            'result': self.result
        }
Esempio n. 8
0
class TemFile(db.Model):
    __tablename__ = 'temfile'

    id = db.Column(db.Integer, primary_key=True)
    session_id = db.Column(db.Integer, db.ForeignKey('session.id'))
    path = db.Column(db.String())
    content = db.Column(db.String())
    sha = db.Column(db.String())

    # all of the four most recent changes and their properties
    delta1_start = db.Column(db.Integer)
    delta1_amt = db.Column(db.Integer)
    delta1_data = db.Column(db.Integer)

    delta2_start = db.Column(db.Integer)
    delta2_amt = db.Column(db.Integer)
    delta2_data = db.Column(db.Integer)

    delta3_start = db.Column(db.Integer)
    delta3_amt = db.Column(db.Integer)
    delta3_data = db.Column(db.Integer)

    delta4_start = db.Column(db.Integer)
    delta4_amt = db.Column(db.Integer)
    delta4_data = db.Column(db.Integer)

    # 5 most recent md5 file hashes
    hash1 = db.Column(db.String())
    hash2 = db.Column(db.String())
    hash3 = db.Column(db.String())
    hash4 = db.Column(db.String())
    hash5 = db.Column(db.String())

    # whether the file was moved, deleted, edited, or renamed
    # deleted    = db.Column(db.Boolean, default = False)
    changed = db.Column(db.Boolean, default=False)  # implement this
    loaded = db.Column(db.Boolean, default=False)

    def load(self):
        self.loaded = True

    def delete(self):
        self.deleted = True

    def change(self):
        self.changed = True

    def addHash(self, md5, delta):  #delta['start'],delta['amt'],delta['msg']
        def process(delt_start, delt_amt, delt_data):
            if (delt_start + delt_amt <= delta['start']
                    or delta['start'] + delta['amt'] <= delt_start):
                if (delt_start < delta['start']):
                    delta['start'] += delt_data
                return True

        ## find the matching md5 in the database
        # if not found, return false
        prev = False
        if md5 == self.hash5:
            if not process(self.delta4_start, self.delta4_amt,
                           self.delta4_data):
                return False
            prev = True
        if md5 == self.hash4 or prev:
            if not process(self.delta3_start, self.delta3_amt,
                           self.delta3_data):
                return False
            prev = True
        if md5 == self.hash3 or prev:
            if not process(self.delta2_start, self.delta2_amt,
                           self.delta2_data):
                return False
            prev = True
        if md5 == self.hash2 or prev:
            if not process(self.delta1_start, self.delta1_amt,
                           self.delta1_data):
                return False
            prev = True
        if not (prev or md5 == self.hash1): return False
        ## if found update and shift
        self.content = self.content[:delta['start']] + delta[
            'msg'] + self.content[delta['start'] + delta['amt']:]
        hash = hashlib.md5(self.content.encode("utf-8")).hexdigest()

        # shift hashes down one
        self.hash5 = self.hash4
        self.hash4 = self.hash3
        self.hash3 = self.hash2
        self.hash2 = self.hash1
        self.hash1 = hash
        if self.hash1 == self.hash2: self.hash2 = ""
        if self.hash1 == self.hash3: self.hash3 = ""
        if self.hash1 == self.hash4: self.hash4 = ""
        if self.hash1 == self.hash5: self.hash5 = ""

        # shift deltas down one
        self.delta4_start = self.delta3_start
        self.delta4_amt = self.delta3_amt
        self.delta4_data = self.delta3_data
        self.delta3_start = self.delta2_start
        self.delta3_amt = self.delta2_amt
        self.delta3_data = self.delta2_data
        self.delta2_start = self.delta1_start
        self.delta2_amt = self.delta1_amt
        self.delta2_data = self.delta1_data
        self.delta1_start = delta['start']
        self.delta1_amt = delta['amt']
        self.delta1_data = len(delta['msg']) - delta['amt']
        return True

    def __init__(self, session_id, path, content, sha, md5=""):
        self.session_id = session_id
        self.path = path
        self.content = content
        self.sha = sha
        self.hash1 = md5
        self.hash2 = ""
        self.hash3 = ""
        self.hash4 = ""
        self.hash5 = ""

    def __repr__(self):
        return '<id {}>'.format(self.id)
Esempio n. 9
0
class TemFolder(db.Model):
    __tablename__ = 'temfolder'

    id = db.Column(db.Integer, primary_key=True)
    session_id = db.Column(db.Integer, db.ForeignKey('session.id'))
    path = db.Column(db.String())