Ejemplo n.º 1
0
    def _GetEventFilterSqlExpression(self, ev_filter):  # pylint: disable=C0103
        """
        Generic Function to build SQLBinaryExpression for the given Filter

        :param ev_filter: Minidom XML filter entry
        :return: SQLBinaryExpression representing filter for Database
        """
        field_name = self._GetAttributeValue(FILTERDATA_FIELD, ev_filter)
        comp = self._GetAttributeValue(FILTERDATA_COMPARITOR, ev_filter)
        value = self.GetValue(
            self._GetAttributeValue(FILTERDATA_VALUE, ev_filter),
            self._GetAttributeValue(FILTERDATA_VTYPE, ev_filter))

        if field_name in self._attribute_name_list:
            # if the field is Attribute
            name_cond = SQLBinaryExpr(COL_NAME_EVENTS_VIEW_NAME, OP_EQ,
                                      SQLLiteral(field_name))
            val_cond = SQLBinaryExpr(COL_NAME_EVENTS_VIEW_VALUE, comp, value)
            return SQLBinaryExpr(name_cond, OP_AND, val_cond)

        elif field_name == FILTERDATA_ATTRIB_DURATION:
            # special case for event duration if it is not an attribute
            field_name = SQLBinaryExpr(
                SQLColumnExpr(SQLTableExpr(TABLE_NAME_EVENTS_ATTRIBUTES_VIEW),
                              COL_NAME_EVENTS_VIEW_ENDABSTS), OP_SUB,
                SQLColumnExpr(SQLTableExpr(TABLE_NAME_EVENTS_ATTRIBUTES_VIEW),
                              COL_NAME_EVENTS_VIEW_BEGINABSTS))

        return SQLBinaryExpr(field_name, comp, value)
Ejemplo n.º 2
0
    def get_stateids_from_type(self, name):
        """
        Get the state ids for a meta type.

        :param name: Meta Type Name.
        :type name: String
        :return: Meta State IDs
        :rtype: List
        """
        tblms = TABLE_NAME_MET_STATES
        tblmt = TABLE_NAME_MET_TYPES
        join_1 = SQLJoinExpr(
            SQLTableExpr(tblms), OP_INNER_JOIN, SQLTableExpr(tblmt),
            SQLBinaryExpr(
                SQLColumnExpr(SQLTableExpr(tblms), COL_NAME_MET_STATES_TYPEID),
                OP_EQ,
                SQLColumnExpr(SQLTableExpr(tblmt), COL_NAME_MET_TYPES_TYPEID)))

        cond = SQLBinaryExpr(
            SQLColumnExpr(SQLTableExpr(tblmt), COL_NAME_MET_TYPES_NAME), OP_EQ,
            SQLLiteral(name.upper()))
        col_list = [
            SQLColumnExpr(SQLTableExpr(tblms), COL_NAME_MET_DATA_STATEID)
        ]
        stateids = self.select_generic_data(select_list=col_list,
                                            table_list=[join_1],
                                            where=cond)
        return stateids
Ejemplo n.º 3
0
    def _sim_file_condition(simfile_id=None,
                            measid_c1=None,
                            binfile_c1=None,
                            measid_c2=None):
        """
        Generic function for creating SQL Condition for SIM_FILE

        :param simfile_id: simulation id i.e. primary key value
        :type simfile_id: int
        :param measid_c1: Measurement ID for the camera recording
        :type measid_c1: int
        :param binfile_c1: Bsig File path corresponding to camera recording
        :type binfile_c1: str
        :param measid_c2: Measurement ID for the radar recording
        :type measid_c2: int
        """

        cond = None
        if simfile_id is not None:
            cond = SQLBinaryExpr(COLUMN_NAME_SIM_FILES_SIMID, OP_EQ,
                                 simfile_id)

        if measid_c1 is not None:
            if cond is None:
                cond = SQLBinaryExpr(COLUMN_NAME_SIM_FILES_MEASID_C1, OP_EQ,
                                     measid_c1)
            else:
                cond = SQLBinaryExpr(
                    cond, OP_AND,
                    SQLBinaryExpr(COLUMN_NAME_SIM_FILES_MEASID_C1, OP_EQ,
                                  measid_c1))

        if binfile_c1 is not None:
            if cond is None:
                cond = SQLBinaryExpr(COLUMN_NAME_SIM_FILES_BINFILE_C1, OP_EQ,
                                     SQLLiteral(binfile_c1.lower()))
            else:
                cond = SQLBinaryExpr(
                    cond, OP_AND,
                    SQLBinaryExpr(COLUMN_NAME_SIM_FILES_BINFILE_C1, OP_EQ,
                                  SQLLiteral(binfile_c1.lower())))

        if measid_c2 is not None:
            if cond is None:
                cond = SQLBinaryExpr(COLUMN_NAME_SIM_FILES_MEASID_C2, OP_EQ,
                                     measid_c2)
            else:
                cond = SQLBinaryExpr(
                    cond, OP_AND,
                    SQLBinaryExpr(COLUMN_NAME_SIM_FILES_MEASID_C2, OP_EQ,
                                  measid_c2))
        return cond
Ejemplo n.º 4
0
    def _DecodeEventFilters(self):  # pylint: disable=C0103
        """
        Decode Filter XML filter setting file for EVENT and Prepare all the statements for Filtermaps
        """
        self._ReadXMLConfig()
        filtermaps = self.GetFilterMaps()
        filters = self.GetFilters()

        for filtermap_key, filtermap_domdict in filtermaps.items():
            # filtermap_dict = self._GetAttributeValue(filtermap)
            if FILTERMAPDATA_STATEMENT in filtermap_domdict:
                cond = None
                statement = filtermap_domdict[FILTERMAPDATA_STATEMENT].strip()
                relation = None
                for entry in statement.split(" "):

                    if entry.upper() in FILTERMAPDATA_FILTER_JOINS:
                        if cond is None:
                            raise StandardError(
                                "The filter configuration are invalid")
                        else:
                            relation = entry
                    else:
                        if cond is None:
                            cond = self._GetEventFilterSqlExpression(
                                filters[entry])
                        else:
                            if relation is None:
                                raise StandardError(
                                    "The filter configuration are invalid")
                            else:
                                cond = SQLBinaryExpr(
                                    cond, relation.upper(),
                                    self._GetEventFilterSqlExpression(
                                        filters[entry]))
                                relation = None

                if self._trid is not None:
                    if cond is not None:
                        cond = SQLBinaryExpr(
                            cond, OP_AND,
                            SQLBinaryExpr(COL_NAME_EVENTS_VIEW_TRID, OP_EQ,
                                          self._trid))
                    else:
                        cond = SQLBinaryExpr(COL_NAME_EVENTS_VIEW_TRID, OP_EQ,
                                             self._trid)

                self._cond[filtermap_key] = cond

        return True
Ejemplo n.º 5
0
    def get_enabled_environment_names_for_type(self, envtypeid, disable=None):  # pylint: disable=C0103
        """
        Get existing not disabled Environment names based on Environment Type Identifier.

        :param envtypeid: The Environment Type Identifier.
        :type envtypeid: Integer
        :param disable: The disable key (For e.g '0')
        :type disable: Integer
        :return: Returns the Environment names related to an environment type which are not disabled.
        :rtype: list
        """
        record_name = []
        cond = SQLBinaryExpr(COL_NAME_ENVIRONMENT_ENVTYPEID, OP_EQ, envtypeid)
        entries = self.select_generic_data(select_list=[COL_NAME_ENVIRONMENT_NAME, COL_NAME_ENVIRONMENT_DESC],
                                           table_list=[TABLE_NAME_ENVIRONMENT], where=cond)
        if len(entries) <= 0:
            self._log.warning(str("Environment with type id '%s' does not exists in the FCT  database." % envtypeid))
        else:
            for i in range(0, len(entries)):
                if entries[i][COL_NAME_ENVIRONMENT_DESC] is None:
                    record_name.append(entries[i][COL_NAME_ENVIRONMENT_NAME])
                elif entries[i][COL_NAME_ENVIRONMENT_DESC][0] != disable:
                    record_name.append(entries[i][COL_NAME_ENVIRONMENT_NAME])
                else:
                    pass
        return record_name
Ejemplo n.º 6
0
    def _get_meta_states_typeid(self, stateid):
        """
        Get Meta Type ID from Meta State ID

        :param stateid: Meta State ID.
        :type stateid: Integer
        :return: Meta Type ID
        :rtype: Integer
        """
        record = {}
        cond = SQLBinaryExpr(COL_NAME_MET_STATES_STATEID, OP_EQ, stateid)
        entries = self.select_generic_data(table_list=[TABLE_NAME_MET_STATES],
                                           where=cond)
        if len(entries) <= 0:
            self._log.warning(
                str("Meta States with id '%s' does not exists in the MET_STATES table."
                    % stateid))
        elif len(entries) > 1:
            self._log.info(
                str("More than one Meta States exists with id '%s'." %
                    stateid))
            record = entries
        else:
            record = entries[0]
        return record[COL_NAME_MET_STATES_TYPEID]
Ejemplo n.º 7
0
    def _get_meta_types_pickvalue(self, typeid):
        """
        Get the pick value state of a meta type.

        :param typeid: Type ID of the Meta Type
        :type typeid: Integer
        :return: Pick Value state
        :rtype: Boolean
        """
        record = {}
        cond = SQLBinaryExpr(COL_NAME_MET_TYPES_TYPEID, OP_EQ, typeid)
        entries = self.select_generic_data(table_list=[TABLE_NAME_MET_TYPES],
                                           where=cond)
        if len(entries) <= 0:
            self._log.warning(
                str("Meta Types with record '%s' does not exists in the MET_TYPES table."
                    % typeid))
        elif len(entries) > 1:
            self._log.info(
                str("More than one Meta Types exists with record '%s'." %
                    typeid))
            record = entries
        else:
            record = entries[0]
        return record[COL_NAME_MET_TYPES_PICK_VALUE]
Ejemplo n.º 8
0
    def _get_meta_state_condition(meta_state):
        """
        Get the condition expression to access the meta state.

        :param meta_state: Meta State record.
        :type meta_state: Dict
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        name = meta_state[COL_NAME_MET_STATES_NAME]
        typeid = meta_state[COL_NAME_MET_STATES_TYPEID]
        cond1 = SQLBinaryExpr(COL_NAME_MET_STATES_NAME, OP_EQ,
                              SQLLiteral(name))
        cond2 = SQLBinaryExpr(COL_NAME_MET_STATES_TYPEID, OP_EQ,
                              SQLLiteral(typeid))
        cond = SQLBinaryExpr(cond1, OP_AND, cond2)
        return cond
Ejemplo n.º 9
0
    def _get_event_scenario_condition(meas_id, start, end):
        """
        Get the condition expression to access the Scenario.

        :param meas_id: ID of the Measurement
        :type meas_id: Integer
        :param start: The Event Start Timestamp.
        :type start: Integer
        :param end: The Event End Timestamp.
        :type end: Integer
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        cond1 = SQLBinaryExpr(COL_NAME_SCENARIO_STARTABSTS, OP_LEQ, start)
        cond2 = SQLBinaryExpr(COL_NAME_SCENARIO_ENDABSTS, OP_GEQ, end)
        cond3 = SQLBinaryExpr(COL_NAME_SCENARIO_MEASID, OP_EQ, meas_id)
        cond_tmp = SQLBinaryExpr(cond1, OP_AND, cond2)
        cond = SQLBinaryExpr(cond_tmp, OP_AND, cond3)
        return cond
Ejemplo n.º 10
0
    def update_scenario(self, scenario, where=None, updated_start=None, updated_end=None):
        """
        Update existing Scenario records.

        :param scenario: The Scenario record to be updated.
        :type scenario: Dict
        :param where: Special condition for selecting the scenario
        :type where: SQLBinaryExpression
        :param updated_start: Updated Scenario Start Timestamp
        :type updated_start: Integer
        :param updated_end: Updated Scenario End Timestamp
        :type updated_end: Integer
        :return: Returns the number of affected Scenario.
        :rtype: Integer
        """
        rowcount = 0
        cond1 = self._get_scenario_condition(scenario[COL_NAME_SCENARIO_MEASID])
        cond2 = SQLBinaryExpr(COL_NAME_SCENARIO_SCENARIOID, OP_NEQ, self.__get_scenario_id(scenario))
        cond = SQLBinaryExpr(cond1, OP_AND, cond2)
        entries = self.select_generic_data(table_list=[TABLE_NAME_SCENARIO], where=cond)
        if where is None:
            where = self._get_scenario_condition(scenario[COL_NAME_SCENARIO_MEASID],
                                                 scenario[COL_NAME_SCENARIO_STARTABSTS],
                                                 scenario[COL_NAME_SCENARIO_ENDABSTS])
        if updated_start is not None:
            scenario[COL_NAME_SCENARIO_STARTABSTS] = updated_start
        if updated_end is not None:
            scenario[COL_NAME_SCENARIO_ENDABSTS] = updated_end
        if scenario[COL_NAME_SCENARIO_STARTABSTS] >= scenario[COL_NAME_SCENARIO_ENDABSTS]:
            tmp = "(TimeIntegrityError) Scenario Begin Timestamp is not less than the Scenario End timestamp. \
                %d >= %d" % (scenario[COL_NAME_SCENARIO_STARTABSTS], scenario[COL_NAME_SCENARIO_ENDABSTS])
            raise AdasDBError(tmp)
        if (scenario is not None) and (len(scenario) != 0):
            overlap = self._check_overlap(scenario, entries)
            if overlap is 0:
                rowcount = self.update_generic_data(scenario, TABLE_NAME_SCENARIO, where)
            else:
                # tmp = "'%s' " % (scenario)
                tmp = "Scenario cannot be added to generic label database because the time range is overlapping "
                tmp += "with %s other existing Scenario(s)." % overlap
                raise AdasDBError(tmp)
        return rowcount
Ejemplo n.º 11
0
    def _get_meta_type_condition(name):
        """
        Get the condition expression to access the Scenario.

        :param name: State ID
        :type name: String
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        cond = SQLBinaryExpr(COL_NAME_MET_TYPES_NAME, OP_EQ,
                             SQLLiteral(name.upper()))
        return cond
Ejemplo n.º 12
0
    def __get_criticality_condition(self, name):
        """
        Get the condition expression to access the criticality.

        :param name: Name of the criticality
        :type name: String
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        cond = SQLBinaryExpr(SQLFuncExpr(self.db_func_map[DB_FUNC_NAME_UPPER],
                             COL_NAME_CRITICALITY_NAME), OP_EQ, SQLLiteral(name.upper()))
        return cond
Ejemplo n.º 13
0
    def __get_ego_behaviour_condition(self, name):
        """
        Get the condition expression to access the EgoBehaviour.

        :param name: Name of the EgoBehaviour
        :type name: Sring
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        cond = SQLBinaryExpr(SQLFuncExpr(self.db_func_map[DB_FUNC_NAME_LOWER],
                             COL_NAME_CRITICALITY_NAME), OP_EQ, SQLLiteral(name.lower()))
        return cond
Ejemplo n.º 14
0
    def __get_environment_condition(self, name):
        """
        Get the condition expression to access the Environment.

        :param name: Name of the Environment
        :type name: String
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        cond = SQLBinaryExpr(SQLFuncExpr(self.db_func_map[DB_FUNC_NAME_LOWER],
                             COL_NAME_ENVIRONMENT_NAME), OP_EQ, SQLLiteral(name.lower()))
        return cond
Ejemplo n.º 15
0
    def get_environment_id(self, name, envtypeid):
        """
        Get existing Environment ID based on Environment Type Identifier.

        :param name: The Environment name.
        :type name: String
        :param envtypeid: Environment Type ID
        :type envtypeid: Integer
        :return: Returns the Environment ID.
        :rtype: Integer
        """
        cond1 = self.__get_environment_condition(name)
        cond2 = SQLBinaryExpr(COL_NAME_ENVIRONMENT_ENVTYPEID, OP_EQ, envtypeid)
        cond = SQLBinaryExpr(cond1, OP_AND, cond2)
        entries = self.select_generic_data(table_list=[TABLE_NAME_ENVIRONMENT], where=cond)
        if len(entries) <= 0:
            self._log.warning(str("Environment with name '%s' does not exists in the FCT  database." % name))
        elif len(entries) > 1:
            self._log.warning(str("Environment with name '%s' cannot be resolved because it is ambiguous." % name))
        else:
            record_id = entries[0][COL_NAME_ENVIRONMENT_ENVID]
            return record_id
Ejemplo n.º 16
0
    def _get_existing_stateid(self, measid, stateid):
        """
        Get the existing state id for a measid.

        :param measid: Measurement ID.
        :type measid: Integer
        :param stateid: Meta State ID.
        :type stateid: Integer
        :return: Meta State ID
        :rtype: Integer
        """
        typeid = self._get_meta_states_typeid(stateid)
        tblmd = TABLE_NAME_MET_DATA
        tblms = TABLE_NAME_MET_STATES
        join_1 = SQLJoinExpr(
            SQLTableExpr(tblmd), OP_INNER_JOIN, SQLTableExpr(tblms),
            SQLBinaryExpr(
                SQLColumnExpr(SQLTableExpr(tblmd), COL_NAME_MET_DATA_STATEID),
                OP_EQ,
                SQLColumnExpr(SQLTableExpr(tblms),
                              COL_NAME_MET_STATES_STATEID)))

        cond1 = SQLBinaryExpr(
            SQLColumnExpr(SQLTableExpr(tblmd), COL_NAME_MET_DATA_MEASID),
            OP_EQ, measid)
        cond2 = SQLBinaryExpr(
            SQLColumnExpr(SQLTableExpr(tblms), COL_NAME_MET_STATES_TYPEID),
            OP_EQ, typeid)
        cond = SQLBinaryExpr(cond1, OP_AND, cond2)
        col_list = [
            SQLColumnExpr(SQLTableExpr(tblmd), COL_NAME_MET_DATA_STATEID)
        ]
        ex_stateid = self.select_generic_data(select_list=col_list,
                                              table_list=[join_1],
                                              where=cond)
        if ex_stateid == []:
            return stateid
        else:
            return ex_stateid[0][COL_NAME_MET_DATA_STATEID]
Ejemplo n.º 17
0
    def _get_meta_data_condition(self, meta_data):
        """
        Get the condition expression to access the meta data.

        :param meta_data: The meta_data record.
        :type meta_data: Dict
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        pick_val = self._get_pickvalue_from_stateid(
            meta_data[COL_NAME_MET_DATA_STATEID])
        if pick_val == 0 and COL_NAME_MET_DATA_ABSTS not in meta_data:
            existing_stateid = self._get_existing_stateid(
                meta_data[COL_NAME_MET_DATA_MEASID],
                meta_data[COL_NAME_MET_DATA_STATEID])
        else:
            existing_stateid = meta_data[COL_NAME_MET_DATA_STATEID]
        cond1 = SQLBinaryExpr(COL_NAME_MET_DATA_MEASID, OP_EQ,
                              meta_data[COL_NAME_MET_DATA_MEASID])
        if (COL_NAME_MET_DATA_ABSTS
                in meta_data) and (COL_NAME_MET_DATA_STATEID in meta_data):
            cond2 = SQLBinaryExpr(COL_NAME_MET_DATA_ABSTS, OP_EQ,
                                  meta_data[COL_NAME_MET_DATA_ABSTS])
            cond3 = SQLBinaryExpr(COL_NAME_MET_DATA_STATEID, OP_EQ,
                                  existing_stateid)
            cond_tmp = SQLBinaryExpr(cond1, OP_AND, cond2)
            cond = SQLBinaryExpr(cond_tmp, OP_AND, cond3)
        elif (COL_NAME_MET_DATA_ABSTS
              not in meta_data) and (COL_NAME_MET_DATA_STATEID in meta_data):
            cond3 = SQLBinaryExpr(COL_NAME_MET_DATA_STATEID, OP_EQ,
                                  existing_stateid)
            cond = SQLBinaryExpr(cond1, OP_AND, cond3)
        elif (COL_NAME_MET_DATA_ABSTS
              in meta_data) and (COL_NAME_MET_DATA_STATEID not in meta_data):
            cond2 = SQLBinaryExpr(COL_NAME_MET_DATA_ABSTS, OP_EQ,
                                  meta_data[COL_NAME_MET_DATA_ABSTS])
            cond = SQLBinaryExpr(cond1, OP_AND, cond2)
        else:
            cond = cond1
        return cond
Ejemplo n.º 18
0
    def update_ego_behaviour(self, egobehaviour, where=None):
        """
        Update existing egobehaviour records.

        :param egobehaviour: The egobehaviour record update.
        :type egobehaviour: Dict
        :param where: The condition to be fulfilled by the egobehaviour to the updated, by default based on ID.
        :type where: SQLBinaryExpression
        :return: Returns the number of affected egobehaviour.
        :rtype: Integer
        """
        rowcount = 0
        if where is None:
            where = SQLBinaryExpr(COL_NAME_EGOBEHAVIOUR_EBID, OP_EQ, egobehaviour[COL_NAME_EGOBEHAVIOUR_EBID])
        if (egobehaviour is not None) and (len(egobehaviour) != 0):
            rowcount = self.update_generic_data(egobehaviour, TABLE_NAME_EGOBEHAVIOUR, where)
        return rowcount
Ejemplo n.º 19
0
    def update_criticality(self, criticality, where=None):
        """
        Update existing criticality records.

        :param criticality: The criticality record update.
        :type criticality: Dict
        :param where: The condition to be fulfilled by the criticality to the updated, by default based on ID.
        :type where: SQLBinaryExpression
        :return: Returns the number of affected criticality.
        :rtype: Integer
        """
        rowcount = 0
        if where is None:
            where = SQLBinaryExpr(COL_NAME_CRITICALITY_CID, OP_EQ, criticality[COL_NAME_CRITICALITY_CID])
        if (criticality is not None) and (len(criticality) != 0):
            rowcount = self.update_generic_data(criticality, TABLE_NAME_CRITICALITY, where)
        return rowcount
Ejemplo n.º 20
0
    def get_environment_name(self, envid):
        """
        Get existing Environment name based on Environment Identifier.

        :param envid: The Environment Identifier.
        :type envid: Integer
        :return: Returns the Environment names related to an environment identifier.
        :rtype: String
        """
        cond = SQLBinaryExpr(COL_NAME_ENVIRONMENT_ENVID, OP_EQ, envid)
        entries = self.select_generic_data(select_list=[COL_NAME_ENVIRONMENT_NAME],
                                           table_list=[TABLE_NAME_ENVIRONMENT], where=cond)
        if len(entries) <= 0:
            self._log.warning(str("Environment with id '%s' does not exists in the FCT  database." % envid))
        elif len(entries) > 1:
            self._log.warning(str("Environment with id '%s' cannot be resolved because it is ambiguous." % envid))
        else:
            return entries[0][COL_NAME_ENVIRONMENT_NAME]
Ejemplo n.º 21
0
    def get_environment_names_for_type(self, envtypeid):
        """
        Get existing Environment names based on Environment Type Identifier.

        :param envtypeid: The Environment Type Identifier.
        :type envtypeid: Integer
        :return: Returns the Environment names related to an environment type.
        :rtype: list
        """
        record_name = []
        cond = SQLBinaryExpr(COL_NAME_ENVIRONMENT_ENVTYPEID, OP_EQ, envtypeid)
        entries = self.select_generic_data(select_list=[COL_NAME_ENVIRONMENT_NAME],
                                           table_list=[TABLE_NAME_ENVIRONMENT], where=cond)
        if len(entries) <= 0:
            self._log.warning(str("Environment with type id '%s' does not exists in the FCT  database." % envtypeid))
        else:
            for i in range(0, len(entries)):
                record_name.append(entries[i][COL_NAME_ENVIRONMENT_NAME])
        return record_name
Ejemplo n.º 22
0
    def delete_scenario(self, scenario):
        """
        Delete existing Scenario record.

        :param scenario: The Scenario record to be deleted.
        :type scenario: Dict
        :return: Returns the number of affected Scenario.
        :rtype: Integer
        """
        rowcount = 0
        if (scenario is not None) and (len(scenario) != 0):
            if COL_NAME_SCENARIO_SCENARIOID in scenario and \
                    (scenario[COL_NAME_SCENARIO_SCENARIOID] is not None):
                cond = SQLBinaryExpr(COL_NAME_SCENARIO_SCENARIOID, OP_EQ, scenario[COL_NAME_SCENARIO_SCENARIOID])
            else:
                cond = self._get_scenario_condition(scenario[COL_NAME_SCENARIO_MEASID],
                                                    scenario[COL_NAME_SCENARIO_STARTABSTS],
                                                    scenario[COL_NAME_SCENARIO_ENDABSTS])
            rowcount = self.delete_generic_data(TABLE_NAME_SCENARIO, where=cond)
        return rowcount
Ejemplo n.º 23
0
    def get_criticality_name(self, cid):
        """
        Get criticality name.

        :param cid: The criticality ID.
        :type cid: Integer
        :return: Returns the criticality name.
        :rtype: String
        """
        record = {}
        cond = SQLBinaryExpr(COL_NAME_CRITICALITY_CID, OP_EQ, cid)
        entries = self.select_generic_data(table_list=[TABLE_NAME_CRITICALITY], where=cond)
        if len(entries) <= 0:
            self._log.info(str("Criticality with cid '%s' does not exists in the FCT  database." % cid))
        elif len(entries) > 1:
            self._log.warning(str("Criticality with cid '%s' cannot be resolved because it is ambiguous." % cid))
            record = entries
        else:
            record = entries[0]
        return record[COL_NAME_CRITICALITY_NAME]
Ejemplo n.º 24
0
    def _get_rec_filepath(self, measid_c2):
        """
        Function use to verify if the measurement Id
        really correspond recfile path

        :param measid_c2: Measurement Id
        :type measid_c2: int
        :return: File path of recording
        :rtype: StringSQLBinaryExpression
        """

        cond = SQLBinaryExpr(COL_NAME_FILES_MEASID, OP_EQ, measid_c2)
        entries = self.select_generic_data(
            select_list=[COL_NAME_FILES_FILEPATH],
            table_list=[TABLE_NAME_FILES],
            where=cond)
        if len(entries) == 1:
            measid = entries[0][COL_NAME_FILES_FILEPATH].lower()
            return measid
        else:
            return None
Ejemplo n.º 25
0
    def get_event_scenario(self, meas_id, start, end):
        """
        Get corresponding scenario record from the event.

        :param meas_id: The measurement id.
        :type meas_id: Integer
        :param start: The Event Start Timestamp.
        :type start: Integer
        :param end: The Event End Timestamp.
        :type end: Integer
        :return: Returns the Scenario record.
        :rtype: Dict
        """
        record = {}
#        Cache last recfile scenario if doesnt have any scenario at then dont execute actual and return blank dict
        if meas_id == self.__last_measid:
            if self.__no_scenario_last_measid:
                return record
        else:
            self.__last_measid = meas_id
            cond3 = SQLBinaryExpr(COL_NAME_SCENARIO_MEASID, OP_EQ, meas_id)
            entries = self.select_generic_data(select_list=[SQLBinaryExpr("count(*)", OP_AS, "COUNT")],
                                               table_list=[TABLE_NAME_SCENARIO],
                                               where=cond3)
            self.__no_scenario_last_measid = entries[0]["COUNT"] == 0

        sql_param = {"1": start, "2": end, "3": meas_id}
        cond1 = SQLBinaryExpr(COL_NAME_SCENARIO_STARTABSTS, OP_LEQ, ":1")
        cond2 = SQLBinaryExpr(COL_NAME_SCENARIO_ENDABSTS, OP_GEQ, ":2")
        cond3 = SQLBinaryExpr(COL_NAME_SCENARIO_MEASID, OP_EQ, ":3")
        cond_tmp = SQLBinaryExpr(cond1, OP_AND, cond2)
        cond = SQLBinaryExpr(cond_tmp, OP_AND, cond3)
        entries = self.select_generic_data(table_list=[TABLE_NAME_SCENARIO], where=cond, sqlparams=sql_param)
        if len(entries) <= 0:
            self._log.warning(str("Scenario with meas_id '%s' does not exists in the FCT  database." % meas_id))
        elif len(entries) > 1:
            self._log.warning(str("Scenario with meas_id '%s' cannot be resolved because it is ambiguous." % meas_id))
        else:
            record = entries[0]
        return record
Ejemplo n.º 26
0
    def _get_scenario_condition(meas_id, start=None, end=None):
        """
        Get the condition expression to access the Scenario.

        :param meas_id: ID of the Measurement
        :type meas_id: Integer
        :param start: Scenario Start Timestamp
        :type start: Integer
        :param end: Scenario End Timestamp
        :type end: Integer
        :return: Returns the condition expression
        :rtype: SQLBinaryExpression
        """
        if start is None or end is None:
            cond = SQLBinaryExpr(COL_NAME_SCENARIO_MEASID, OP_EQ, meas_id)
        else:
            cond1 = SQLBinaryExpr(COL_NAME_SCENARIO_STARTABSTS, OP_EQ, start)
            cond2 = SQLBinaryExpr(COL_NAME_SCENARIO_ENDABSTS, OP_EQ, end)
            cond3 = SQLBinaryExpr(COL_NAME_SCENARIO_MEASID, OP_EQ, meas_id)
            cond_tmp = SQLBinaryExpr(cond1, OP_AND, cond2)
            cond = SQLBinaryExpr(cond_tmp, OP_AND, cond3)
        return cond