Skip to content

Commit

Permalink
Fix updating ts and share booleans on summary metric
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Nov 13, 2024
1 parent db68ff5 commit b7207b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/supabase/user_contract_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BEGIN
-- Update the row where answer_id is null with the aggregated metrics
UPDATE user_contract_metrics
SET
data = data || jsonb_build_object('hasYesShares', sum_has_yes_shares, 'hasNoShares', sum_has_no_shares, 'hasShares', sum_has_shares),
has_yes_shares = sum_has_yes_shares,
has_no_shares = sum_has_no_shares,
has_shares = sum_has_shares
Expand Down
23 changes: 17 additions & 6 deletions common/src/calculate-metrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Dictionary, groupBy, min, orderBy, sum, sumBy, uniq } from 'lodash'
import {
cloneDeep,
Dictionary,
groupBy,
min,
orderBy,
sum,
sumBy,
uniq,
} from 'lodash'
import {
calculatePayout,
calculateTotalSpentAndShares,
Expand Down Expand Up @@ -415,11 +424,13 @@ export const calculateAnswerMetricsWithNewBetsOnly = (

return Object.entries(betsByUser).flatMap(([userId, bets]) => {
// If it's a multi market, we need to summarize the stats for the null answer
const oldSummary = userMetrics.find(
(m) =>
m.answerId === null &&
m.userId === userId &&
m.contractId === contractId
const oldSummary = cloneDeep(
userMetrics.find(
(m) =>
m.answerId === null &&
m.userId === userId &&
m.contractId === contractId
)
)
const userBetsByAnswer = groupBy(bets, 'answerId')
const newMetrics = Object.entries(userBetsByAnswer).map(
Expand Down

0 comments on commit b7207b9

Please sign in to comment.