class BboxMixin(object): """A model mix-in with columns for a bounding box.""" max_lat = Column(Double(asdecimal=False)) #: min_lat = Column(Double(asdecimal=False)) #: max_lon = Column(Double(asdecimal=False)) #: min_lon = Column(Double(asdecimal=False)) #:
class StationMixin(BaseStationMixin): max_lat = Column(Double(asdecimal=False)) min_lat = Column(Double(asdecimal=False)) max_lon = Column(Double(asdecimal=False)) min_lon = Column(Double(asdecimal=False)) new_measures = Column(Integer(unsigned=True))
class StationMixin(BboxMixin, PositionMixin, TimeTrackingMixin, CreationMixin, ScoreMixin): """A model mix-in with common station columns.""" radius = Column(Integer(unsigned=True)) #: region = Column(String(2)) #: samples = Column(Integer(unsigned=True)) #: source = Column(TinyIntEnum(StationSource)) #: weight = Column(Double(asdecimal=False)) #: last_seen = Column(Date) #: block_first = Column(Date) #: block_last = Column(Date) #: block_count = Column(TinyInteger(unsigned=True)) #: def blocked(self, today=None): """Is the station currently blocked?""" if (self.block_count and self.block_count >= PERMANENT_BLOCKLIST_THRESHOLD): return True temporary = False if self.block_last: if today is None: today = util.utcnow().date() age = today - self.block_last temporary = age < TEMPORARY_BLOCKLIST_DURATION return bool(temporary)
class OCIDCell(_Model): __tablename__ = 'ocid_cell' __table_args__ = (Index('ocid_cell_created_idx', 'created'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', }) created = Column(DateTime) modified = Column(DateTime) # lat/lon lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False)) # radio mapped via RADIO_TYPE radio = Column(TinyInteger, autoincrement=False, primary_key=True) mcc = Column(SmallInteger, autoincrement=False, primary_key=True) mnc = Column(SmallInteger, autoincrement=False, primary_key=True) lac = Column(SmallInteger(unsigned=True), autoincrement=False, primary_key=True) cid = Column(Integer(unsigned=True), autoincrement=False, primary_key=True) psc = Column(SmallInteger) range = Column(Integer) total_measures = Column(Integer(unsigned=True)) changeable = Column(Boolean) def __init__(self, *args, **kw): if 'created' not in kw: kw['created'] = util.utcnow() if 'modified' not in kw: kw['modified'] = util.utcnow() if 'lac' not in kw: kw['lac'] = -1 if 'cid' not in kw: kw['cid'] = -1 if 'range' not in kw: kw['range'] = 0 if 'total_measures' not in kw: kw['total_measures'] = 0 if 'changeable' not in kw: kw['changeable'] = True super(OCIDCell, self).__init__(*args, **kw)
class CellMeasure(_Model): __tablename__ = 'cell_measure' __table_args__ = ( Index('cell_measure_created_idx', 'created'), Index('cell_measure_key_idx', 'radio', 'mcc', 'mnc', 'lac', 'cid'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', } ) id = Column(BigInteger(unsigned=True), primary_key=True, autoincrement=True) report_id = Column(BINARY(length=16)) created = Column(DateTime) # the insert time of the record into the DB # lat/lon lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False)) time = Column(DateTime) # the time of observation of this data accuracy = Column(Integer) altitude = Column(Integer) altitude_accuracy = Column(Integer) # http://dev.w3.org/geo/api/spec-source.html#heading heading = Column(Float) # http://dev.w3.org/geo/api/spec-source.html#speed speed = Column(Float) # mapped via RADIO_TYPE radio = Column(TinyInteger) mcc = Column(SmallInteger) mnc = Column(SmallInteger) lac = Column(SmallInteger(unsigned=True)) cid = Column(Integer(unsigned=True)) psc = Column(SmallInteger) asu = Column(SmallInteger) signal = Column(SmallInteger) ta = Column(TinyInteger) def __init__(self, *args, **kw): if 'created' not in kw: kw['created'] = util.utcnow() super(CellMeasure, self).__init__(*args, **kw)
class CellArea(_Model): __tablename__ = 'cell_area' __table_args__ = { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', } created = Column(DateTime) modified = Column(DateTime) # lat/lon lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False)) # radio mapped via RADIO_TYPE radio = Column(TinyInteger, autoincrement=False, primary_key=True) mcc = Column(SmallInteger, autoincrement=False, primary_key=True) mnc = Column(SmallInteger, autoincrement=False, primary_key=True) lac = Column(SmallInteger(unsigned=True), autoincrement=False, primary_key=True) range = Column(Integer) avg_cell_range = Column(Integer) num_cells = Column(Integer(unsigned=True)) def __init__(self, *args, **kw): if 'created' not in kw: kw['created'] = util.utcnow() if 'modified' not in kw: kw['modified'] = util.utcnow() if 'range' not in kw: kw['range'] = 0 if 'avg_cell_range' not in kw: kw['avg_cell_range'] = 0 if 'num_cells' not in kw: kw['num_cells'] = 0 super(CellArea, self).__init__(*args, **kw)
class StationMixin(BboxMixin, PositionMixin, TimeTrackingMixin, CreationMixin): """A model mix-in with common station columns.""" radius = Column(Integer(unsigned=True)) region = Column(String(2)) samples = Column(Integer(unsigned=True)) source = Column(TinyIntEnum(constants.ReportSource)) weight = Column(Double(asdecimal=False)) last_seen = Column(Date) block_first = Column(Date) block_last = Column(Date) block_count = Column(TinyInteger(unsigned=True))
class WifiMeasure(_Model): __tablename__ = 'wifi_measure' __table_args__ = ( Index('wifi_measure_created_idx', 'created'), Index('wifi_measure_key_idx', 'key'), Index('wifi_measure_key_created_idx', 'key', 'created'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', } ) id = Column(BigInteger(unsigned=True), primary_key=True, autoincrement=True) report_id = Column(BINARY(length=16)) created = Column(DateTime) # the insert time of the record into the DB # lat/lon lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False)) time = Column(DateTime) # the time of observation of this data accuracy = Column(Integer) altitude = Column(Integer) altitude_accuracy = Column(Integer) # http://dev.w3.org/geo/api/spec-source.html#heading heading = Column(Float) # http://dev.w3.org/geo/api/spec-source.html#speed speed = Column(Float) key = Column(String(12)) channel = Column(SmallInteger) signal = Column(SmallInteger) snr = Column(SmallInteger) def __init__(self, *args, **kw): if 'created' not in kw: kw['created'] = util.utcnow() super(WifiMeasure, self).__init__(*args, **kw)
class GedScoreModel(db.Model): __tablename__ = 'ged_score' # one to one user_id = db.Column(db.String(32), db.ForeignKey('user.user_id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True) grade = db.Column(Double(unsigned=True), nullable=False, default=0.0) conversion_score = db.Column(Double(unsigned=True), nullable=False, default=0.0) attendance_score = db.Column(Integer(unsigned=True), nullable=False, default=15) volunteer_score = db.Column(Double(unsigned=True), nullable=False, default=0.0) final_score = db.Column(Double(), nullable=False) created_at = db.Column(db.DateTime, nullable=False) updated_at = db.Column(db.DateTime, nullable=False)
class Cell(_Model): __tablename__ = 'cell' __table_args__ = ( Index('cell_created_idx', 'created'), Index('cell_modified_idx', 'modified'), Index('cell_new_measures_idx', 'new_measures'), Index('cell_total_measures_idx', 'total_measures'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', } ) created = Column(DateTime) modified = Column(DateTime) # lat/lon lat = Column(Double(asdecimal=False)) max_lat = Column(Double(asdecimal=False)) min_lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False)) max_lon = Column(Double(asdecimal=False)) min_lon = Column(Double(asdecimal=False)) # mapped via RADIO_TYPE radio = Column(TinyInteger, autoincrement=False, primary_key=True) # int in the range 0-1000 mcc = Column(SmallInteger, autoincrement=False, primary_key=True) # int in the range 0-1000 for gsm # int in the range 0-32767 for cdma (system id) mnc = Column(SmallInteger, autoincrement=False, primary_key=True) lac = Column( SmallInteger(unsigned=True), autoincrement=False, primary_key=True) cid = Column(Integer(unsigned=True), autoincrement=False, primary_key=True) psc = Column(SmallInteger) range = Column(Integer) new_measures = Column(Integer(unsigned=True)) total_measures = Column(Integer(unsigned=True)) def __init__(self, *args, **kw): if 'created' not in kw: kw['created'] = util.utcnow() if 'modified' not in kw: kw['modified'] = util.utcnow() if 'lac' not in kw or not kw['lac']: kw['lac'] = 0 if 'cid' not in kw or not kw['cid']: kw['cid'] = 0 if 'range' not in kw: kw['range'] = 0 if 'new_measures' not in kw: kw['new_measures'] = 0 if 'total_measures' not in kw: kw['total_measures'] = 0 super(Cell, self).__init__(*args, **kw)
class Wifi(_Model): __tablename__ = 'wifi' __table_args__ = ( UniqueConstraint('key', name='wifi_key_unique'), Index('wifi_created_idx', 'created'), Index('wifi_new_measures_idx', 'new_measures'), Index('wifi_total_measures_idx', 'total_measures'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', } ) id = Column(BigInteger(unsigned=True), primary_key=True, autoincrement=True) created = Column(DateTime) modified = Column(DateTime) key = Column(String(12)) # lat/lon lat = Column(Double(asdecimal=False)) max_lat = Column(Double(asdecimal=False)) min_lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False)) max_lon = Column(Double(asdecimal=False)) min_lon = Column(Double(asdecimal=False)) range = Column(Integer) new_measures = Column(Integer(unsigned=True)) total_measures = Column(Integer(unsigned=True)) def __init__(self, *args, **kw): if 'created' not in kw: kw['created'] = util.utcnow() if 'modified' not in kw: kw['modified'] = util.utcnow() if 'new_measures' not in kw: kw['new_measures'] = 0 if 'total_measures' not in kw: kw['total_measures'] = 0 super(Wifi, self).__init__(*args, **kw)
class GraduateScoreModel(db.Model): __tablename__ = 'graduate_score' # one to one user_id = db.Column(db.String(32), db.ForeignKey('user.user_id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True) first_grade = db.Column(Double(unsigned=True), nullable=False, default=0.0) second_grade = db.Column(Double(unsigned=True), nullable=False, default=0.0) third_grade = db.Column(Double(unsigned=True), nullable=False, default=0.0) conversion_score = db.Column(Double(unsigned=True), nullable=False, default=0.0) attendance_score = db.Column(Integer(unsigned=True), nullable=False, default=0) volunteer_score = db.Column(Double(unsigned=True), nullable=False, default=0.0) final_score = db.Column(Double(), nullable=False) volunteer_time = db.Column(Integer(unsigned=True), nullable=False, default=0) period_cut = db.Column(Integer(unsigned=True), nullable=False, default=0) full_cut = db.Column(Integer(unsigned=True), nullable=False, default=0) late = db.Column(Integer(unsigned=True), nullable=False, default=0) early_leave = db.Column(Integer(unsigned=True), nullable=False, default=0) created_at = db.Column(db.DateTime, nullable=False) updated_at = db.Column(db.DateTime, nullable=False)
class PositionMixin(object): lat = Column(Double(asdecimal=False)) lon = Column(Double(asdecimal=False))
class PositionMixin(object): """A model mix-in with lat and lon float columns.""" lat = Column(Double(asdecimal=False)) #: lon = Column(Double(asdecimal=False)) #: