src/dirbs/condition.py
def _calc_imeis_job(self, app_config, run_id, curr_date, virt_imei_range_start, virt_imei_range_end):
        """
        Function to calculate the IMEIs that are met by this condition (single job).

        Arguments:
            app_config: dirbs app current configuration, to extract various configs required for the job
            run_id: run_id of the currently running classification job
            curr_date: current date of the system to be used within the job
            virt_imei_range_start: start of the shard for the imeis to analyze
            virt_imei_range_end: end of the shard for the imeis to analyze

        Returns:
            tuple containing count of matched imeis and time duration of the job execution
        """
        with create_db_connection(app_config.db_config) as conn, conn.cursor() as cursor, CodeProfiler() as cp:
            dims_sql = [d.sql(conn, app_config, virt_imei_range_start, virt_imei_range_end, curr_date=curr_date)
                        for d in self.dimensions]

            # Calculate the SQL for the intersection of all dimensions
            condition_sql = sql.SQL(' INTERSECT ').join(dims_sql)

            # If sticky, we need to UNION the sql with the currently selected IMEIs
            if self.config.sticky:
                condition_sql = sql.SQL("""SELECT imei_norm
                                             FROM classification_state
                                            WHERE cond_name = {cond_name}
                                              AND virt_imei_shard >= {virt_imei_range_start}
                                              AND virt_imei_shard < {virt_imei_range_end}
                                              AND end_date IS NULL
                                                  UNION ALL {cond_results_sql}
                                        """).format(cond_name=sql.Literal(self.label),
                                                    virt_imei_range_start=sql.Literal(virt_imei_range_start),
                                                    virt_imei_range_end=sql.Literal(virt_imei_range_end),
                                                    cond_results_sql=condition_sql)

            # Make sure we only get distinct IMEIs
            condition_sql = sql.SQL("""SELECT imei_norm, calc_virt_imei_shard(imei_norm) AS virt_imei_shard
                                         FROM ({0}) non_distinct
                                     GROUP BY imei_norm""").format(condition_sql)

            # Copy results to the temp table
            tbl_name = partition_utils.imei_shard_name(base_name=self.intermediate_tbl_name(run_id),
                                                       virt_imei_range_start=virt_imei_range_start,
                                                       virt_imei_range_end=virt_imei_range_end)
            cursor.execute(sql.SQL("""INSERT INTO {intermediate_tbl}(imei_norm, virt_imei_shard) {condition_sql}""")
                           .format(intermediate_tbl=sql.Identifier(tbl_name),
                                   condition_sql=condition_sql))

            matching_imeis_count = cursor.rowcount

        return matching_imeis_count, cp.duration

        Function to calculate the IMEIs that are met by this condition (single job).

        Arguments:
            app_config: dirbs app current configuration, to extract various configs required for the job
            run_id: run_id of the currently running classification job
            curr_date: current date of the system to be used within the job
            virt_imei_range_start: start of the shard for the imeis to analyze
            virt_imei_range_end: end of the shard for the imeis to analyze

        Returns:
            tuple containing count of matched imeis and time duration of the job execution
        
Function to calculate the IMEIs that are met by this condition (single job).
Function to calculate the IMEIs that are met by this condition ( single job ) .
def _calc_imeis_job(self, app_config, run_id, curr_date, virt_imei_range_start, virt_imei_range_end):
        with create_db_connection(app_config.db_config) as conn, conn.cursor() as cursor, CodeProfiler() as cp:
            dims_sql = [d.sql(conn, app_config, virt_imei_range_start, virt_imei_range_end, curr_date=curr_date)
                        for d in self.dimensions]
            condition_sql = sql.SQL(' INTERSECT ').join(dims_sql)
            if self.config.sticky:
                condition_sql = sql.SQL("""SELECT imei_norm
                                             FROM classification_state
                                            WHERE cond_name = {cond_name}
                                              AND virt_imei_shard >= {virt_imei_range_start}
                                              AND virt_imei_shard < {virt_imei_range_end}
                                              AND end_date IS NULL
                                                  UNION ALL {cond_results_sql}
                                        """).format(cond_name=sql.Literal(self.label),
                                                    virt_imei_range_start=sql.Literal(virt_imei_range_start),
                                                    virt_imei_range_end=sql.Literal(virt_imei_range_end),
                                                    cond_results_sql=condition_sql)
            condition_sql = sql.SQL("""SELECT imei_norm, calc_virt_imei_shard(imei_norm) AS virt_imei_shard
                                         FROM ({0}) non_distinct
                                     GROUP BY imei_norm""").format(condition_sql)
            tbl_name = partition_utils.imei_shard_name(base_name=self.intermediate_tbl_name(run_id),
                                                       virt_imei_range_start=virt_imei_range_start,
                                                       virt_imei_range_end=virt_imei_range_end)
            cursor.execute(sql.SQL("""INSERT INTO {intermediate_tbl}(imei_norm, virt_imei_shard) {condition_sql}""")
                           .format(intermediate_tbl=sql.Identifier(tbl_name),
                                   condition_sql=condition_sql))
            matching_imeis_count = cursor.rowcount
        return matching_imeis_count, cp.duration
def _calc_imeis_job ( self , app_config , run_id , curr_date , virt_imei_range_start , virt_imei_range_end ) : with create_db_connection ( app_config . db_config ) as conn , conn . cursor ( ) as cursor , CodeProfiler ( ) as cp : dims_sql = [ d . sql ( conn , app_config , virt_imei_range_start , virt_imei_range_end , curr_date = curr_date ) for d in self . dimensions ] condition_sql = sql . SQL ( ' INTERSECT ' ) . join ( dims_sql ) if self . config . sticky : condition_sql = sql . SQL ( """SELECT imei_norm
                                             FROM classification_state
                                            WHERE cond_name = {cond_name}
                                              AND virt_imei_shard >= {virt_imei_range_start}
                                              AND virt_imei_shard < {virt_imei_range_end}
                                              AND end_date IS NULL
                                                  UNION ALL {cond_results_sql}
                                        """ ) . format ( cond_name = sql . Literal ( self . label ) , virt_imei_range_start = sql . Literal ( virt_imei_range_start ) , virt_imei_range_end = sql . Literal ( virt_imei_range_end ) , cond_results_sql = condition_sql ) condition_sql = sql . SQL ( """SELECT imei_norm, calc_virt_imei_shard(imei_norm) AS virt_imei_shard
                                         FROM ({0}) non_distinct
                                     GROUP BY imei_norm""" ) . format ( condition_sql ) tbl_name = partition_utils . imei_shard_name ( base_name = self . intermediate_tbl_name ( run_id ) , virt_imei_range_start = virt_imei_range_start , virt_imei_range_end = virt_imei_range_end ) cursor . execute ( sql . SQL ( """INSERT INTO {intermediate_tbl}(imei_norm, virt_imei_shard) {condition_sql}""" ) . format ( intermediate_tbl = sql . Identifier ( tbl_name ) , condition_sql = condition_sql ) ) matching_imeis_count = cursor . rowcount return matching_imeis_count , cp . duration
Function to calculate the IMEIs that are met by this condition (single job).
Function to calculate the IMEIs that are met by this condition ( single job ) .
"""
        Function to calculate the IMEIs that are met by this condition (single job).

        Arguments:
            app_config: dirbs app current configuration, to extract various configs required for the job
            run_id: run_id of the currently running classification job
            curr_date: current date of the system to be used within the job
            virt_imei_range_start: start of the shard for the imeis to analyze
            virt_imei_range_end: end of the shard for the imeis to analyze

        Returns:
            tuple containing count of matched imeis and time duration of the job execution
        """ # Calculate the SQL for the intersection of all dimensions # If sticky, we need to UNION the sql with the currently selected IMEIs # Make sure we only get distinct IMEIs # Copy results to the temp table
tuple containing count of matched imeis and time duration of the job execution
tuple containing count of matched imeis and time duration of the job execution
self
app_config
dirbs app current configuration, to extract various configs required for the job
dirbs app current configuration to extract various configs required for the job
run_id
run_id of the currently running classification job
run_id of the currently running classification job
curr_date
current date of the system to be used within the job
current date of the system to be used within the job
virt_imei_range_start
start of the shard for the imeis to analyze
start of the shard for the imeis to analyze
virt_imei_range_end
end of the shard for the imeis to analyze
end of the shard for the imeis to analyze