class Shot(BaseModel): id = AutoField() game_id = IntegerField() game_event_id = CharField() player_id = ForeignKeyField(Player, backref="shots") distance = IntegerField() x = IntegerField() y = IntegerField() made = BooleanField() franchise_id = ForeignKeyField(Franchise, backref="shots") period = SmallIntegerField() minutes_remaining = SmallIntegerField() seconds_remaining = SmallIntegerField() action_type = CharField() shot_type = CharField() shot_zone_basic = CharField() shot_zone_area = CharField() shot_zone_range = CharField() game_date = IntegerField() season_type = SmallIntegerField() home_franchise = ForeignKeyField(Franchise, backref="shots_as_home") visitor_franchise = ForeignKeyField(Franchise, backref="shots_as_visitor") class Meta: table_name = "shots"
class Account(BaseModel): """Database model for account""" auth_service = CharField() username = CharField(primary_key=True) password = CharField() last_modified = DateTimeField() system_id = CharField() level = SmallIntegerField() banned = BooleanField() shadowbanned = BooleanField() lures = SmallIntegerField() def get_status(self): """Returns the status of the account, i.e. 'good', 'only blind' or 'banned'""" if not self.banned and not self.shadowbanned: return 'good' elif not self.banned and self.shadowbanned: return 'only blind' elif self.banned: return 'banned' else: return 'unknown' def __repr__(self): return "%s (Lv. %s): %s" % (self.username, self.level, self.get_status())
class Inventory(BaseModel): object_id = BigIntegerField() lot = SmallIntegerField() character = ForeignKeyField(Character, backref='items') bound = BooleanField(default=False) amount = SmallIntegerField(default=1) slot = SmallIntegerField()
def database_migrate(db, old_ver): # Update database schema version. Versions.update(val=db_schema_version).where( Versions.key == 'schema_version').execute() log.info('Detected database version %i, updating to %i...', old_ver, db_schema_version) # Perform migrations here. migrator = MySQLMigrator(db) if old_ver < 17: migrate( migrator.add_column('pokemon', 'form', SmallIntegerField(null=True))) if old_ver < 18: migrate( migrator.add_column('pokemon', 'cp', SmallIntegerField(null=True))) if old_ver < 19: migrate( migrator.add_column('pokemon', 'cp_multiplier', FloatField(null=True))) if old_ver < 20: migrate( migrator.drop_column('gym', 'gym_points'), migrator.add_column('gym', 'slots_available', SmallIntegerField(null=False, default=0)), migrator.add_column('gymmember', 'cp_decayed', SmallIntegerField(null=False, default=0)), migrator.add_column( 'gymmember', 'deployment_time', DateTimeField(null=False, default=datetime.utcnow())), migrator.add_column('gym', 'total_cp', SmallIntegerField(null=False, default=0)))
class PoolTransaction(Model): id = CharField(max_length=64, primary_key=True) version = SmallIntegerField() sequence = SmallIntegerField() timestamp = IntegerField(index=True) sender_public_key = CharField(max_length=66, index=True) recipient_id = CharField(max_length=66, null=True, index=True) type = SmallIntegerField() vendor_field = CharField(max_length=255, null=True) amount = BigIntegerField() fee = BigIntegerField() asset = JSONField(null=True) expires_at = IntegerField(index=True) class Meta: table_name = "pool_transactions" @classmethod def from_crypto(cls, transaction): # TODO: figure out how to improve this model = cls() model.id = transaction.id model.version = transaction.version model.sequence = transaction.sequence model.timestamp = transaction.timestamp model.sender_public_key = transaction.sender_public_key model.recipient_id = transaction.recipient_id model.type = transaction.type model.vendor_field = transaction.vendor_field model.amount = transaction.amount model.fee = transaction.fee model.asset = transaction.asset model.expires_at = transaction.calculate_expires_at( config.pool["max_transaction_age"]) return model
class PriorityPublication(Model): title = CharField(max_length=256) content = TextField() priority = SmallIntegerField(default=4) state = SmallIntegerField(default=0) class Meta: database = instance.get_store()
class monsters(BaseModel): human_id = CharField(index=True, max_length=30) pokemon_id = SmallIntegerField(index=True) distance = IntegerField(index=True) min_iv = SmallIntegerField(index=True) class Meta: order_by = ('id',)
class Transaction(Model): id = CharField(max_length=64, primary_key=True) version = SmallIntegerField() block_id = ForeignKeyField(Block) sequence = SmallIntegerField() timestamp = IntegerField(index=True) sender_public_key = CharField(max_length=66, index=True) recipient_id = CharField(max_length=66, null=True, index=True) type = SmallIntegerField() vendor_field = CharField(max_length=255, null=True) amount = BigIntegerField() fee = BigIntegerField() serialized = BytesField() asset = JSONField(null=True) class Meta: table_name = "transactions" indexes = (( ("sender_public_key", "recipient_id", "vendor_field", "timestamp"), False, ), ) @classmethod def from_crypto(cls, transaction): # TODO: figure out how to improve this model = cls() model.id = transaction.id model.version = transaction.version model.block_id = transaction.block_id model.sequence = transaction.sequence model.timestamp = transaction.timestamp model.sender_public_key = transaction.sender_public_key model.recipient_id = transaction.recipient_id model.type = transaction.type model.vendor_field = transaction.vendor_field model.amount = transaction.amount model.fee = transaction.fee model.asset = transaction.asset # TODO: probably obsolete serialized = transaction.serialize() model.serialized = serialized return model @staticmethod def statistics(): """Returns statistics about Blocks table """ stats = Transaction.select( fn.COUNT(Transaction.id), fn.SUM(Transaction.fee), fn.SUM(Transaction.amount), ).scalar(as_tuple=True) return { "transactions_count": stats[0], "total_fee": stats[1], "total_amount": stats[2], }
class User(BaseModel): access_token = FixedCharField(max_length=36, verbose_name='用户授权令牌', null=False) aliId = IntegerField(null=False, verbose_name='阿里巴巴集团统一的id') refresh_token = FixedCharField(max_length=36, null=False, verbose_name='用户刷新令牌') resource_owner = FixedCharField(max_length=25, null=False, verbose_name='登录id') refresh_token_timeout = FixedCharField(null=False, max_length=22, verbose_name='用户刷新令牌到期时间') # 主键 memberId = FixedCharField(max_length=22, null=False, primary_key=True, verbose_name='会员接口id') addressLocation = FixedCharField(max_length=35, verbose_name='定位地址', null=False) buyKeywords = FixedCharField(max_length=25, verbose_name='购买关键字', null=False) buyRate = SmallIntegerField(null=False, verbose_name='购买指数') categoryId = SmallIntegerField(null=False, verbose_name='类目ID') categoryName = FixedCharField(null=False, max_length=15, verbose_name='类目名称') companyName = FixedCharField(null=False, max_length=20, verbose_name='公司名称') createDate = FixedCharField(null=False, max_length=22, verbose_name='创建账号时间') domainInPlatforms = FixedCharField(null=False, max_length=255, verbose_name='账号下店铺') homepageUrl = FixedCharField(null=False, max_length=30, verbose_name='首页url') memberBizType = FixedCharField(null=False, max_length=15, verbose_name='账号业务类型') phoneNo = FixedCharField(null=False, max_length=19, verbose_name='联系电话') product = FixedCharField(null=False, max_length=100, verbose_name='产品') saleKeywords = FixedCharField(null=False, max_length=36, verbose_name='销售关键词') sellerName = FixedCharField(null=False, max_length=15, verbose_name='卖家姓名') shopUrl = FixedCharField(null=False, max_length=60, verbose_name='店铺url') supplierName = FixedCharField(null=False, max_length=20, verbose_name='供应商名字') tpYear = SmallIntegerField(null=False, verbose_name='淘宝年龄') trustScore = SmallIntegerField(null=False, verbose_name='诚信分数') update_time = DateTimeField(null=False, verbose_name='更新时间')
class Game(DeepFieldModel): name_id = FixedCharField(12, unique=True) local_start_time = TimeField("%H:%M", null=True) time_of_day = SmallIntegerField(null=True) field_type = SmallIntegerField(null=True) date = DateField() venue_id = ForeignKeyField(Venue, null=True) home_team_id = ForeignKeyField(Team) away_team_id = ForeignKeyField(Team)
class Weather(BaseModel): s2_cell_id = Utf8mb4CharField(primary_key=True, max_length=50) latitude = DoubleField() longitude = DoubleField() cloud_level = SmallIntegerField(null=True, index=True, default=0) rain_level = SmallIntegerField(null=True, index=True, default=0) wind_level = SmallIntegerField(null=True, index=True, default=0) snow_level = SmallIntegerField(null=True, index=True, default=0) fog_level = SmallIntegerField(null=True, index=True, default=0) wind_direction = SmallIntegerField(null=True, index=True, default=0) gameplay_weather = SmallIntegerField(null=True, index=True, default=0) severity = SmallIntegerField(null=True, index=True, default=0) warn_weather = SmallIntegerField(null=True, index=True, default=0) world_time = SmallIntegerField(null=True, index=True, default=0) last_updated = DateTimeField(default=datetime.utcnow, null=True, index=True) @staticmethod def get_weathers(): query = Weather.select().dicts() weathers = [] for w in query: weathers.append(w) return weathers @staticmethod def get_weather_by_location(swLat, swLng, neLat, neLng, alert): # We can filter by the center of a cell, this deltas can expand # the viewport bounds # So cells with center outside the viewport, but close to it # can be rendered # otherwise edges of cells that intersects with viewport # won't be rendered lat_delta = 0.15 lng_delta = 0.4 if not alert: query = Weather.select().where( (Weather.latitude >= float(swLat) - lat_delta) & (Weather.longitude >= float(swLng) - lng_delta) & (Weather.latitude <= float(neLat) + lat_delta) & (Weather.longitude <= float(neLng) + lng_delta)).dicts() else: query = Weather.select().where( (Weather.latitude >= float(swLat) - lat_delta) & (Weather.longitude >= float(swLng) - lng_delta) & (Weather.latitude <= float(neLat) + lat_delta) & (Weather.longitude <= float(neLng) + lng_delta) & (Weather.severity.is_null(False))).dicts() weathers = [] for w in query: weathers.append(w) return weathers
class Play(DeepFieldModel): game_id = ForeignKeyField(Game) inning_half = SmallIntegerField() start_outs = SmallIntegerField() start_on_base = SmallIntegerField() play_num = SmallIntegerField() desc = CharField() pitch_ct = CharField(null=True) batter_id = ForeignKeyField(Player) pitcher_id = ForeignKeyField(Player)
class Rules(BaseModel): rule_num = SmallIntegerField() before_variable = CharField() before_not = SmallIntegerField(default=0) before_value = CharField() and_field = SmallIntegerField(default=0) or_field = SmallIntegerField(default=0) after_variable = CharField(null=True) after_not = SmallIntegerField(null=True) after_value = CharField(null=True)
class Offer_Keyword_7days(BaseModel): id = PrimaryKeyField(verbose_name='主键id') keyword = CharField(max_length=10, null=False, verbose_name='关键词') category = CharField(max_length=10, null=False, verbose_name='关键词类目') recommendTags = CharField(max_length=30, null=False, verbose_name='推荐理由') countBuyer = SmallIntegerField(null=False, verbose_name='竞争指数') leftAvgClick7days = FloatField(null=False, verbose_name='点击率') leftAvgPV7days = FloatField(null=False, verbose_name='平均出价') searchAvg7days = SmallIntegerField(null=False, verbose_name='展示指数') update_time = DateTimeField(null=False, verbose_name='更新时间')
class Token(Model): address = FixedCharField(max_length=42, unique=True) symbol = CharField() icon = CharField(null=True) # emoji decimals = SmallIntegerField() default_slippage = SmallIntegerField() effective_buy_price = CharField(null=True) class Meta: database = db
class Pokemon(BaseModel): # We are base64 encoding the ids delivered by the api # because they are too big for sqlite to handle. encounter_id = Utf8mb4CharField(primary_key=True, max_length=50) spawnpoint_id = Utf8mb4CharField(index=True) pokemon_id = SmallIntegerField(index=True) latitude = DoubleField() longitude = DoubleField() disappear_time = DateTimeField(index=True) individual_attack = SmallIntegerField(null=True) individual_defense = SmallIntegerField(null=True) individual_stamina = SmallIntegerField(null=True) move_1 = SmallIntegerField(null=True) move_2 = SmallIntegerField(null=True) cp = SmallIntegerField(null=True) cp_multiplier = FloatField(null=True) weight = FloatField(null=True) height = FloatField(null=True) gender = SmallIntegerField(null=True) form = SmallIntegerField(null=True) last_modified = DateTimeField(null=True, index=True, default=datetime.utcnow) class Meta: indexes = ((('latitude', 'longitude'), False), )
class Raid(BaseModel): gym_id = Utf8mb4CharField(primary_key=True, max_length=50) level = IntegerField(index=True) spawn = DateTimeField(index=True) start = DateTimeField(index=True) end = DateTimeField(index=True) pokemon_id = SmallIntegerField(null=True) cp = IntegerField(null=True) move_1 = SmallIntegerField(null=True) move_2 = SmallIntegerField(null=True) last_scanned = DateTimeField(default=datetime.utcnow, index=True)
class User(BaseModel): id = BigIntegerField(primary_key=True) username = TextField() discriminator = SmallIntegerField() user_rank = SmallIntegerField(default=0) class Meta: db_table = 'users' indexes = ((('id', 'username', 'discriminator'), True), )
class Reserv(AioModel): id = PrimaryKeyField() status = CharField(max_length=301, index=True, unique=True) author = SmallIntegerField() employee = SmallIntegerField() device = ForeignKeyField(Devices, to_field='id') day = CharField(max_length=20) created = CharField(max_length=25, null=True) class Meta: database = db
class KrillConfig(Model): id = AutoField() guild = ForeignKeyField(Guild, backref='krill_config', unique=True) return_home_freq = SmallIntegerField(default=0) shadow_roll_freq = SmallIntegerField(default=0) krill_rider_freq = SmallIntegerField(default=0) crab_freq = SmallIntegerField(default=0) allow_text = BooleanField(default=True) monster_duration = SmallIntegerField(default=21600) class Meta: database = connection
class Trivia(BaseModel): guild_id = BigIntegerField() user_id = BigIntegerField() correct_answers = SmallIntegerField() incorrect_answers = SmallIntegerField() points = SmallIntegerField() # Small should be good.. right? :thonk: class Meta: db_table = 'trivia' indexes = ((('guild_id', 'user_id'), False), )
class CategoryDAO(Model): class Meta: database = mysql_db table_name = 'article_category' id = SmallIntegerField(5) article_id = SmallIntegerField(5) category_text = CharField(100) category_hash = BigIntegerField(16) create_time = DateTimeField(default=datetime.datetime.now) update_time = DateTimeField(default=datetime.datetime.now) @classmethod def create_category(cls, data): """ data is a list of dict @rtype is a list of tuple like (dao, bool) """ daos = [] with cls._meta.database.atomic(): for data_dict in data: daos.append(cls.get_or_create(**data_dict)) return daos @classmethod def get_article_categories(cls, article_id): return list(cls.select().where(cls.article_id == article_id).execute()) @classmethod def get_all_categories(cls): """rtype list(namedtuples)""" return list( cls.select(cls.category_text, fn.COUNT(cls.id).alias('n_category')).group_by( cls.category_hash).namedtuples()) @classmethod def get_category_all_articles(cls, category_text): category_hash = get_hashed_value(category_text) return list( cls.select().where(cls.category_hash == category_hash).execute()) @classmethod def update_category(cls, old_category, category_text): old_hash = get_hashed_value(old_category) daos = cls.select().where(cls.category_hash == old_hash).execute() if not daos: return new_hash = get_hashed_value(category_text) map( lambda dao: dao.update(category_text=category_text, category_hash=new_hash).execute(), daos)
class File(BaseModel): class Meta: table_name = "files" author_id = IntegerField(null=True) title = CharField(max_length=128) date = DateTimeField() description = CharField(max_length=255, null=True) file_type = SmallIntegerField() path = CharField(max_length=255) access_rights = SmallIntegerField(default=0) downloads_count = SmallIntegerField(default=0) deleted = SmallIntegerField(default=0)
class Course(BaseModel): class Meta: table_name = "courses" cursus = ForeignKeyField(Cursus, null=True, backref="courses") semester = SmallIntegerField(default=0) name = CharField(max_length=64) short_name = CharField(max_length=16) ECTS = FloatField(default=3) description = TextField() use_latex = SmallIntegerField(default=0) use_sourcecode = SmallIntegerField(default=1) deleted = SmallIntegerField(default=0)
class Device(BaseModel): name = CharField() device_type = IntegerField() mac = CharField() host = CharField(column_name='ipaddress') state = SmallIntegerField(column_name='state', default=0) enable = SmallIntegerField(default=1) avg = FloatField() loss_rate = FloatField() last_time = DateTimeField() class Meta: table_name = 'device'
class AutoResponder(Model): id = AutoField() serverid = BigIntegerField() trigger = CharField(max_length=300, collation="utf8mb4_general_ci") response = CharField(max_length=2000, collation="utf8mb4_general_ci") flags = SmallIntegerField(default=0) chance = SmallIntegerField(default=10000) responsechannelid = BigIntegerField(default=0) listenchannelid = BigIntegerField(default=0) logchannelid = BigIntegerField(default=0) class Meta: database = connection
class User(BaseModel): id = UUIDField(primary_key=True, default=uuid4) email = CharField(unique=True) password = CharField() firstname = CharField() lastname = CharField() age = SmallIntegerField() gender = CharField() height = SmallIntegerField() is_smoke = BooleanField() hobbies = TextField(null=True) created_at = DateTimeField(default=now_in_utc) class Meta: table_name = 'users'
class User_campaign(Member): campaignId = IntegerField(null=False, primary_key=True, verbose_name='推广计划id') title = FixedCharField(max_length=60, null=False, verbose_name='推广计划名称') budget = SmallIntegerField(null=False, verbose_name='推广计划预算') promoteArea = FixedCharField(null=False, max_length=255, verbose_name='投放地域') schedule = SmallIntegerField(null=False, verbose_name='投放时段') onlineStatus = BooleanField(null=False, verbose_name='推广计划状态') settleStatus = BooleanField(null=False) cositeFlag = BooleanField(null=False, verbose_name='站外推广') createTime = DateTimeField(null=False, verbose_name='推广计划创建时间') modifiedTime = DateTimeField(null=False, verbose_name='推广计划被修改时间')
class DateData(BaseModel): """Tracks weight and calories consumed for a given date.""" date = DateField( unique=True, default=datetime.datetime.now, help_text="The date for the data", ) calories = SmallIntegerField( null=True, help_text="Calories consumed in kcal", ) weight = SmallIntegerField( null=True, help_text="Weight in kg", )
class Tracklist(BaseModel): track_path = CharField(max_length=750) track_performer = CharField(max_length=200, null=True) track_title = CharField(max_length=200) track_duration = IntegerField() info_user_id = BigIntegerField() info_user_name = CharField(max_length=100) info_message_id = BigIntegerField() ether_day = SmallIntegerField() ether_num = SmallIntegerField() position = IntegerField() @classmethod def add(cls, track: PlaylistItem, ether: Ether): assert track.track_info is not None, "Local playlist need track info!" position = cls.select(fn.Max( cls.position)).where(*_e2cmp(ether)).scalar() or 0 day, num = (0, 0) if ether is None else (ether.day, ether.num) cls.insert(track_path=track.path.name, track_performer=track.performer, track_title=track.title, track_duration=track.duration, info_user_id=track.track_info.user_id, info_user_name=track.track_info.user_name, info_message_id=track.track_info.moderation_id, ether_day=day, ether_num=num, position=position + 1).on_conflict_replace().execute() @classmethod def get_by_ether(cls, ether: Ether): return cls.select().where(*_e2cmp(ether)).order_by(cls.position.asc()) @classmethod def get_track_by_path(cls, ether: Ether, path: Path) -> Optional[Tracklist]: return cls.select().where(*_e2cmp(ether), cls.track_path == path.name).first() @classmethod def remove_track(cls, ether: Ether, path: Path) -> Optional[Tracklist]: if track := cls.get_track_by_path(ether, path): track.delete_instance() return track return None