export function htmlPrintPpCmdsDiff(l : PpCmds, old : PpCmds) : string { _(patterns).each(pattern => { l = pattern(l) old = pattern(old) }) if (!ppCmdsSameShape(l, old)) { return markDifferent( _.reduce( l, (acc : string, p : PpCmdType) => { return acc + htmlPrintPpCmd(p) }, '' ) ) } const z = _.zip(l, old) return _.reduce( z, (acc : string, [p, oldP] : [PpCmdType, PpCmdType]) => { return acc + htmlPrintPpCmdDiff(p, oldP) }, '' ) }
export function addHiddenChildTotals(values) { let childValues = values; // Add the Totals Together let childEntryTotalAgg = reduce(filter(childValues, (z: any) => { return z.TYPE === 'Total'; }) , (sum = 0, z: any) => { return sum + Number(z.AMOUNT); }, 0); // Get the Sub Category child entires values = filter(childValues, (z: any) => { return z.TYPE !== 'Total'; }); if (values.length == 0) { // No Deducated Entries values = childValues; } else { // Get the SubCategory child entry Values that aren't totals let subValueTotals = reduce(filter(childValues, (z: any) => { return z.TYPE != 'Total'; }) , (sum = 0, z: any) => { return sum + Number(z.AMOUNT); }, 0); // If The Subcategory Entry Values dont add up to the Subcategory Total Value // Insert a hidden arc on the circle if (subValueTotals !== childEntryTotalAgg) { values.push({ AMOUNT: childEntryTotalAgg - subValueTotals, CATEGORY: "Flexible Earmark", FUNDING_CATEGORY: "Emergency Reserve", TYPE: 'Hidden' }) } } return values; }
return _.map(outcomeTradeRowsByPeriod, (trades: Array<MarketPriceHistoryRow>, startTimestamp): Candlestick => { // TODO remove this partialCandlestick stuff and just return // a Candlestick after the temporary Candlestick.tokenVolume // is removed (see note on Candlestick.tokenVolume). const partialCandlestick: Pick<Candlestick, Exclude<keyof Candlestick, "tokenVolume">> = { // this Pick/Exclude stuff just allows us to set the Candlestick.tokenVolume later, but in a typesafe way that prevents typos. startTimestamp: parseInt(startTimestamp, 10), start: _.minBy(trades, "timestamp")!.price.toString(), end: _.maxBy(trades, "timestamp")!.price.toString(), min: _.minBy(trades, "price")!.price.toString(), max: _.maxBy(trades, "price")!.price.toString(), volume: _.reduce(trades, (totalVolume: BigNumber, tradeRow: MarketPriceHistoryRow) => totalVolume.plus(volumeForTrade({ marketMinPrice: marketsRow.minPrice, marketMaxPrice: marketsRow.maxPrice, numCreatorTokens: tradeRow.numCreatorTokens, numCreatorShares: tradeRow.numCreatorShares, numFillerTokens: tradeRow.numFillerTokens, numFillerShares: tradeRow.numFillerShares, })), ZERO).toString(), shareVolume: _.reduce(trades, (totalShareVolume: BigNumber, tradeRow: MarketPriceHistoryRow) => totalShareVolume.plus(tradeRow.amount), ZERO).toString(), // the business definition of shareVolume should be the same as used with markets/outcomes.shareVolume (which currently is just summation of trades.amount) }; return { tokenVolume: partialCandlestick.shareVolume, // tokenVolume is temporary, see note on Candlestick.tokenVolume ...partialCandlestick, }; });
export async function getReportingFees(db: Knex, augur: Augur, params: t.TypeOf<typeof ReportingFeesParams>): Promise<FeeDetails> { const currentUniverse = await getUniverse(db, params.universe); const participantEthFees: Array<ParticipantEthFee> = await getParticipantEthFees(db, augur, params.reporter, params.universe); const participationTokenEthFees: Array<ParticipationTokenEthFee> = await getParticipationTokenEthFees(db, augur, params.reporter, params.universe); const result: FormattedMarketInfo = await getMarketsReportingParticipants(db, params.reporter, currentUniverse, participantEthFees); const repStakeResults = await getStakedRepResults(db, params.reporter, params.universe, result.nonforkedMarkets); const unclaimedParticipantEthFees = _.reduce(participantEthFees, (acc, cur) => acc.plus(cur.fork ? 0 : cur.ethFees), ZERO); const unclaimedForkEthFees = _.reduce(participantEthFees, (acc, cur) => acc.plus(cur.fork ? cur.ethFees : 0), ZERO); const unclaimedParticipationTokenEthFees = _.reduce(participationTokenEthFees, (acc, cur) => acc.plus(cur.ethFees), ZERO); const redeemableFeeWindows = _.map(participationTokenEthFees, "feeWindow"); const participationTokenRepStaked = _.reduce(participationTokenEthFees, (acc, cur) => acc.plus(cur.participationTokens), ZERO); const unclaimedRepStaked = repStakeResults.fees.unclaimedRepStaked.plus(participationTokenRepStaked); return { total: { unclaimedParticipationTokenEthFees: unclaimedParticipationTokenEthFees.toFixed(0, BigNumber.ROUND_DOWN), participationTokenRepStaked: participationTokenRepStaked.toFixed(0, BigNumber.ROUND_DOWN), unclaimedEth: unclaimedParticipantEthFees.plus(unclaimedParticipationTokenEthFees).toFixed(0, BigNumber.ROUND_DOWN), unclaimedRepStaked: unclaimedRepStaked.toFixed(0, BigNumber.ROUND_DOWN), unclaimedRepEarned: repStakeResults.fees.unclaimedRepEarned.toFixed(0, BigNumber.ROUND_DOWN), lostRep: repStakeResults.fees.lostRep.toFixed(0, BigNumber.ROUND_DOWN), unclaimedForkEth: unclaimedForkEthFees.toFixed(0, BigNumber.ROUND_DOWN), unclaimedForkRepStaked: repStakeResults.fees.unclaimedForkRepStaked.toFixed(0, BigNumber.ROUND_DOWN), }, feeWindows: redeemableFeeWindows.sort(), forkedMarket: result.forkedMarket, nonforkedMarkets: repStakeResults.nonforkedMarkets, }; }
function countBackgroundGoals<T>(goals : IGoals<T>) : number { return _.reduce( goals.bgGoals, (acc, elt) => acc + elt.before.length + elt.after.length, 0 ) }
export async function fetchOncoKbAnnotatedGenes(client: OncoKbAPI = oncokbClient): Promise<{[entrezGeneId:number]:boolean}> { return _.reduce(await client.genesGetUsingGET({}), (map:{[entrezGeneId:number]:boolean}, next:OncoKbGene)=>{ map[next.entrezGeneId] = true; return map; }, {}); }
const itemsFromInvoiceToStockable = (items) => { return _.reduce(items, (prev, cur: StockItemModel) => { prev[cur.sku] = prev[cur.sku] || 0; prev[cur.sku] += cur.quantity; return prev; }, {}); };
let saveLog = results => { let application: ApplicationModel = results[0], basicinfo: ApplicationBasicinfoModel = results[1]; if (isLog === 'true') { LogModel.setConnection(connection); let after = _.reduce(admissionInfo.getDocument(), (result, value) => (result.push(value), result), []); return LogModel.save({ id: UUID.raw(), moduleid, module, opttype: '1', nodeid: user.nodeId, nodetype: user.nodeType, studentid: id, cscid: application.cscId, passportname: basicinfo.fullname, after: after.join('/'), before: null, columnen: null, columnch: null, tableen: 'ASMS_ADMISSION', tablech: '录取信息表', createby: user.userId, created: moment().toDate() }); } }
private groupKeyForLineItems(lineItems: ILineItem[]): string { const sortedLineItems = sortBy(lineItems, 'product.id'); return reduce(sortedLineItems, (key, lineItem) => { return key + this.groupKeyForLineItem(lineItem); }, ''); }
let baseData = _.map(data, item => { return _.reduce(report.columns, (prev, cur: any) => { if(!cur.checked && !cur.always) { return prev; } const value = _.get(item, cur.key, ''); prev[cur.name] = value; if(_.isNull(value)) { prev[cur.name] = ''; } if(_.includes(['Purchase Time', 'Last Sold', 'Start Date', 'End Date'], cur.name)) { if(!value) { prev[cur.name] = 'Never'; } else { prev[cur.name] = dateFunctions.format(new Date(value), 'YYYY-MM-DD hh:mm A'); } } if(cur.name === 'Purchase Method') { prev[cur.name] = settings.invoiceMethodDisplay(value); } return prev; }, {}); });