• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.sumBy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: findReversedAndShiftedInternalIndices

 /**
  * Same as above, except this method first takes reversals and shift offsets
  * into account.
  */
 private findReversedAndShiftedInternalIndices(subIdx: number, cmdIdx: number) {
   const sps = this.findSubPathStateLeaf(subIdx);
   const css = sps.getCommandStates();
   const numCommandsInSubPath = _.sumBy(css, cs => cs.getCommands().length);
   if (cmdIdx && sps.isReversed()) {
     cmdIdx = numCommandsInSubPath - cmdIdx;
   }
   cmdIdx += sps.getShiftOffset();
   if (cmdIdx >= numCommandsInSubPath) {
     // Note that subtracting (numCommandsInSubPath - 1) is intentional here
     // (as opposed to subtracting numCommandsInSubPath).
     cmdIdx -= numCommandsInSubPath - 1;
   }
   return this.findInternalIndices(css, cmdIdx);
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:19,代码来源:Path.ts


示例17: alterationInfoForOncoprintTrackData

export function alterationInfoForOncoprintTrackData(
    sampleMode: boolean,
    data: {
        trackData: GeneticTrackDatum[],
        oql: {gene: string} | string[]
    },
    sequencedSampleKeysByGene: {[hugoGeneSymbol:string]:string[]},
    sequencedPatientKeysByGene: {[hugoGeneSymbol:string]:string[]}
) {
    const sequenced = getAlterationInfoSequenced(sampleMode, data.oql, sequencedSampleKeysByGene, sequencedPatientKeysByGene);
    const altered = _.sumBy(data.trackData!, d=>(+isAltered(d)));
    const percent = percentAltered(altered, sequenced);
    return {
        sequenced, altered, percent
    };
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:16,代码来源:OncoprintUtils.ts


示例18: cumulativeMapFacetValues

export function cumulativeMapFacetValues(values: Array<{ val: string; count: number }>) {
  const noDataVal = values.find(value => value.val === 'NO_DATA');
  const filteredValues = noDataVal ? values.filter(value => value.val !== 'NO_DATA') : values;

  let sum = sumBy(filteredValues, value => value.count);
  const map: { [value: string]: number } = {};
  filteredValues.forEach((value, index) => {
    map[value.val] = index > 0 && index < values.length - 1 ? sum : value.count;
    sum -= value.count;
  });

  if (noDataVal) {
    map[noDataVal.val] = noDataVal.count;
  }
  return map;
}
开发者ID:christophelevis,项目名称:sonarqube,代码行数:16,代码来源:utils.ts


示例19: shiftCommandStates

/**
 * Returns a list of shifted command state objects.
 */
function shiftCommandStates(css: CommandState[], isReversed: boolean, shiftOffset: number) {
  if (!shiftOffset || css.length === 1) {
    return css;
  }

  const numCommands = _.sumBy(css, cs => cs.getCommands().length);
  if (isReversed) {
    shiftOffset *= -1;
    shiftOffset += numCommands - 1;
  }
  const newCss: CommandState[] = [];

  let counter = 0;
  let targetCsIdx: number;
  let targetSplitIdx: number;
  let targetCs: CommandState;
  for (let i = 0; i < css.length; i++) {
    const cs = css[i];
    const size = cs.getCommands().length;
    if (counter + size <= shiftOffset) {
      counter += size;
      continue;
    }
    targetCs = cs;
    targetCsIdx = i;
    targetSplitIdx = shiftOffset - counter;
    break;
  }

  newCss.push(
    new CommandState(
      new Command('M', [css[0].getCommands()[0].start, targetCs.getCommands()[targetSplitIdx].end]),
    ),
  );
  const { left, right } = targetCs.slice(targetSplitIdx);
  if (right) {
    newCss.push(right);
  }
  for (let i = targetCsIdx + 1; i < css.length; i++) {
    newCss.push(css[i]);
  }
  for (let i = 1; i < targetCsIdx; i++) {
    newCss.push(css[i]);
  }
  newCss.push(left);
  return newCss;
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:50,代码来源:Path.ts


示例20: deleteDashboard

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

    if (this.dashboard.meta.provisioned) {
      appEvents.emit('confirm-modal', {
        title: 'Cannot delete provisioned dashboard',
        text: `
          This dashboard is managed by Grafanas provisioning and cannot be deleted. Remove the dashboard from the
          config file to delete it.
        `,
        text2: `
          <i>See <a class="external-link" href="http://docs.grafana.org/administration/provisioning/#dashboards" target="_blank">
          documentation</a> for more information about provisioning.</i>
          </br>
          File path: ${this.dashboard.meta.provisionedExternalId}
        `,
        text2htmlBind: true,
        icon: 'fa-trash',
        noText: 'OK',
      });
      return;
    }

    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:grafana,项目名称:grafana,代码行数:46,代码来源:SettingsCtrl.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.tail函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.sum函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap