Ejemplo n.º 1
0
def action_searches_result(label):
    '''
    try to retrieve the searches result with the label used as argument
    returns 
        - (False, Null) if it there is no directory or the search 
          pickle file cannot be found 
        
        - (True, JSON) with the results otherwyse
    '''
    opath = tempfile.gettempdir()
    if not os.path.isdir(opath):
        return False, f'directory {opath} not found'

    # default in case label was not provided
    if label is None:
        label = 'temp'

    iconveyor = Conveyor()

    search_pkl_path = os.path.join(opath, 'similars-' + label + '.pkl')
    if not os.path.isfile(search_pkl_path):
        return False, f'file {search_pkl_path} not found'

    with open(search_pkl_path, 'rb') as handle:
        success, message = iconveyor.load(handle)

    if not success:
        print(f'error reading prediction results with message {message}')
        return False, None

    if not iconveyor.isKey('search_results'):
        return False, 'search results not found'

    results = iconveyor.getVal('search_results')
    names = iconveyor.getVal('obj_nam')
    if iconveyor.isKey('SMILES'):
        smiles = iconveyor.getVal('SMILES')
    if len(results) != len(names):
        return False, 'results length does not match names'

    for i in range(len(results)):
        if iconveyor.isKey('SMILES'):
            print(f'similars to {names[i]} [{smiles[i]}]')
        else:
            print(f'similars to {names[i]}')

        iresult = results[i]
        for j in range(len(iresult['distances'])):
            dist = iresult['distances'][j]
            name = iresult['names'][j]
            smil = iresult['SMILES'][j]
            print(f'   {dist:.3f} : {name} [{smil}]')

    # return a JSON generated by iconveyor
    return True, iconveyor.getJSON()
Ejemplo n.º 2
0
def action_predictions_result (label):
    '''
    try to retrieve the prediction result with the label used as argument
    returns 
        - (False, Null) if it there is no directory or the predictions 
          pickle files cannot be found 
        
        - (True, JSON) with the results otherwyse
    '''
    # get de model repo path
    predictions_path = pathlib.Path(utils.predictions_repository_path())

    label_path = predictions_path.joinpath(label)

    if not label_path.is_dir():
        print (f'directory {label_path} not found')
        return False, None

    result_path = label_path.joinpath('prediction-results.pkl')
    if not result_path.is_file():
        print (f'predictions not found for {label} directory')
        return False, None

    iconveyor = Conveyor()

    with open(result_path, 'rb') as handle:
        success, message = iconveyor.load(handle)

    if not success:
        print (f'error reading prediction results with message {message}')
        return False, None

    # console output    
    print_prediction_result(('obj_num','number of objects',iconveyor.getVal('obj_num')))

    if iconveyor.isKey('external-validation'):
        for val in iconveyor.getVal('external-validation'):
            print_prediction_result (val)   

    if iconveyor.isKey('values'):
        for i in range (iconveyor.getVal('obj_num')):
            print (iconveyor.getVal('obj_nam')[i], '\t', float("{0:.4f}".format(iconveyor.getVal('values')[i])))

    # return a JSON generated by iconveyor
    input_type = iconveyor.getMeta('input_type')
    
    return True, iconveyor.getJSON(xdata=(input_type == 'model_ensemble'))
Ejemplo n.º 3
0
def action_results(model, version=None, ouput_variables=False):
    ''' Returns a JSON with whole results info for a given model and version '''

    if model is None:
        return False, 'Empty model label'

    rdir = utils.model_path(model, version)
    if not os.path.isfile(os.path.join(rdir, 'results.pkl')):
        return False, 'results not found'

    from flame.conveyor import Conveyor

    conveyor = Conveyor()
    with open(os.path.join(rdir, 'results.pkl'), 'rb') as handle:
        conveyor.load(handle)

    return True, conveyor.getJSON()