本文整理汇总了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)
};
}
示例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`);
}
}
示例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();
},
});
}
示例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 }
}
});
}
示例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) => {
示例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;
}
示例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;
}
});
示例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];
});
}
示例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};
});
示例10: copy
consolidateHashes.map((hash) => {
const ret = copy(
D1StoresService.getItemAcrossStores({
hash
})
);
if (ret) {
ret.amount = _.sumBy(D1StoresService.getStores(), (s) => s.amountOfItem(ret));
}
return ret;
})
示例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;
}
示例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);
});
示例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;
});
});
示例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
}
}
示例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;
}