class Schedule(BaseModel): instance_id = CharField(max_length=20, unique=True, null=False) start_at = TimeField(null=False) stop_at = TimeField(null=False) @staticmethod def add(instance_id, start_at, stop_at): schedule = Schedule(instance_id=instance_id, start_at=start_at, stop_at=stop_at) schedule.save() @staticmethod def remove(instance_id): schedule = Schedule.get(instance_id=instance_id) # Don't confuse "delete_instance" with referring to an EC2 instance. It's # referring to an instance of a DB record. schedule.delete_instance() @staticmethod def modify(instance_id, start_at, stop_at): schedule = Schedule.get(instance_id=instance_id) schedule.start_at = start_at schedule.stop_at = stop_at schedule.save() @staticmethod def all(): return Schedule.select().dicts()
class Itinerario(BaseModel): id = AutoField(null=False, primary_key=True) # SERIAL, PK, NOT NULL latitudOrig = CharField(null=False, max_length=255) longitudOrig = CharField(null=False, max_length=255) latitudDst = CharField(null=False, max_length=255) longitudDst = CharField(null=False, max_length=255) dia = CharField(null=False, max_length=255) horaEntrada = TimeField(null=False,formats='%H:%M') horaSalida = TimeField(null=False,formats='%H:%M') fk_persona = ForeignKeyField(null=False,model=Persona,field=Persona.id)
class ModelFeatures(Model): Model = ForeignKeyField(Models, backref="Features") # Current accuracy and loss for the model TrainAccuracy = FloatField() TrainLoss = FloatField() ValidationAccuracy = FloatField() ValidationLoss = FloatField() EvaluationAccuracy = FloatField() EvaluationLoss = FloatField() TrainTime = TimeField() # Model permanent features BUFFER_SIZE = IntegerField() BATCH_SIZE = SmallIntegerField() EPOCHS = SmallIntegerField() VALIDATION_STEPS = SmallIntegerField() LEARNING_RATE = FloatField() EMBED_DIM = SmallIntegerField() DEEP_UNITS = SmallIntegerField() DENSE_UNITS = SmallIntegerField() DROPOUT = FloatField() MAX_FEATURES = IntegerField() MAX_LENGTH = SmallIntegerField() TRAIN_TAKE_SIZE = IntegerField() TEST_TAKE_SIZE = IntegerField() class Meta: database = db
class Accident(Model): asn_id = CharField(20) date = DateField(null=True) time = TimeField(null=True) aircraft = ForeignKeyField(Aircraft, related_name='accidents', null=True) damage_type = CharField(max_length=100, null=True) lat = DecimalField(max_digits=COORDINATES_LENGTH, decimal_places=COORDINATES_DECIMAL, null=True) long = DecimalField(max_digits=COORDINATES_LENGTH, decimal_places=COORDINATES_DECIMAL, null=True) flight_phase = CharField(null=True) flight_nature = CharField(null=True) dep_airfield = ForeignKeyField(Airfield, related_name='dep_accidents', null=True) asn_dep_airfield = CharField(20, null=True) dep_weather = ForeignKeyField(Weather, related_name='department_accident', null=True) dest_airfield = ForeignKeyField(Airfield, related_name='dest_accidents', null=True) asn_dest_airfield = CharField(20, null=True) dest_weather = ForeignKeyField(Weather, related_name='destination_accident', null=True) class Meta: database = db
class QuoteModel(StreamModel): symbol = CharField() field = CharField() value = FloatField() date = DateField() time = TimeField() datetime_created = DateTimeField() class Meta: table_name = 'QUOTE' @staticmethod def insert_new(symbol, field, value, date, time): QuoteModel.create(symbol=symbol.upper(), field=field.upper(), value=float(value), date=date, time=time, datetime_created=datetime.now()) @staticmethod def fetch_by_symbol_field_date(symbol, field, date): query = QuoteModel\ .select()\ .where((QuoteModel.symbol == symbol) & (QuoteModel.field == field) & (fn.DATE(QuoteModel.date) == date)) return [item for item in query]
class ViajeReservado(BaseModel): id = AutoField(null=False, primary_key=True) # SERIAL, PK, NOT NULL latitudOrig = FloatField(null=False) longitudOrig = FloatField(null=False) latitudDst = FloatField(null=False) longitudDst = FloatField(null=False) fecha = DateField(null=False, formats='%d-%m-%Y') hora = TimeField(null=False, formats='%H:%M') fk_persona = ForeignKeyField(null=False, model=Persona, field=Persona.id)
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 MonitoringSession(Model): interface = CharField() executed = TimeField(formats='%H:%M:%S', default=datetime.now) class Meta: database = PcapAnalysisModule.DATABASE def __init__(self, **kwargs): super(MonitoringSession, self).__init__(**kwargs)
class PoolTransactionModel(DynamicModel): pool_name = CharField() action = CharField() amount = FloatField() date = DateField() time = TimeField() class Meta: table_name = 'POOL_TRANSACTION'
class FakeItemIdsStore(Model): is_deleted = BooleanField( default=False) # mark processed or duplicated items item_id = CharField() item_content_json = TextField() created_at = TimeField(default=datetime.datetime.now) class Meta: database = sqlite_database
class ColaDePedidos(BaseModel): id = AutoField(null=False, primary_key=True) # SERIAL, PK, NOT NULL latitudOrig = CharField(null=False) longitudOrig = CharField(null=False) latitudDst = CharField(null=False) longitudDst = CharField(null=False) fecha = DateField(null=True,formats='%d-%m-%Y') hora = TimeField(null=True,formats='%H:%M') estado = CharField(null=True,max_length=255) fk_persona = ForeignKeyField(null=False,model=Persona,field=Persona.id) fk_chofer = ForeignKeyField(null=True,model=Persona,field=Persona.id)
class Programme(BaseModel): name = CharField(max_length=150) date = DateField() time = TimeField() timestart = IntegerField() timestop = IntegerField() channel = CharField(max_length=100) class Meta: db_table = PROGRAMME_TABLE_NAME indexes = ((('name', 'date', 'time', 'channel'), True), )
class Task(BaseModel): """Task Model.""" name = CharField() start_time = TimeField(null=True) end_time = TimeField(null=True) day = ForeignKeyField(Day, related_name='tasks') class Meta: """Meta class.""" constraints = [ Check("start_time is NULL or start_time LIKE '__:__'"), Check("end_time is NULL or end_time LIKE '__:__'") ] def __str__(self): """Get string representation.""" return 'Task: {} {}/{}'.format(self.name, self.start_time, self.end_time)
class Termin(Model): id = UUIDField(primary_key=True) einrichtung = ForeignKeyField(Einrichtung, backref='termine') spender = ForeignKeyField(Person, backref='termine') datum = DateField() uhrzeit = TimeField() kategorie = IntegerField( 12) # Wunsch = 0 / Alternativ 1 = 1 / Alternativ 2 = 2 bestaetigt = BooleanField() # Ja = True / Nein = False anmerkungen = CharField(null=True) class Meta: database = db
class Viaje(BaseModel): id = AutoField(null=False, primary_key=True) # SERIAL, PK, NOT NULL fecha = DateField(null=False, formats='%d-%m-%Y', default=datetime.now().strftime("%d-%m-%Y")) hora = TimeField(null=False, formats='%H:%M:%S', default=datetime.now().strftime("%H:%M:%S")) fk_chofer = ForeignKeyField(null=False, model=Persona, field=Persona.id) #Chofer fk_pasajero = ForeignKeyField(null=False, model=Persona, field=Persona.id) #Pasajero latitud = FloatField(null=False) longitud = FloatField(null=False) estado = CharField(null=False, default='completo')
class Post(Model): stream = ForeignKeyField(Stream, backref='posts', null=False) title = CharField(max_length=200, null=True) slug = CharField(max_length=200, null=True) text = TextField(null=False) text_html = TextField(null=True) date = DateTimeField(null=False, default=datetime.utcnow) year = IntegerField(null=True) month = IntegerField(null=True) day = IntegerField(null=True) time = TimeField(null=True) class Meta: database = db indexes = ( (('year', 'month', 'day', 'time', 'stream'), False), )
class PoolTradeModel(DynamicModel): pool_name = CharField() instrument = CharField() action = CharField() amount = FloatField() symbol = CharField() price = FloatField() date = DateField() time = TimeField() is_open = BooleanField() spot = FloatField(null=True) strike = FloatField(null=True) expiry_date = DateField(null=True) note = CharField() class Meta: table_name = 'POOL_TRADE' @staticmethod def insert_entry_by_name(pool_name, instrument, action, amount, symbol, price, date, time, spot, strike, expiry_date, note): PoolTradeModel.create(pool_name=pool_name, instrument=instrument, action=action, amount=amount, symbol=symbol, price=price, date=date, time=time, is_open=True, spot=spot, strike=strike, expiry_date=expiry_date, note=note, datetime_created=datetime.now())
class Food(BaseModel): name = CharField(max_length=20) time = TimeField( default=lambda: time(hour=now().hour, minute=now().minute)) date = DateField(default=lambda: now().date())
class Food(BaseModel): name = CharField(max_length=20) time = TimeField(default=current_time) date = DateField(default=current_date)
class Entry(BaseModel): date = DateField() user = ForeignKeyField(User, backref='reported_by') approver = ForeignKeyField(User, backref='approved_by', null=True) started_at = TimeField() finished_at = TimeField() modified_at = DateTimeField(default=datetime.now) approved_at = DateTimeField(null=True) comment = TextField(null=True, default="") break_for = ForeignKeyField(Break, backref='break_for', null=True) is_approved = BooleanField(default=False) break_length = property(lambda self: self.break_for.minutes if self.break_for else 0) @property def total_min(self): if self.started_at is None or self.finished_at is None: return None total = (self.finished_at.hour - self.started_at.hour) * 60 total += (self.finished_at.minute - self.started_at.minute) total -= self.break_length return total @property def total_time(self): total = self.total_min if total is None: return None return timedelta(hours=(total / 60), minutes=(total % 60)) def __str__(self): output = "On %s from %s to %s" % ( self.date.isoformat(), "N/A" if self.started_at is None else self.started_at.strftime("%H:%M"), "N/A" if self.finished_at is None else self.finished_at.strftime("%H:%M")) if self.break_for: output += " with beak for " + self.break_for.name total_min = self.total_min if total_min: output += ", total: %d:%02d" % (total_min // 60, total_min % 60) return output class Meta: table_alias = 'e' @classmethod def get_user_timesheet(cls, *, user=None, week_ending_date=None): """ Retrievs timesheet entries for a user a week ending on week_ending_date. """ if user is None: user = current_user if week_ending_date is None: week_ending_date = current_week_ending_date() rq = RawQuery(cls, """ WITH daynums(num) AS (VALUES (6),(5),(4),(3),(2),(1),(0)), week(day) AS (SELECT date(?, '-'||num||' day') FROM daynums) SELECT id, day as date, finished_at, started_at, user_id, modified_at, break_for_id, is_approved, approver_id, approved_at, comment FROM week LEFT JOIN entry ON "date" = day AND user_id = ? ORDER BY "date" ASC""", week_ending_date.isoformat(), user.id) return rq.execute() @classmethod def get_for_approving(cls, *, user=None, week_ending_date=None): """ Retrievs timesheet entries for approval """ query = Entry.select() if user: query = query.where(Entry.user_id == user.id) if week_ending_date: week_start_date = week_ending_date - timedelta(days=7) query = query.where((Entry.date >= week_start_date) & (Entry.date <= week_ending_date)) return query.order_by(Entry.date).limit(100).execute()
class Period(db.Model): period = ForeignKeyField(Forecast, backref='period', primary_key=True) period_from = TimeField() period_to = TimeField()
class Forecast(db.Model): id = PrimaryKeyField(null=False) user = ForeignKeyField(User, backref='forecast') address = CharField() notification = TimeField()