src/dirbs/importer/operator_data_importer.py
def _check_for_leading_zeroes(self):
        """Method to validate that the input file did not have leading zeroes stripped from it."""
        with self._conn.cursor() as cursor:
            metric_key = 'leading_zero'
            leading_digit_query = sql.SQL('SELECT COUNT(*) FROM {0} WHERE SUBSTRING(imei, 1, 1) = %s') \
                .format(self._staging_tbl_identifier)

            # Work out if there are more TACs that start with 1 than 0. If so, zeroes have likely been stripped
            cursor.execute(leading_digit_query, ['0'])
            leading_zero_count = cursor.fetchone()[0]
            cursor.execute(leading_digit_query, ['1'])
            leading_one_count = cursor.fetchone()[0]
            if leading_one_count > leading_zero_count:
                return False, 'Failed leading zero check - suspect leading 0s have ' \
                              'been removed from IMEIs. Import aborted - no rows have been imported.', \
                              metric_key

            # Get all IMEIs starting with 1 taking first 7 digits and compare to digits 2-8 of GSMA TAC DB TAC
            cursor.execute(sql.SQL("""SELECT COUNT(*)
                                        FROM {0}
                                  INNER JOIN gsma_data ON SUBSTRING(imei, 1, 7) = SUBSTRING(tac, 2, 8)
                                       WHERE SUBSTRING(imei, 1, 1) = '1'
                                         AND SUBSTRING(tac, 1, 1) = '0'""")
                           .format(self._staging_tbl_identifier))
            suspect_missing_zero_imeis = cursor.fetchone()[0]

            leading_zero_suspect_limit = self._leading_zero_suspect_limit
            if leading_one_count > 1 and suspect_missing_zero_imeis / leading_one_count > leading_zero_suspect_limit:
                return False, 'Too many IMEIs that start with 1 match the TAC DB when prepended with 0', metric_key

            return True, 'Leading zero check passed', metric_key
Method to validate that the input file did not have leading zeroes stripped from it.
Method to validate that the input file did not have leading zeroes stripped from it.
Method to validate that the input file did not have leading zeroes stripped from it .
def _check_for_leading_zeroes(self):
        with self._conn.cursor() as cursor:
            metric_key = 'leading_zero'
            leading_digit_query = sql.SQL('SELECT COUNT(*) FROM {0} WHERE SUBSTRING(imei, 1, 1) = %s') \
                .format(self._staging_tbl_identifier)
            cursor.execute(leading_digit_query, ['0'])
            leading_zero_count = cursor.fetchone()[0]
            cursor.execute(leading_digit_query, ['1'])
            leading_one_count = cursor.fetchone()[0]
            if leading_one_count > leading_zero_count:
                return False, 'Failed leading zero check - suspect leading 0s have ' \
                              'been removed from IMEIs. Import aborted - no rows have been imported.', \
                              metric_key
            cursor.execute(sql.SQL("""SELECT COUNT(*)
                                        FROM {0}
                                  INNER JOIN gsma_data ON SUBSTRING(imei, 1, 7) = SUBSTRING(tac, 2, 8)
                                       WHERE SUBSTRING(imei, 1, 1) = '1'
                                         AND SUBSTRING(tac, 1, 1) = '0'""")
                           .format(self._staging_tbl_identifier))
            suspect_missing_zero_imeis = cursor.fetchone()[0]
            leading_zero_suspect_limit = self._leading_zero_suspect_limit
            if leading_one_count > 1 and suspect_missing_zero_imeis / leading_one_count > leading_zero_suspect_limit:
                return False, 'Too many IMEIs that start with 1 match the TAC DB when prepended with 0', metric_key
            return True, 'Leading zero check passed', metric_key
def _check_for_leading_zeroes ( self ) : with self . _conn . cursor ( ) as cursor : metric_key = 'leading_zero' leading_digit_query = sql . SQL ( 'SELECT COUNT(*) FROM {0} WHERE SUBSTRING(imei, 1, 1) = %s' ) . format ( self . _staging_tbl_identifier ) cursor . execute ( leading_digit_query , [ '0' ] ) leading_zero_count = cursor . fetchone ( ) [ 0 ] cursor . execute ( leading_digit_query , [ '1' ] ) leading_one_count = cursor . fetchone ( ) [ 0 ] if leading_one_count > leading_zero_count : return False , 'Failed leading zero check - suspect leading 0s have ' 'been removed from IMEIs. Import aborted - no rows have been imported.' , metric_key cursor . execute ( sql . SQL ( """SELECT COUNT(*)
                                        FROM {0}
                                  INNER JOIN gsma_data ON SUBSTRING(imei, 1, 7) = SUBSTRING(tac, 2, 8)
                                       WHERE SUBSTRING(imei, 1, 1) = '1'
                                         AND SUBSTRING(tac, 1, 1) = '0'""" ) . format ( self . _staging_tbl_identifier ) ) suspect_missing_zero_imeis = cursor . fetchone ( ) [ 0 ] leading_zero_suspect_limit = self . _leading_zero_suspect_limit if leading_one_count > 1 and suspect_missing_zero_imeis / leading_one_count > leading_zero_suspect_limit : return False , 'Too many IMEIs that start with 1 match the TAC DB when prepended with 0' , metric_key return True , 'Leading zero check passed' , metric_key
Method to validate that the input file did not have leading zeroes stripped from it.
Method to validate that the input file did not have leading zeroes stripped from it .
"""Method to validate that the input file did not have leading zeroes stripped from it.""" # Work out if there are more TACs that start with 1 than 0. If so, zeroes have likely been stripped # Get all IMEIs starting with 1 taking first 7 digits and compare to digits 2-8 of GSMA TAC DB TAC
self