Ejemplo n.º 1
0
    def forward_one_sheet(self):
        """Move forward in the batch by one sheet.

           Always return True but there is no guarantee that the files really exist."""

        self.next_seq_num_in_batch += self.sided
        self.images_scanned += self.sided
        self.front_path = fullpath_to_image(self.next_seq_num_in_batch -
                                            self.sided)
        if self.sided > 1:
            self.back_path = fullpath_to_image(self.next_seq_num_in_batch -
                                               self.sided + 1)
        return True
Ejemplo n.º 2
0
    def timeoutfunc_sim(self):
        """Simulate getting an image or a pair every sim_scanner_speed msecs."""

        self.bsb.front_path = fullpath_to_image(self.bsb.next_seq_num_in_batch)
        if self.bsb.sided == 1:
            self.bsb.back_path = None
        else:
            self.bsb.back_path = fullpath_to_image(
                self.bsb.next_seq_num_in_batch + 1)

        this_seq_num = self.bsb.next_seq_num_in_batch
        GLB.db.add_image_nums(self.bsb.elections_batch_num,
                              (this_seq_num, this_seq_num + 1))

        # advance the "next image" pointer and image count
        self.bsb.next_seq_num_in_batch += self.bsb.sided
        self.bsb.images_scanned += self.bsb.sided

        # if we are simulating errors, is this the one?
        if self.bsb.dbg_throw_error_after:
            self.bsb.dbg_throw_error_after -= self.bsb.sided
            if self.bsb.dbg_throw_error_after <= 0:
                # yes, simulate an error now
                self.bsb.cur_stop_code = Batch_status.stop_code.OTHER_ERROR
                self.bsb.dbg_conditional_trace(
                    self.tracing, 'about to emit an error signal')

                # at this point the "erroneous" file has been entered in the database and is
                # reflected in the bsb as having been processed
                self.scan_error_sig.emit()
                return

        # self.bsb.dbg_conditional_trace(True, 'after a non-error sheet is simulated')
        self.bsb.dbg_conditional_trace(self.tracing,
                                       'after a non-error sheet is simulated')
        self.scan_update.emit()

        # time to end the batch?
        if self.bsb.seq_num_limit > self.bsb.next_seq_num_in_batch:
            # no, continue batch
            t = threading.Timer(self.sim_scanner_speed,
                                self.timeoutfunc_sim)  # not done with batch
            t.start()

        else:
            # end batch now
            self.bsb.cur_stop_code = Batch_status.stop_code.NORMAL
            self.bsb.seq_num_limit = self.bsb.next_seq_num_in_batch
            self.bsb.dbg_conditional_trace(self.tracing, 'batch is complete')
            self.complete_sig.emit()
Ejemplo n.º 3
0
    def back_up_one_sheet(self):
        """Back up the batch by one sheet.

           Return True if successful and false if we are already at the start of the batch."""

        if self.OK_to_backup():
            return False

        self.next_seq_num_in_batch -= self.sided
        self.images_scanned -= self.sided
        self.front_path = fullpath_to_image(self.next_seq_num_in_batch -
                                            self.sided)
        if self.sided > 1:
            self.back_path = fullpath_to_image(self.next_seq_num_in_batch -
                                               self.sided + 1)
        return True
Ejemplo n.º 4
0
    def exit_check(self, departureType='continue'):
        """Test for consistency among Admin settings. Return True if the operation should continue.
           e.g., no error or user response was "ignore"."""

        bsb = GLB.batch_status
        simulating = GLB.config['Scanning']['simulating']
        self.initial_front_path = None
        if self.initial_next_seq_num > bsb.next_seq_num_in_batch:
            deletions = range(bsb.next_seq_num_in_batch,
                              self.initial_next_seq_num)


            if not simulating:
                assert False, "How to test this?"
                for filenum in deletions:
                    f = fullpath_to_image(filenum)
                    if isfile(f):

                        os.remove(f)
                        print(f'deleting file: {f}', file = sys.stderr)

                    else:
                        print(f'not a file: {f}', file = sys.stderr)

            GLB.db.delete_images(deletions)
        return True
Ejemplo n.º 5
0
        while True:
            # get a list of rows to fix
            #
            tries += 1
            # print(f'{pid} trying {tries}', file=sys.stderr)
            # print(f'{pid} trying {tries}', )
            rows_to_fix = db.get_images_for_barcode(pid, 10)  # batch of 10
            if tries != 1: raise Exception
            tries -= 1
            # print(f'{pid} getting {tries}')
            # print(f'{pid} getting {tries}', file=sys.stderr)
            fixes = []  # tuples of (precinct, page_number, image_number)
            for row in rows_to_fix:
                image_num = row.image_number
                print(f'yyy{image_num}')
                pth = fullpath_to_image(image_num)
                print(f'zzz{pth}')
                barcode = b2str(hgbt.getBallotType(pth))
                if barcode is not None:
                    try:
                        precinct = pctids_2018_11[pct_id(barcode)]
                        pagenum = page_num(barcode)

                    except KeyError:
                        precinct = 'UNKNOWN'
                        pagenum = 'UNK'

                    fixes.append((precinct, pagenum, image_num))

                else:
                    precinct = 'UNKNOWN'
    else:
        db = dbase.ETPdb(dbase.dbconfig)

    while True:
        with HARTgetBallotType() as hgbt:
            if stopflag:
                exit(0)

            # get a list of rows to fix
            #
            rows_to_fix = db.get_images_for_barcode(10)  # batch of 10
            fixes = []  # tuples of (precinct, page_number, image_number)
            for row in rows_to_fix:
                image_num = row.image_number
                pth = fullpath_to_image(
                    image_num) + '.jpg'  # todo: fails if scanner returns .JPEG
                barcode = '000001'  # b2str(hgbt.getBallotType(pth))
                if barcode is not None:
                    try:
                        precinct = pctids_2018_11[pct_id(barcode)]
                        pagenum = page_num(barcode)

                    except KeyError:
                        precinct = 'UNKNOWN'
                        pagenum = 'UNK'

                    fixes.append((precinct, pagenum, image_num))

                else:
                    precinct = 'UNKNOWN'
                    pagenum = 'UNK'