def loop_step(input, input2, output, stop_event):
    '''
    For every csv file in input make a prediction, if predicted as posible
    double the name is stored in output file.
    '''
    # directory/file check
    if not os.path.isdir(input):
        return 0

    if not os.path.isfile(input2):
        if show:
            logger.critical('Model, {0}, not found.'.format(input2))
        return 0

    # load the logistic regression model
    model = joblib.load(input2)
    # encrypt input directory file
    encinput = os.fsencode(input)
    # loop through every element in input directory
    for file in os.listdir(encinput):
        # decrypt file name
        fname = os.fsdecode(file)
        # ignore file if it isn't a csv
        if not fname.endswith(".csv"):
            continue
        # ignore file if it has been processed before
        if fname in open(settings.logpath(histfile)).read():
            continue
        # make a prediction
        p = predict(model, '{0}/{1}'.format(input, fname))
        os.remove('{0}/{1}'.format(input, fname))
        # if prediction is 1 store it as accepted
        if p[0] == 1:
            with open(output, 'a') as out:
                out.write('{0}.jpg\n'.format(fname[:-4]))
            logger.info(
                'Star {0} predicted as: may be double, added to {1}'.format(
                    fname[:-4], output))
        else:
            logger.info('Star {0} predicted as: not double')
        hist.info(fname)
        # this check will allow stop events to break the execution sooner
        if stop_event.is_set():
            return 0
Esempio n. 2
0
def loop_list(input, dimages, dout, stop_event):
    '''
    Loop through every element in input list
    '''
    with open(input, 'r') as input:
        # recolor every jpg file listed
        for file in input:
            # take only the name without the '\n
            fname = file[:-1]
            # ignore file if it has been processed before
            if fname in open(settings.logpath(histfile)).read():
                continue
            # recolor the picture
            process(fname, dimages, dout)
            # remove the original picture
            #os.remove('{0}/{1}'.format(dimages, fname))
            # this check will allow stop events to break the execution sooner
            if stop_event.is_set():
                return 0
Esempio n. 3
0
def loop_step(input, data, stop_event):
    '''
  Crops every jpg file inside input, for each file creates a jpg file in output.
  '''
    # input directory check
    if not os.path.isdir(input):
        logger.critical('input directory, {0}, not found.'.format(input))
        return 0

    # encrypt input directory file
    encinput = os.fsencode(input)
    # loop through every element in input directory
    for e in os.listdir(encinput):
        # decrypt element name
        ename = os.fsdecode(e)
        # remove whitespaces to match wds
        ejoin = ''.join(ename.split())
        # ignore file if it has been processed before
        if ename in open(settings.logpath(histfile)).read():
            continue
        # ignore all folder
        if ename == 'all':
            continue
        # process the element if theres any data about it
        if ejoin in data:
            for line in data:
                dline = os.fsdecode(line)
                if ejoin in dline:
                    try:
                        process(ename, input, dline)
                        # register file in history log to prevent future processing
                        hist.info(ename)
                        break
                    except FileNotFoundError:
                        break
        else:
            # register file in history log to prevent future processing
            hist.info(ename)
        # this check will allow stop events to break the execution sooner
        if stop_event.is_set():
            return 0
Esempio n. 4
0
def loop_step(originals, input, output, stop_event):
    '''
    Parses every png file inside input, for each file accepted creates a folder
    insite output with the associated data.
    '''
    # input directory check
    if not os.path.isdir(input):
        if show:
            logger.critical('input directory, {0}, not found.'.format(input))
        return 0
    # output directory check
    if not os.path.isdir(output):
        logger.warning(
            'Output directory, {0}, not found. Creating...'.format(output))
        os.makedirs(output)
    # output all directory check
    if not os.path.isdir('{0}/all'.format(output)):
        os.makedirs('{0}/all'.format(output))
    # encrypt input directory
    encinput = os.fsencode(input)
    # loop through every element in input directory
    for file in os.listdir(encinput):
        # decrypt file name
        fname = os.fsdecode(file)
        # ignore file if it doesn't end in png
        if not fname.endswith(".png"):
            continue
        # ignore file if it has been processed before
        if fname in open(settings.logpath(histfile)).read():
            logger.info(
                '{0} found in step history file, file removed...'.format(
                    fname))
            os.remove('{0}/{1}'.format(input, fname))
            continue
        # parse the picture
        process(originals, fname, input, output)
        # this check will allow stop events to break the execution sooner
        if stop_event.is_set():
            return 0
Esempio n. 5
0
def loop_step(input, output, stop_event, only_center):
    '''
    Crops every jpg file inside input, for each file creates a jpg file in output.
    '''
    # input directory check
    if not os.path.isdir(input):
        logger.critical('input directory, {0}, not found.'.format(input))
        return 0
    # output directory check
    if not os.path.isdir(output):
        logger.warning(
            'Output directory, {0}, not found. Creating...'.format(output))
        os.makedirs(output)
    # temporal output directory check
    if not os.path.isdir('{0}_tmp'.format(output)):
        os.makedirs('{0}_tmp'.format(output))
    # encrypt input directory file
    encinput = os.fsencode(input)
    # loop through every element in input directory
    for file in os.listdir(encinput):
        # decrypt file name
        fname = os.fsdecode(file)
        # ignore file if it doesn't end in jpg
        if not fname.endswith(".jpg"):
            continue
        # ignore file if it has been processed before
        if fname in open(settings.logpath(histfile)).read():
            continue
        # delete the jpg file if the size is 0
        if os.stat('{0}/{1}'.format(input, fname)).st_size == 0:
            logger.debug('Deleted {0} because file size is 0'.format(fname))
            os.remove('{0}/{1}'.format(input, fname))
            continue
        # process the file
        process(fname, input, output, only_center)
        # this check will allow stop events to break the execution sooner
        if stop_event.is_set():
            return 0
Esempio n. 6
0
def loop_all(dimages, dout, stop_event):
    '''
    Loop through every element in dimages
    '''
    # encrypt input directory file
    encinput = os.fsencode(dimages)
    # loop through every element in input directory
    for file in os.listdir(encinput):
        # decrypt file name
        fname = os.fsdecode(file)
        # ignore file if it isnt a picture
        if not fname.endswith('.jpg'):
            continue
        # ignore file if it has been processed before
        if fname in open(settings.logpath(histfile)).read():
            continue
        # recolor the picture
        process(fname, dimages, dout)
        # remove the original picture
        #os.remove('{0}/{1}'.format(dimages, fname))
        # this check will allow stop events to break the execution sooner
        if stop_event.is_set():
            return 0