当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.sumBy函数代码示例

本文整理汇总了TypeScript中lodash.sumBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sumBy函数的具体用法?TypeScript sumBy怎么用?TypeScript sumBy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sumBy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: dataStats

export function dataStats(data) {
  const taggedItemsD1 = _.sumBy(
    Object.keys(data)
      .filter((k) => k.startsWith('dimItemInfo') && k.endsWith('-d1'))
      .map((k) => _.size(data[k])),
    (v) => v
  );
  const taggedItemsD2 = _.sumBy(
    Object.keys(data)
      .filter((k) => k.startsWith('dimItemInfo') && k.endsWith('-d2'))
      .map((k) => _.size(data[k])),
    (v) => v
  );

  const loadoutsD1 = count(
    data['loadouts-v3.0'] || [],
    (loadoutId: string) => data[loadoutId] && data[loadoutId].destinyVersion !== 2
  );
  const loadoutsD2 = count(
    data['loadouts-v3.0'] || [],
    (loadoutId: string) => data[loadoutId] && data[loadoutId].destinyVersion === 2
  );

  return {
    LoadoutsD1: loadoutsD1,
    LoadoutsD2: loadoutsD2,
    TagNotesD1: taggedItemsD1,
    TagNotesD2: taggedItemsD2,
    Settings: _.size(data['settings-v1.0']),
    IgnoredUsers: _.size(data.ignoredUsers)
  };
}
开发者ID:w1cked,项目名称:DIM,代码行数:32,代码来源:data-stats.ts

示例2: main

async function main() {
  const config = getConfigRoot();
  const bfConfig = findBrokerConfig(config, 'Bitflyer');
  const ccConfig = findBrokerConfig(config, 'Coincheck');
  const quConfig = findBrokerConfig(config, 'Quoine');

  const bfApi = new BitflyerApi(bfConfig.key, bfConfig.secret);
  const ccApi = new CoincheckApi(ccConfig.key, ccConfig.secret);
  const quApi = new QuoineApi(quConfig.key, quConfig.secret);

  // csv header
  process.stdout.write('Exchange, Currency, Type, Amount\n');

  // bitflyer cash balance
  if (bfConfig.enabled) {
    const bfBalance = await bfApi.getBalance();
    const bfJpy = (bfBalance.find(x => x.currency_code === 'JPY') as Balance).available;
    const bfBtc = (bfBalance.find(x => x.currency_code === 'BTC') as Balance).available;
    process.stdout.write(`bitFlyer, JPY, Cash, ${_.round(bfJpy)}\n`);
    process.stdout.write(`bitFlyer, BTC, Cash, ${bfBtc}\n`);
  }

  // coincheck cash balance
  if (ccConfig.enabled) {
    const ccBalance = await ccApi.getAccountsBalance();
    process.stdout.write(`Coincheck, JPY, Cash, ${_.round(ccBalance.jpy)}\n`);
    process.stdout.write(`Coincheck, BTC, Cash, ${ccBalance.btc}\n`);

    // coincheck margin balance
    const ccLeverageBalance = await ccApi.getLeverageBalance();
    process.stdout.write(`Coincheck, JPY, Margin, ${_.round(ccLeverageBalance.margin.jpy)}\n`);
    process.stdout.write(`Coincheck, JPY, Free Margin, ${_.round(ccLeverageBalance.margin_available.jpy)}\n`);
    const positions = await ccApi.getAllOpenLeveragePositions();
    const longPosition = _.sumBy(positions.filter(p => p.side === 'buy'), p => p.amount);
    const shortPosition = _.sumBy(positions.filter(p => p.side === 'sell'), p => p.amount);
    process.stdout.write(`Coincheck, BTC, Leverage Position, ${longPosition - shortPosition}\n`);
  }

  if (quConfig.enabled) {
    // quoine cash balance
    const quCashBalance = await quApi.getAccountBalance();
    const quJpyCash = quCashBalance.find(b => b.currency === 'JPY') as AccountBalance;
    const quBtcCash = quCashBalance.find(b => b.currency === 'BTC') as AccountBalance;
    process.stdout.write(`Quoine, JPY, Cash, ${_.round(quJpyCash.balance)}\n`);
    process.stdout.write(`Quoine, BTC, Cash, ${quBtcCash.balance}\n`);

    // quoine margin balance
    const quBalance = await quApi.getTradingAccounts();
    const quBtcJpyBalance = quBalance.find(x => x.currency_pair_code === 'BTCJPY') as TradingAccount;
    process.stdout.write(`Quoine, JPY, Margin, ${_.round(quBtcJpyBalance.balance)}\n`);
    process.stdout.write(`Quoine, JPY, Free Margin, ${_.round(quBtcJpyBalance.free_margin)}\n`);
    process.stdout.write(`Quoine, BTC, Leverage Position, ${quBtcJpyBalance.position}\n`);
  }
}
开发者ID:tangkaisky,项目名称:r2,代码行数:54,代码来源:getBalance.ts

示例3: deleteDashboard

  deleteDashboard() {
    var confirmText = '';
    var text2 = this.dashboard.title;

    const alerts = _.sumBy(this.dashboard.panels, panel => {
      return panel.alert ? 1 : 0;
    });

    if (alerts > 0) {
      confirmText = 'DELETE';
      text2 = `This dashboard contains ${alerts} alerts. Deleting this dashboard will also delete those alerts`;
    }

    appEvents.emit('confirm-modal', {
      title: 'Delete',
      text: 'Do you want to delete this dashboard?',
      text2: text2,
      icon: 'fa-trash',
      confirmText: confirmText,
      yesText: 'Delete',
      onConfirm: () => {
        this.dashboard.meta.canSave = false;
        this.deleteDashboardConfirmed();
      },
    });
  }
开发者ID:arcolife,项目名称:grafana,代码行数:26,代码来源:settings.ts

示例4: emptyCartForUser

export async function emptyCartForUser(userId, db: Prisma): Promise<{}> {
  const { cart } = await db.query.user(
    { where: { id: userId } },
    `{
      cart {
        id
        quantity
        variant {
          id
          price
        }
      }
    }`
  );

  if (cart.length === 0) {
    return null;
  }

  const lineItemsIds = cart.map(lineItem => ({ id: lineItem.id }));
  const totalPrice = _.sumBy(
    cart,
    lineItem => lineItem.quantity * lineItem.variant.price
  );

  await db.mutation.updateUser({
    where: { id: userId },
    data: {
      cart: { disconnect: lineItemsIds }
    }
  });
}
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:32,代码来源:order.ts

示例5:

    this.walletProvider.getLowUtxos(this.wallet).then((resp) => {

      if (resp && resp.allUtxos && resp.allUtxos.length) {

        let allSum = _.sumBy(resp.allUtxos || 0, 'satoshis');
        let per = (resp.minFee / allSum) * 100;

        this.lowUtxosNb = resp.lowUtxos.length;
        this.allUtxosNb = resp.allUtxos.length;
        this.lowUtxosSum = this.txFormatProvider.formatAmountStr(this.wallet.coin, _.sumBy(resp.lowUtxos || 0, 'satoshis'));
        this.allUtxosSum = this.txFormatProvider.formatAmountStr(this.wallet.coin, allSum);
        this.minFee = this.txFormatProvider.formatAmountStr(this.wallet.coin, resp.minFee || 0);
        this.minFeePer = per.toFixed(2) + '%';

      }
    }).catch((err) => {
开发者ID:bitjson,项目名称:copay,代码行数:16,代码来源:wallet-addresses.ts

示例6: canReturn

  canReturn() {
    const itemCount = _.sumBy(this.invoice.stockitems, 'quantity');
    const returnedItemCount = _.reduce(this.invoice.invoices, (prev, cur) => {
      return prev + _.sumBy(cur.stockitems, 'quantity');
    }, 0);

    return itemCount !== returnedItemCount;
  }
开发者ID:Linko91,项目名称:posys,代码行数:8,代码来源:invoice.view.ts

示例7: copy

 return _.flatMap(Object.values(_.groupBy(items, (t) => t.hash)), (items) => {
   if (items[0].maxStackSize > 1) {
     const item = copy(items[0]);
     item.amount = _.sumBy(items, (i) => i.amount);
     return [item];
   } else {
     return items;
   }
 });
开发者ID:w1cked,项目名称:DIM,代码行数:9,代码来源:auto-loadouts.ts

示例8: BytesUsed

export function BytesUsed(s: INodeStatus): number {
  const usedCapacity = s.metrics[MetricConstants.usedCapacity];
  if (usedCapacity !== 0) {
    return usedCapacity;
  }
  return _.sumBy(aggregateByteKeys, (key: string) => {
    return s.metrics[key];
  });
}
开发者ID:a6802739,项目名称:cockroach,代码行数:9,代码来源:proto.ts

示例9:

    const res = _.map(grouped, (events, key) => {

      const sum = _.sumBy(events, (event) => event.elapsed);

      const hours = this.formatNumber(sum / 1000 / 3600);

      const count = events.length;

      return {key, hours, count, events};

    });
开发者ID:akkunchoi,项目名称:kilogk,代码行数:11,代码来源:EventAnalyzer.ts

示例10: copy

 consolidateHashes.map((hash) => {
   const ret = copy(
     D1StoresService.getItemAcrossStores({
       hash
     })
   );
   if (ret) {
     ret.amount = _.sumBy(D1StoresService.getStores(), (s) => s.amountOfItem(ret));
   }
   return ret;
 })
开发者ID:w1cked,项目名称:DIM,代码行数:11,代码来源:farming.service.ts

示例11: computeSandwichPrice

    public static computeSandwichPrice(sandwich: SandwichModel, size = 1) {
        if (!sandwich.toppings || sandwich.toppings.length < 0 || !sandwich.bread) {
            return null;
        }

        // use formula sizedSandwichPrice = sandwichFullPrice * (2 + size)/5
        let totalPrice = _.sumBy(sandwich.toppings, t => t.price);
        totalPrice += sandwich.bread.price;

        return totalPrice * (2 + (+size)) / 5;
    }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:11,代码来源:sandwich.util.ts

示例12:

 virtualStudies.forEach(virtualStudy=>{
     // tslint:disable-next-line:no-object-literal-type-assertion
     const cancerStudy = {
         allSampleCount: _.sumBy(virtualStudy.data.studies, study=>study.samples.length),
         studyId: virtualStudy.id,
         name: virtualStudy.data.name,
         description: virtualStudy.data.description,
         cancerTypeId: "My Virtual Studies"
     } as CancerStudy;
     queriedStudies.push(cancerStudy);
 });
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:11,代码来源:ResultsViewPageStoreUtils.ts

示例13:

 sortedSets = _.sortBy(sortedSets, (set) => {
   return -_.sumBy(set.armor, (item) => {
     if (!item || !item.sockets) {
       return 0;
     }
     return item.sockets.sockets.filter((slot) =>
       slot.plugOptions.some((perk) =>
         lockedPerks.find((lockedPerk) => lockedPerk.item.hash === perk.plugItem.hash)
       )
     ).length;
   });
 });
开发者ID:w1cked,项目名称:DIM,代码行数:12,代码来源:utils.ts

示例14: percentile

function percentile(data: [number, number][]) {
  data = _.sortBy(data, 0)
  var total = _.sumBy(data, '1')
  return (percentileNo: number) => {
    var current = 0
    for (var i = 0; i < data.length; i++) {
      current += data[i][1]
      if (current / total >= percentileNo / 100) return data[i][0]
    }
    return 0
  }
}
开发者ID:bemusic,项目名称:bemuse,代码行数:12,代码来源:bpm-info.ts

示例15: createOrderFromCart

export async function createOrderFromCart(args: CreateOrderInput, db: Prisma): Promise<Order> {
  const { selectedShop: { id: shopId }, cart } = await db.query.user(
    { where: { id: args.userId } },
    `{
      selectedShop { id }
      cart {
        id
        quantity
        variant {
          id
          price
        }
      }
    }`
  );

  if (cart.length === 0) {
    return null;
  }

  const lineItemsIds = cart.map(lineItem => ({ id: lineItem.id }));
  const totalPrice = _.sumBy(
    cart,
    lineItem => lineItem.quantity * lineItem.variant.price
  );

  if (args.emptyCart) {
    await db.mutation.updateUser({
      where: { id: args.userId },
      data: {
        cart: { disconnect: lineItemsIds }
      }
    });
  }

  const newOrder = await db.mutation.createOrder({
    data: {
      owner: { connect: { id: args.userId } },
      receiver: { connect: { id: shopId } },
      lineItems: { connect: lineItemsIds },
      totalPrice,
      totalTax: 0,
      totalRefunded: 0,
      orderStatus: args.orderStatus
    }
  });

  return newOrder;
}
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:49,代码来源:order.ts


注:本文中的lodash.sumBy函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。