Beispiel #1
0
def extract(what, calc_id=-1, webapi=False, local=False, extract_dir='.'):
    """
    Extract an output from the datastore and save it into an .hdf5 file.
    By default uses the WebAPI, otherwise the extraction is done locally.
    """
    with performance.Monitor('extract', measuremem=True) as mon:
        if local:
            if calc_id == -1:
                calc_id = logs.dbcmd('get_job', calc_id).id
            aw = WebExtractor(calc_id, 'http://localhost:8800', '').get(what)
        elif webapi:
            aw = WebExtractor(calc_id).get(what)
        else:
            aw = Extractor(calc_id).get(what)
        w = what.replace('/', '-').replace('?', '-')
        if isinstance(aw.array, str):  # a big string
            fname = os.path.join(extract_dir, '%s_%d.csv' % (w, calc_id))
            with open(fname, 'w', encoding='utf-8') as f:
                f.write(aw.array)
        elif aw.is_good():  # a regular ArrayWrapper
            fname = os.path.join(extract_dir, '%s_%d.npz' % (w, calc_id))
            hdf5.save_npz(aw, fname)
        else:  # ArrayWrapper of strings, dictionaries or other types
            fname = os.path.join(extract_dir, '%s_%d.txt' % (w, calc_id))
            open(fname, 'w').write(aw.toml())
        print('Saved', fname)
    if mon.duration > 1:
        print(mon)
Beispiel #2
0
def extract(what, calc_id=-1, webapi=True, local=False):
    """
    Extract an output from the datastore and save it into an .hdf5 file.
    By default uses the WebAPI, otherwise the extraction is done locally.
    """
    with performance.Monitor('extract', measuremem=True) as mon:
        if local:
            obj = WebExtractor(calc_id, 'http://localhost:8800', '').get(what)
        elif webapi:
            obj = WebExtractor(calc_id).get(what)
        else:
            obj = Extractor(calc_id).get(what)
        w = what.replace('/', '-').replace('?', '-')
        if not obj.shape:  # is a dictionary of arrays
            fname = '%s_%d.txt' % (w, calc_id)
            open(fname, 'w').write(obj.toml())
        else:  # a regular ArrayWrapper
            fname = '%s_%d.hdf5' % (w, calc_id)
            obj.save(fname)
        print('Saved', fname)
    if mon.duration > 1:
        print(mon)