docs: def export_agg_losses(ekey, dstore):
      """
      :param ekey: export key, i.e. a pair (datastore key, fmt)
      :param dstore: datastore object
      """
      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)
      expvalue = dstore['exposed_value'].value  # shape (T1, T2, ..., L)
      tagcol = dstore['assetcol/tagcol']
      tagnames = tuple(dstore['oqparam'].aggregate_by)
      header = ('loss_type',) + tagnames + (
          'loss_value', 'exposed_value', 'loss_ratio')
      for r, tag in enumerate(tags):
          rows = []
          for multi_idx, loss in numpy.ndenumerate(value[:, r]):
              l, *tagidxs = multi_idx
              evalue = expvalue[tuple(tagidxs) + (l,)]
              row = tagcol.get_tagvalues(tagnames, tagidxs) + (
                  loss, evalue, loss / evalue)
              rows.append((dt.names[l],) + row)
          dest = dstore.build_fname(name, tag, 'csv')
          writer.save(rows, dest, header)
      return writer.getsaved()