class Statement_Of_Work(db.Model): id = db.Column(db.Integer, primary_key=True) swarm_id = db.Column(db.Integer, db.ForeignKey('swarm.id'), nullable=False) # Условия deadline = db.Column(db.Integer, nullable=False) # Количественные параметры size = db.Column(db.Integer, nullable=False) min_uniqueness = db.Column(db.Float, nullable=False) max_spam = db.Column(db.Integer, nullable=False) max_water = db.Column(db.Integer, nullable=False) keyword_metric_direct = db.Column(db.Integer, nullable=False) keyword_metric_indirect = db.Column(db.Integer, nullable=False) # Требования к форматированию number_of_para = db.Column(db.Integer) by_num_of_keywords = db.Column(db.Boolean) lists_demanded = db.Column(db.Boolean) headers_demanded = db.Column(db.Boolean) # Ключевые слова keywords = db.Column(db.String(500), nullable=False) meta_info = db.Column(db.String(1000)) def __repr__(self): return f"Statement_Of_Work('{self.deadline}'," \ f"'{self.size}'," \ f"'{self.min_uniqueness}'," \ f"'{self.max_spam}'," \ f"'{self.max_water}'," \ f"'{self.keyword_metric_direct}'," \ f"'{self.keyword_metric_indirect}'," \ f"'{self.number_of_para}'," \ f"'{self.by_num_of_keywords}'," \ f"'{self.lists_demanded}'," \ f"'{self.headers_demanded}'," \ f"'{self.keywords}'," \ f"'{self.meta_info}',)"
class Bee(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(20), unique=True, nullable=False) username = db.Column(db.String(20), unique=True, nullable=False) textru_uid = db.Column(db.String(40)) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) swarms = db.relationship('Swarm', backref='queen', lazy=True) honeycombs = db.relationship('Honeycomb', backref='bee', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return Bee.query.get(user_id) def __repr__(self): return f"Bee('{self.username}', '{self.email}', '{self.image_file}')"
class Transaction(db.Model): id = db.Column(db.Integer, primary_key=True) honeycomb_id = db.Column(db.Integer, db.ForeignKey('honeycomb.id'), nullable=False) sender = db.Column(db.String(60), nullable=False) recipient = db.Column(db.String(60), nullable=False) amount = db.Column(db.Integer, nullable=False) def __repr__(self): return f"Transaction('{self.sender}', '{self.recipient}', '{self.amount}')"
class Honeycomb(db.Model): id = db.Column(db.Integer, primary_key=True) bee_id = db.Column(db.Integer, db.ForeignKey('bee.id'), nullable=False) swarm_id = db.Column(db.Integer, db.ForeignKey('swarm.id'), nullable=False) block_idx = db.Column(db.Integer, nullable=False) timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) transaction = db.relationship('Transaction', backref='honeycomb', lazy=True) honey = db.Column(db.String(500), nullable=False) previous_hash = db.Column(db.String(64), nullable=False) check_integrity = db.Column(db.Boolean, default=True) def __repr__(self): return f"Honeycomb('{self.timestamp}', '{self.honey}', '{self.check_integrity}')"
class Swarm(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_swarmed = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) progress = db.Column(db.Integer, default=0) statement_of_work = db.relationship('Statement_Of_Work', backref="swarm", lazy=True) honeycombs = db.relationship('Honeycomb', backref='sweetspot', lazy=True) queen_id = db.Column(db.Integer, db.ForeignKey('bee.id'), nullable=False) def __repr__(self): return f"Swarm('{self.title}', '{self.date_swarmed}', '{self.progress}')"