Example #1
0
def load_query_results(hs, qcx_list, force_load=False):
    query_cfg = hs.prefs.query_cfg
    # Build query big cache uid
    query_uid = query_cfg.get_uid()
    hs_uid    = hs.get_db_name()
    qcxs_uid  = helpers.hashstr(tuple(qcx_list))
    qres_uid  = hs_uid + query_uid + qcxs_uid
    cache_dir = join(hs.dirs.cache_dir, 'query_results_bigcache')
    print('\n===============')
    print('\n[rr2] Load Query Results')
    print('[rr2] load_query_results(): %r' % qres_uid)
    io_kwargs = dict(dpath=cache_dir, fname='query_results', uid=qres_uid, ext='.cPkl')
    # Return cache if available
    if not hs.args.nocache_query and (not force_load):
        qcx2_res = io.smart_load(**io_kwargs)
        if qcx2_res is not None:
            print('[rr2] load_query_results(): cache hit')
            return qcx2_res
        print('[rr2] load_query_results(): cache miss')
    else:
        print('[rr2] load_query_results(): cache off')
    # Individually load / compute queries
    qcx2_res = [hs.query(qcx) for qcx in qcx_list]
    # Save to the cache
    print('[rr2] Saving query_results to bigcache: %r' % qres_uid)
    helpers.ensuredir(cache_dir)
    io.smart_save(qcx2_res, **io_kwargs)
    return qcx2_res
Example #2
0
def _user_option(parent, msg, title='options', options=['No', 'Yes'], use_cache=False):
    'Prompts user with several options with ability to save decision'
    print('[*guitools] _user_option:\n %r: %s' + title + ': ' + msg)
    # Recall decision
    print('[*guitools] asking user: %r %r' % (msg, title))
    cache_id = helpers.hashstr(title + msg)
    if use_cache:
        reply = io.global_cache_read(cache_id, default=None)
        if reply is not None:
            return reply
    # Create message box
    msgBox = _newMsgBox(msg, title, parent)
    _addOptions(msgBox, options)
    if use_cache:
        dontPrompt = _cacheReply(msgBox)
    # Wait for output
    optx = msgBox.exec_()
    if optx == QtGui.QMessageBox.Cancel:
        return None
    try:
        reply = options[optx]
    except Exception as ex:
        print('[*guitools] USER OPTION EXCEPTION !')
        print('[*guitools] optx = %r' % optx)
        print('[*guitools] options = %r' % options)
        print('[*guitools] ex = %r' % ex)
        raise
    # Remember decision
    if use_cache and dontPrompt.isChecked():
        io.global_cache_write(cache_id, reply)
    del msgBox
    return reply
Example #3
0
def load_query_results(hs, qcx_list, force_load=False):
    query_cfg = hs.prefs.query_cfg
    # Build query big cache uid
    query_uid = query_cfg.get_uid()
    hs_uid = hs.get_db_name()
    qcxs_uid = helpers.hashstr(tuple(qcx_list))
    qres_uid = hs_uid + query_uid + qcxs_uid
    cache_dir = join(hs.dirs.cache_dir, 'query_results_bigcache')
    print('\n===============')
    print('\n[rr2] Load Query Results')
    print('[rr2] load_query_results(): %r' % qres_uid)
    io_kwargs = dict(dpath=cache_dir,
                     fname='query_results',
                     uid=qres_uid,
                     ext='.cPkl')
    # Return cache if available
    if not hs.args.nocache_query and (not force_load):
        qcx2_res = io.smart_load(**io_kwargs)
        if qcx2_res is not None:
            print('[rr2] load_query_results(): cache hit')
            return qcx2_res
        print('[rr2] load_query_results(): cache miss')
    else:
        print('[rr2] load_query_results(): cache off')
    # Individually load / compute queries
    qcx2_res = [hs.query(qcx) for qcx in qcx_list]
    # Save to the cache
    print('[rr2] Saving query_results to bigcache: %r' % qres_uid)
    helpers.ensuredir(cache_dir)
    io.smart_save(qcx2_res, **io_kwargs)
    return qcx2_res
Example #4
0
def query_result_fpath(hs, qcx, query_uid):
    qres_dir = hs.dirs.qres_dir
    qcid = hs.tables.cx2_cid[qcx]
    fname = 'res_%s_qcid=%d.npz' % (query_uid, qcid)
    if len(fname) > 64:
        hash_id = helpers.hashstr(query_uid, 16)
        fname = 'res_%s_qcid=%d.npz' % (hash_id, qcid)
    fpath = join(qres_dir, fname)
    return fpath
Example #5
0
def query_result_fpath(hs, qcx, query_uid):
    qres_dir  = hs.dirs.qres_dir
    qcid  = hs.tables.cx2_cid[qcx]
    fname = 'res_%s_qcid=%d.npz' % (query_uid, qcid)
    if len(fname) > 64:
        hash_id = helpers.hashstr(query_uid, 16)
        fname = 'res_%s_qcid=%d.npz' % (hash_id, qcid)
    fpath = join(qres_dir, fname)
    return fpath