示例#1
0
class TcSuiteMap(Base):
    """
    This class is mapped to the tc_to_suite_map table in the Management schema.
    DB Comment: Define links between test suites and test cases in this table.
    """
    __tablename__ = 'tc_to_suite_map'
    __table_args__ = {'schema': schema_name}

    tc_id = Column(INTEGER(),
                   ForeignKey(schema_name + '.' + 'test_case.tc_id'),
                   primary_key=True,
                   nullable=False)
    tc_version = Column(REAL(),
                        ForeignKey(schema_name + '.' + 'test_case.tc_version'),
                        primary_key=True,
                        nullable=False)
    suite_id = Column(INTEGER(),
                      ForeignKey(schema_name + '.' + 'test_suite.suite_id'),
                      primary_key=True,
                      nullable=False)
    suite_version = Column(REAL(),
                           ForeignKey(schema_name + '.' +
                                      'test_suite.suite_version'),
                           primary_key=True,
                           nullable=False)

    added_by = Column(VARCHAR())
    added_time = Column(TIMESTAMP())
示例#2
0
class Misc(Base):
    """This model contains all possible MySQL types"""

    __tablename__ = "misc"
    id = Column(Integer, primary_key=True)
    big_integer_field = Column(BigInteger, default=0)
    big_integer_unsigned_field = Column(BIGINT(unsigned=True), default=0)
    large_binary_field = Column(LargeBinary, nullable=True)
    boolean_field = Column(Boolean, default=False)
    char_field = Column(CHAR(255), nullable=True)
    date_field = Column(Date, nullable=True)
    date_time_field = Column(DateTime, nullable=True)
    decimal_field = Column(DECIMAL(10, 2), nullable=True)
    float_field = Column(Float(12, 4), default=0)
    integer_field = Column(Integer, default=0)
    integer_unsigned_field = Column(INTEGER(unsigned=True), default=0)
    tinyint_field = Column(TINYINT, default=0)
    tinyint_unsigned_field = Column(TINYINT(unsigned=True), default=0)
    mediumint_field = Column(MEDIUMINT, default=0)
    mediumint_unsigned_field = Column(MEDIUMINT(unsigned=True), default=0)
    if environ.get("LEGACY_DB", "0") == "0":
        json_field = Column(JSON, nullable=True)
    nchar_field = Column(NCHAR(255), nullable=True)
    numeric_field = Column(Numeric(12, 4), default=0)
    unicode_field = Column(Unicode(255), nullable=True)
    real_field = Column(REAL(12, 4), default=0)
    small_integer_field = Column(SmallInteger, default=0)
    small_integer_unsigned_field = Column(SMALLINT(unsigned=True), default=0)
    string_field = Column(String(255), nullable=True)
    text_field = Column(Text, nullable=True)
    time_field = Column(Time, nullable=True)
    varbinary_field = Column(VARBINARY(255), nullable=True)
    varchar_field = Column(VARCHAR(255), nullable=True)
    timestamp_field = Column(TIMESTAMP, default=current_timestamp())
    dupe = Column(Boolean, index=True, default=False)
示例#3
0
class Misc(Base):
    """This model contains all possible MySQL types"""

    __tablename__ = "misc"
    id = Column(Integer, primary_key=True)
    big_integer_field = Column(BigInteger, default=0)
    large_binary_field = Column(LargeBinary, nullable=True)
    boolean_field = Column(Boolean, default=False)
    char_field = Column(CHAR(255), nullable=True)
    date_field = Column(Date, nullable=True)
    date_time_field = Column(DateTime, nullable=True)
    decimal_field = Column(DECIMAL(10, 2), nullable=True)
    float_field = Column(Float(12, 4), default=0)
    integer_field = Column(Integer, default=0)
    json_field = Column(JSON, nullable=True)
    nchar_field = Column(NCHAR(255), nullable=True)
    numeric_field = Column(Numeric(12, 4), default=0)
    unicode_field = Column(Unicode(255), nullable=True)
    real_field = Column(REAL(12, 4), default=0)
    small_integer_field = Column(SmallInteger, default=0)
    string_field = Column(String(255), nullable=True)
    text_field = Column(Text, nullable=True)
    time_field = Column(Time, nullable=True)
    varbinary_field = Column(VARBINARY(255), nullable=True)
    varchar_field = Column(VARCHAR(255), nullable=True)
    timestamp_field = Column(TIMESTAMP, default=current_timestamp())
示例#4
0
class Misc(Base):
    """This model contains all possible MySQL types"""

    __tablename__ = "misc"
    id = Column(Integer, primary_key=True)
    big_integer_field = Column(BigInteger, default=0)
    blob_field = Column(BLOB, nullable=True, index=True)
    boolean_field = Column(Boolean, default=False)
    char_field = Column(CHAR(255), nullable=True)
    date_field = Column(Date, nullable=True)
    date_time_field = Column(DateTime, nullable=True)
    decimal_field = Column(SQLiteNumeric(10, 2), nullable=True)
    float_field = Column(SQLiteNumeric(12, 4), default=0)
    integer_field = Column(Integer, default=0)
    if environ.get("LEGACY_DB", "0") == "0":
        json_field = Column(JSON, nullable=True)
    numeric_field = Column(SQLiteNumeric(12, 4), default=0)
    real_field = Column(REAL(12, 4), default=0)
    small_integer_field = Column(SmallInteger, default=0)
    string_field = Column(String(255), nullable=True)
    text_field = Column(Text, nullable=True)
    time_field = Column(Time, nullable=True)
    varchar_field = Column(VARCHAR(255), nullable=True)
    timestamp_field = Column(TIMESTAMP, default=current_timestamp())
    my_type_field = Column(MyCustomType(255), nullable=True)
示例#5
0
class Requirement(Base):
    """
    This class is mapped to the requirement table in the Management schema.
    DB Comment: Mapping to TFS requirements. Since not all automated test cases may be found in TFS,
    traceability must be ensured internally.
    """
    __tablename__ = 'requirement'
    __table_args__ = {'schema': schema}

    req_id = Column(INTEGER(), primary_key=True, nullable=False)
    """Internal requirement ID."""
    title = Column(VARCHAR(length=2000), nullable=False)
    """Maps to TFS work item title."""
    tfs_link = Column(VARCHAR(length=2000))
    """Link to the work item in TFS."""
    tfs_id = Column(VARCHAR(length=250))
    """Maps to TFS ID."""
    mrd = Column(VARCHAR(length=250))
    """If the requirement is an SRD/TRD, this links it to the parent marketing requirement."""
    feature = Column(VARCHAR(length=2000))
    """Links the requirement to the parent feature. (Where applicable)"""
    req_type = Column(VARCHAR(length=10))
    """MRD, SRD, TRD or Backlog Item."""
    req_version = Column(REAL(precision=8, decimal_return_scale=8),
                         primary_key=True,
                         nullable=False,
                         server_default=DefaultClause("1.0", for_update=False))
    """The requirement version as it is stored in TFS, where applicable. Set to default for backlog items."""
示例#6
0
class Station(Base):
    """
    Station Object

    :type ref: int
    :param ref: The Station ID in the database
    :type net: str
    :param net: The network code of the Station
    :type sta: str
    :param sta: The station code
    :type X: float
    :param X: The X coordinate of the station
    :type Y: float
    :param Y: The Y coordinate of the station
    :type altitude: float
    :param altitude: The altitude of the station
    :type coordinates: str
    :param coordinates: The coordinates system. "DEG" is WGS84 latitude/
        longitude in degrees. "UTM" is expressed in meters.
    :type instrument: str
    :param instrument: The instrument code, useful with PAZ correction
    :type used: bool
    :param used: Whether this station must be used in the computations.
    """
    __tablename__ = "stations"
    ref = Column(Integer, primary_key=True)
    net = Column(String(10))
    sta = Column(String(10))
    X = Column(REAL())
    Y = Column(REAL())
    altitude = Column(Float())
    coordinates = Column(Enum('DEG', 'UTM'))
    instrument = Column(String(20))
    used = Column(Boolean)

    def __init__(self, net, sta, X, Y, altitude, coordinates, instrument,
                 used):
        """"""
        self.net = net
        self.sta = sta
        self.X = X
        self.Y = Y
        self.altitude = altitude
        self.coordinates = coordinates
        self.instrument = instrument
        self.used = used
示例#7
0
class ContentClassificationTask(Base):
    __tablename__ = 'content_classification_tasktable'

    __table_args__ = {'extend_existing': True}

    index = Column(Integer, primary_key=True)
    object_id = Column(String(255))
    task_status = Column(String(64))
    n_failed = Column(Integer, default=0)
    max_retries = Column(Integer, default=0)
    max_timeout = Column(REAL())
    priority_factor = Column(REAL())
    updated_at = Column(REAL())
    created_at = Column(REAL())
    last_submitted = Column(REAL())
    last_queried = Column(REAL())
    last_success = Column(REAL())
    last_failure = Column(REAL())
    endpoint = Column(Text)
    params = Column(Text)  # jason
    task_id = Column(String(132))
    state = Column(String(64))
    res_status = Column(String(64))
    res_data = Column(Text)  # jason
    res_error = Column(Text)  # jason
    f_no_total_clicks = Column(Integer, default=0)
    f_no_unique_clicks = Column(Integer, default=0)
    _uuid = Column(String(132))

    def __init__(self, **kwargs):
        self._uuid = kwargs['_uuid']
        self.index = kwargs['index']

    def to_dict(self):
        return {
            c.name: getattr(self, c.name, None)
            for c in self.__table__.columns
        }

    def saveOne(self):
        db_session.add(self)

        db_session.commit()
        db_session.close()

    @classmethod
    def saveAll(cls, dataList):
        for d in dataList:
            cck = cls(**d)
            db_session.add(cck)

        db_session.commit()
        db_session.close()
class RylaisOrder(Base):
    __tablename__ = 'rylais_order'
    champ_id = Column(Integer, primary_key=True)
    percent_build = Column(REAL(5))
    built_winrate = Column(REAL(5))
    not_built_winrate = Column(REAL(5))
    total_games_built = Column(Integer)
    wins = Column(String(40))
    losses = Column(String(40))
    winrates = Column(String(40))

    def __init__(self, champ_id, percent_build, built_winrate,
                 not_built_winrate, total_games_built, wins, losses, winrates):
        self.champ_id = champ_id
        self.percent_build = percent_build
        self.built_winrate = built_winrate
        self.not_built_winrate = not_built_winrate
        self.total_games_built = total_games_built
        self.wins = wins
        self.losses = losses
        self.winrates = winrates
示例#9
0
class TestCase(Base):
    """
    This class is mapped to the test_case table in the Management schema.
    DB Comment: Can be an internal TAF test case or more likely a representation of a TFS test case.
    """
    __tablename__ = 'test_case'
    __table_args__ = {'schema': schema_name}

    tc_id_seq = Sequence('test_case_id_seq', metadata=Base.metadata)
    tc_id = Column(INTEGER(),
                   Sequence('test_case_id_seq'),
                   primary_key=True,
                   nullable=False,
                   server_default=DefaultClause(tc_id_seq.next_value(),
                                                for_update=False))
    tc_title = Column(VARCHAR(length=500))
    """A short description of the test case."""
    tc_description = Column(TEXT())
    """The details of the test case, or even the test steps, if it is short or simple."""
    ext_id = Column(INTEGER())
    """A link to TFS if the TC represents a TFS entity."""
    tc_version = Column(REAL(),
                        primary_key=True,
                        nullable=False,
                        server_default=DefaultClause('0.1', for_update=False))
    """The test case version. Each modification has to trigger a new version and a backup."""
    created_by = Column(VARCHAR(length=200), nullable=False)
    created_time = Column(TIMESTAMP(), nullable=False)
    last_modified_by = Column(VARCHAR(length=200))
    last_modified_time = Column(TIMESTAMP())
    # The database also has a CHECK constraint on this field for the allowed values: MANUAL, AUTO, BDD, DDT, KWD, COMBI
    # Here the CHECK constraint is passed as a string as SQLAlchemy doesn't know how to handle these, so this is
    # exactly as it appears in the PostgreSQL database
    # https://docs.sqlalchemy.org/en/13/core/constraints.html?highlight=constraint#check-constraint
    test_type = Column(VARCHAR(length=20),
                       CheckConstraint(
                           "((test_type)::text = "
                           "ANY ((ARRAY['MANUAL'::character varying, "
                           "'AUTO'::character varying, "
                           "'BDD'::character varying, "
                           "'DDT'::character varying, "
                           "'KWD'::character varying])::text[]))"),
                       nullable=False,
                       server_default=DefaultClause('AUTO', for_update=False))
    """MANUAL, AUTO, BDD, DDT, KWD, COMBI"""
    linked_test_id = Column(INTEGER())
    """The DB ID of a BDD feature or scenario, a KWD set a combinatorial set, or a TFS ID."""
    linked_test_format = Column(VARCHAR(length=20))
    """File, database, TFS."""
示例#10
0
class TestSuite(Base):
    """
    This class is mapped to the test_suite table in the Management schema.
    DB Comment: Define test suites/sets in this table.
    """
    __tablename__ = 'test_suite'
    __table_args__ = {'schema': schema_name}

    suite_id = Column(INTEGER(), primary_key=True, nullable=False)
    suite_name = Column(VARCHAR(length=200), nullable=False)
    suite_description = Column(TEXT())
    suite_version = Column(REAL(),
                           primary_key=True,
                           nullable=False,
                           server_default=DefaultClause("0.1",
                                                        for_update=False))
    created_by = Column(VARCHAR(length=200), nullable=False)
    created_time = Column(TIMESTAMP(), nullable=False)
    last_modified_by = Column(VARCHAR(length=200))
    last_modified_time = Column(TIMESTAMP())
示例#11
0
    class Station(PrefixerBase):
        """
        Station Object

        :type ref: int
        :param ref: The Station ID in the database
        :type net: str
        :param net: The network code of the Station
        :type sta: str
        :param sta: The station code
        :type X: float
        :param X: The X coordinate of the station
        :type Y: float
        :param Y: The Y coordinate of the station
        :type altitude: float
        :param altitude: The altitude of the station
        :type coordinates: str
        :param coordinates: The coordinates system. "DEG" is WGS84 latitude/
            longitude in degrees. "UTM" is expressed in meters.
        :type instrument: str
        :param instrument: The instrument code, useful with PAZ correction
        :type used: bool
        :param used: Whether this station must be used in the computations.
        """
        __incomplete_tablename__ = "stations"
        ref = Column(Integer, primary_key=True)
        net = Column(String(10))
        sta = Column(String(10))
        used_location_codes = Column(String(20))
        used_channel_names = Column(String(20))

        X = Column(REAL())
        Y = Column(REAL())
        altitude = Column(Float())
        coordinates = Column(Enum('DEG', 'UTM', name="coordinate_type"))
        used = Column(Boolean)

        def __init__(self, *args):
            """"""
            if len(args):
                self.net = args[0]
                self.sta = args[1]
                self.X = args[2]
                self.Y = args[3]
                self.altitude = args[4]
                self.coordinates = args[5]
                self.used = args[7]

        def locs(self):
            if self.used_location_codes is None:
                location_codes = []
            else:
                location_codes = sorted(self.used_location_codes.split(","))
            return location_codes

        def chans(self):
            if self.used_channel_names is None:
                channels = []
            else:
                channels = sorted(self.used_channel_names.split(","))
            return channels
示例#12
0
    col_default=0,
)
SlotString = define_simpleslot(
    postfix="String",
    pytype=(str_unicode, ),
    KVPtype=KVP_Type.KVP_TYPE_STRING,
    field="string_val",
    col_type=VARCHAR(length=4096),
    col_default=None,
)
SlotDouble = define_simpleslot(
    postfix="Double",
    pytype=(float, ),
    KVPtype=KVP_Type.KVP_TYPE_DOUBLE,
    field="double_val",
    col_type=REAL(),
    col_default=0,
)
SlotTime = define_simpleslot(
    postfix="Time",
    pytype=(datetime.time, ),
    KVPtype=KVP_Type.KVP_TYPE_TIMESPEC,
    field="timespec_val",
    col_type=_DateTime(),
    col_default=None,
)


class SlotFrame(DictWrapper, Slot):
    __mapper_args__ = {'polymorphic_identity': KVP_Type.KVP_TYPE_FRAME}
    _python_type = (dict, )
示例#13
0
class Food(db.Model, SearchableMixin):
    __tablename__ = 'foods'
    __indexname__ = 'foods_new'
    __ingredients_index__ = 'ingredients'

    id = Column('id', Integer(), primary_key=True)
    Calories = Column('calories', Integer())
    Fat = Column('fat', REAL())
    Fiber = Column('fiber', REAL())
    Protein = Column('protein', REAL())
    Category = Column('category', VARCHAR(20), nullable=False)
    Image = Column('image', VARCHAR(400), default=None)
    Thumbnail = Column('thumbnail', VARCHAR(400), default=None)
    Title = Column('title', VARCHAR(200), nullable=False)
    CreatedAt = Column('created_at', TIMESTAMP())
    AuthorId = Column('author',
                      Integer(),
                      ForeignKey('users.id'),
                      nullable=False)

    # should not be accessed directly, use `recipe` property insted
    # this column will be deprecated soon
    Recipe = Column('recipe', TEXT())

    # @hybrid_property
    # def Category(self):
    #     return self._Category.strip()
    #
    # @Category.setter
    # def category_setter(self, category):
    #     self._Category = category

    @property
    def recipe(self) -> dict:
        if self.Recipe is None or self.Recipe == '':
            return None
        else:
            payload = json.loads(self.Recipe)
            payload['category'] = self.get_category()
            payload['date_created'] = self.CreatedAt.strftime(
                '%Y-%m-%d %H:%M:%S')

            # fixing image loss
            if len(payload['images']
                   ) != 0 and payload['primary_image'] is None:
                payload['primary_image'] = payload['images'][0]['image']
                payload['primary_thumbnail'] = payload['images'][0][
                    'thumbnail']

            return payload

    def __repr__(self):
        return f"<Food '{self.Title}'>"

    @property
    def simple_view(self) -> dict:
        """
               a simple view of food model
        """
        payload = {
            'id': self.id,
            'category': self.get_category(),
            'image': self.Image,
            'thumbnail': self.Thumbnail,
            'title': self.Title,
            'nutrition': {
                'calories': self.Calories,
                'fat': self.Fat,
                'fiber': self.Fiber,
                'protein': self.Protein
            }
        }
        if payload['image'] is None:
            recipe = self.recipe
            payload['image'] = recipe['primary_image']
            payload['thumbnail'] = recipe['primary_thumbnail']

        return payload

    def __str__(self):
        return json.dumps(self.simple_view)

    def get_calorie(self) -> int:
        return self.Calories

    def get_category(self) -> str:
        return self.Category.strip().lower()

    @property
    def elastic_document(self):
        """
        :return: elastic search index document
        """
        recipe = self.recipe
        payload = {
            'author':
            self.author.FullName,
            'name':
            recipe['food_name'],
            'description':
            recipe['description'],
            'category':
            recipe['category'],
            'nutrition': {
                key: value / recipe['servings']
                for key, value in recipe['nutrition'].items()
            },
            'tag_cloud':
            recipe['tag_cloud'],
            'ingredients': [
                ingredient['food']['food_name']
                for ingredient in recipe['ingredients']
            ],
            'ingredient_ids':
            [ingredient['food']['id'] for ingredient in recipe['ingredients']],
            'directions':
            [direction['text'] for direction in recipe['directions']],
            'cook_time':
            recipe['cook_time'],
            'prep_time':
            recipe['prep_time'],
            'total_time':
            recipe['cook_time'] + recipe['prep_time']
        }

        return payload

    @property
    def ingredients_summery(self):
        payload = {}
        recipe = self.recipe
        for ingredient in recipe['ingredients']:
            payload[ingredient['food']['id']] = ingredient['food']
        return payload
class RylaisDamage(Base):
    __tablename__ = 'rylais_damage'
    champ_id = Column(Integer, primary_key=True)
    kills_rylais = Column(REAL(5))
    kills_without = Column(REAL(5))
    deaths_rylais = Column(REAL(5))
    deaths_without = Column(REAL(5))
    assists_rylais = Column(REAL(5))
    assists_without = Column(REAL(5))
    kda_rylais = Column(REAL(5))
    kda_without = Column(REAL(5))
    damage_done_rylais = Column(REAL(5))
    damage_done_without = Column(REAL(5))
    damage_taken_rylais = Column(REAL(5))
    damage_taken_without = Column(REAL(5))
    damage_ratio_rylais = Column(REAL(5))
    damage_ratio_without = Column(REAL(5))

    def __init__(self, champ_id, k_r, k_w, d_r, d_w, a_r, a_w, kda_r, kda_w,
                 dd_r, dd_w, dt_r, dt_w, dr_r, dr_w):
        self.champ_id = champ_id
        self.kills_rylais = k_r
        self.kills_without = k_w
        self.deaths_rylais = d_r
        self.deaths_without = d_w
        self.assists_rylais = a_r
        self.assists_without = a_w
        self.kda_rylais = kda_r
        self.kda_without = kda_w
        self.damage_done_rylais = dd_r
        self.damage_done_without = dd_w
        self.damage_taken_rylais = dt_r
        self.damage_taken_without = dt_w
        self.damage_ratio_rylais = dr_r
        self.damage_ratio_without = dr_w