:param ekey: export key, i.e. a pair (datastore key, fmt)
    :param dstore: datastore object
175453
def export_avg_losses(ekey, dstore):
    
    dskey = ekey[0]
    oq = dstore['oqparam']
    dt = oq.loss_dt()
    name, value, tags = _get_data(dstore, dskey, oq.hazard_stats().items())
    writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
    assets = get_assets(dstore)
    for tag, values in zip(tags, value.transpose(1, 0, 2)):
        dest = dstore.build_fname(name, tag, 'csv')
        array = numpy.zeros(len(values), dt)
        for l, lt in enumerate(dt.names):
            array[lt] = values[:, l]
        writer.save(compose_arrays(assets, array), dest)
    return writer.getsaved()
682635
def insertDatastore(self, index, store):
    ''''''
    if not isinstance(store, Datastore):
      raise TypeError("stores must be of type %s" % Datastore)

    self._stores.insert(index, store)
957688
def init(self):
        
        if hasattr(self, 'data'):  # already initialized
            return
        if isinstance(self.dstore, str):
            self.dstore = hdf5.File(self.dstore, 'r')
        else:
            self.dstore.open('r')  # if not
        if self.sids is None:
            self.sids = self.dstore['sitecol'].sids
        oq = self.dstore['oqparam']
        self.imtls = oq.imtls
        self.poes = self.poes or oq.poes
        self.data = {}
        try:
            hcurves = self.get_hcurves(self.imtls)  # shape (R, N)
        except IndexError:  # no data
            return
        for sid, hcurve_by_rlz in zip(self.sids, hcurves.T):
            self.data[sid] = datadict = {}
            for rlzi, hcurve in enumerate(hcurve_by_rlz):
                datadict[rlzi] = lst = [None for imt in self.imtls]
                for imti, imt in enumerate(self.imtls):
                    lst[imti] = hcurve[imt]
224230
def _ReferenceFromPairs(pairs, reference=None, app=None, namespace=None):
  
  if reference is None:
    reference = entity_pb.Reference()
  path = reference.mutable_path()
  last = False
  for kind, idorname in pairs:
    if last:
      raise datastore_errors.BadArgumentError(
          'Incomplete Key entry must be last')
    t = type(kind)
    if t is str:
      pass
    elif t is unicode:
      kind = kind.encode('utf8')
    else:
      if issubclass(t, type):
        # Late import to avoid cycles.
        from .model import Model
        modelclass = kind
        if not issubclass(modelclass, Model):
          raise TypeError('Key kind must be either a string or subclass of '
                          'Model; received %r' % modelclass)
        kind = modelclass._get_kind()
        t = type(kind)
      if t is str:
        pass
      elif t is unicode:
        kind = kind.encode('utf8')
      elif issubclass(t, str):
        pass
      elif issubclass(t, unicode):
        kind = kind.encode('utf8')
      else:
        raise TypeError('Key kind must be either a string or subclass of Model;'
                        ' received %r' % kind)
    # pylint: disable=superfluous-parens
    if not (1 <= len(kind) <= _MAX_KEYPART_BYTES):
      raise ValueError('Key kind string must be a non-empty string up to %i'
                       'bytes; received %s' %
                       (_MAX_KEYPART_BYTES, kind))
    elem = path.add_element()
    elem.set_type(kind)
    t = type(idorname)
    if t is int or t is long:
      # pylint: disable=superfluous-parens
      if not (1 <= idorname < _MAX_LONG):
        raise ValueError('Key id number is too long; received %i' % idorname)
      elem.set_id(idorname)
    elif t is str:
      # pylint: disable=superfluous-parens
      if not (1 <= len(idorname) <= _MAX_KEYPART_BYTES):
        raise ValueError('Key name strings must be non-empty strings up to %i '
                         'bytes; received %s' %
                         (_MAX_KEYPART_BYTES, idorname))
      elem.set_name(idorname)
    elif t is unicode:
      idorname = idorname.encode('utf8')
      # pylint: disable=superfluous-parens
      if not (1 <= len(idorname) <= _MAX_KEYPART_BYTES):
        raise ValueError('Key name unicode strings must be non-empty strings up'
                         ' to %i bytes; received %s' %
                         (_MAX_KEYPART_BYTES, idorname))
      elem.set_name(idorname)
    elif idorname is None:
      last = True
    elif issubclass(t, (int, long)):
      # pylint: disable=superfluous-parens
      if not (1 <= idorname < _MAX_LONG):
        raise ValueError('Key id number is too long; received %i' % idorname)
      elem.set_id(idorname)
    elif issubclass(t, basestring):
      if issubclass(t, unicode):
        idorname = idorname.encode('utf8')
      # pylint: disable=superfluous-parens
      if not (1 <= len(idorname) <= _MAX_KEYPART_BYTES):
        raise ValueError('Key name strings must be non-empty strings up to %i '
                         'bytes; received %s' % (_MAX_KEYPART_BYTES, idorname))
      elem.set_name(idorname)
    else:
      raise TypeError('id must be either a numeric id or a string name; '
                      'received %r' % idorname)
  # An empty app id means to use the default app id.
  if not app:
    app = _DefaultAppId()
  # Always set the app id, since it is mandatory.
  reference.set_app(app)
  # An empty namespace overrides the default namespace.
  if namespace is None:
    namespace = _DefaultNamespace()
  # Only set the namespace if it is not empty.
  if namespace:
    reference.set_name_space(namespace)
  return reference
145327
def export_losses_by_event(ekey, dstore):
    
    oq = dstore['oqparam']
    writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
    dest = dstore.build_fname('losses_by_event', '', 'csv')
    if oq.calculation_mode.startswith('scenario'):
        dtlist = [('eid', U64)] + oq.loss_dt_list()
        arr = dstore['losses_by_event'].value[['eid', 'loss']]
        writer.save(arr.copy().view(dtlist), dest)
    elif oq.calculation_mode == 'ebrisk':
        tagcol = dstore['assetcol/tagcol']
        lbe = dstore['losses_by_event'].value
        lbe.sort(order='eid')
        dic = dict(tagnames=['event_id', 'loss_type'] + oq.aggregate_by)
        for tagname in oq.aggregate_by:
            dic[tagname] = getattr(tagcol, tagname)
        dic['event_id'] = ['?'] + list(lbe['eid'])
        dic['loss_type'] = ('?',) + oq.loss_dt().names
        aw = hdf5.ArrayWrapper(lbe['loss'], dic)  # shape (E, L, T...)
        writer.save(aw.to_table(), dest)
    else:
        dtlist = [('event_id', U64), ('rup_id', U32), ('year', U32)] + \
                 oq.loss_dt_list()
        eids = dstore['losses_by_event']['eid']
        year_of = year_dict(dstore['events']['eid'],
                            oq.investigation_time, oq.ses_seed)
        arr = numpy.zeros(len(dstore['losses_by_event']), dtlist)
        arr['event_id'] = eids
        arr['rup_id'] = arr['event_id'] / TWO32
        arr['year'] = [year_of[eid] for eid in eids]
        loss = dstore['losses_by_event']['loss'].T  # shape (L, E)
        for losses, loss_type in zip(loss, oq.loss_dt().names):
            arr[loss_type] = losses
        writer.save(arr, dest)
    return writer.getsaved()
584096
def extract_asset_values(dstore, sid):
    
    if sid:
        return extract(dstore, 'asset_values')[int(sid)]
    assetcol = extract(dstore, 'assetcol')
    asset_refs = assetcol.asset_refs
    assets_by_site = assetcol.assets_by_site()
    lts = assetcol.loss_types
    dt = numpy.dtype([('aref', asset_refs.dtype), ('aid', numpy.uint32)] +
                     [(str(lt), numpy.float32) for lt in lts])
    data = []
    for assets in assets_by_site:
        vals = numpy.zeros(len(assets), dt)
        for a, asset in enumerate(assets):
            vals[a]['aref'] = asset_refs[a]
            vals[a]['aid'] = asset['ordinal']
            for lt in lts:
                vals[a][lt] = asset['value-' + lt]
        data.append(vals)
    return data
1359134
def ebr_data_transfer(token, dstore):
    
    attrs = dstore['losses_by_event'].attrs
    sent = humansize(attrs['sent'])
    received = humansize(attrs['tot_received'])
    return 'Event Based Risk: sent %s, received %s' % (sent, received)
954265
function ekskey(data, key, engine, heap32) {
        var i, off, sw;
        var L_offset = LR_offset >> 2,
            R_offset = L_offset + 1;

        heap32[L_offset] = 0;
        heap32[R_offset] = 0;
        
        off = 0;
        for (i = 0; i < P_LEN; i++) {
            sw = key[off++] << 24 | key[off++] << 16 | key[off++] << 8 | key[off++];
            heap32[P_offset >> 2 | i] ^= sw;
        }
        
        off = 0;
        for (i = 0; i < P_LEN; i += 2) {
            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;   // &0xff0f === %BCRYPT_SALT_LEN
            heap32[L_offset] ^= sw;

            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;
            heap32[R_offset] ^= sw;

            engine.encrypt(LR_offset);
            heap32[P_offset >> 2 | i] = heap32[L_offset];
            heap32[P_offset >> 2 | (i + 1)] = heap32[R_offset];
        }
        
        var s_offset = S_offset >> 2;
        for (i = 0; i < S_LEN; i += 2) {
            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;   // &0xff0f === %BCRYPT_SALT_LEN
            heap32[L_offset] ^= sw;

            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;
            heap32[R_offset] ^= sw;

            engine.encrypt(LR_offset);
            heap32[s_offset | i] = heap32[L_offset];
            heap32[s_offset | (i + 1)] = heap32[R_offset];
        }
    }
396006
def sdiffstore(self, dest, *keys):
        
        keys = [self.redis_key(k) for k in self._parse_values(keys)]

        with self.pipe as pipe:
            return pipe.sdiffstore(self.redis_key(dest), *keys)
914
function sinterstore(destination /* key-1, key-N, req*/) {
  var args = slice.call(arguments, 1)
    , req = typeof args[args.length - 1] === 'object'
      ? args[args.length - 1] : null;
  var list = this.sinter.apply(this, args);
  if(list.length) {
    this.setKey(
      destination, new Set(list), undefined, undefined, undefined, req);
  }
  return list.length;
}
996734
def extract_assets(dstore, what):
    
    qdict = parse(what)
    dic = {}
    dic1, dic2 = dstore['assetcol/tagcol'].__toh5__()
    dic.update(dic1)
    dic.update(dic2)
    arr = dstore['assetcol/array'].value
    for tag, vals in qdict.items():
        cond = numpy.zeros(len(arr), bool)
        for val in vals:
            tagidx, = numpy.where(dic[tag] == val)
            cond |= arr[tag] == tagidx
        arr = arr[cond]
    return ArrayWrapper(arr, dic)
1231774
def sdiffstore(self, destkey, key, *keys):
        """"""
        return self.execute(b'SDIFFSTORE', destkey, key, *keys)
638564
def _key(key=''):
    '''
    
    '''
    if not isinstance(key, datastore.Key):
        # Switchboard uses ':' to denote one thing (parent-child) and datastore
        # uses it for another, so replace ':' in the datastore version of the
        # key.
        safe_key = key.replace(':', '|')
        key = datastore.Key(os.path.join(NAMESPACE, safe_key))
    return key
835729
function sdiffstore(destination /* key-1, key-N, req*/) {
  var args = slice.call(arguments, 1)
    , req = typeof args[args.length - 1] === 'object'
      ? args[args.length - 1] : null;
  var list = this.sdiff.apply(this, args);
  if(list.length) {
    this.setKey(
      destination, new Set(list), undefined, undefined, undefined, req);
  }
  return list.length;
}
856709
@SneakyThrows
    public KeyStore createEmptyKeystore() {
        KeyStore keyStore = KeyStore.getInstance("JKS");
        keyStore.load(null, "".toCharArray());
        return keyStore;
    }
615963
def get(self, key):
    '''
    '''

    ''''''
    value = self.child_datastore.get(key)
    return self.deserializedValue(value)
1321921
function store(options) {
  options = options || {};
  var DataStore = lazy.DataStore();
  var opts = extend(options.store || {});
  return new DataStore('snippets', opts);
}