From 17fca140840175f624de0cfad46c29344c40cf08 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Thu, 12 May 2022 16:52:37 -0400 Subject: [PATCH] outcome label --- common/calculate-dpm.ts | 11 +++++++++++ common/contract.ts | 2 +- functions/src/emails.ts | 4 ++++ web/components/outcome-label.tsx | 8 ++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common/calculate-dpm.ts b/common/calculate-dpm.ts index e6773208..2e36cdfd 100644 --- a/common/calculate-dpm.ts +++ b/common/calculate-dpm.ts @@ -74,6 +74,17 @@ export const getMappedBucket = (value: number, contract: NumericContract) => { return `${bucket}` } +export const getValueFromBucket = ( + bucket: string, + contract: NumericContract +) => { + const { bucketCount, min, max } = contract + const index = parseInt(bucket) + const value = min + (index / bucketCount) * (max - min) + const rounded = Math.round(value * 1e4) / 1e4 + return rounded +} + export function getDpmOutcomeProbabilityAfterBet( totalShares: { [outcome: string]: number diff --git a/common/contract.ts b/common/contract.ts index 29930728..6f0b9e0f 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -48,7 +48,7 @@ export type Contract = FullContract< > export type BinaryContract = FullContract export type FreeResponseContract = FullContract -export type NumericContract = FullContract +export type NumericContract = FullContract export type DPM = { mechanism: 'dpm-2' diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 2b13495a..cbe65700 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -4,6 +4,7 @@ import { DOMAIN, PROJECT_ID } from 'common/envs/constants' import { Answer } from 'common/answer' import { Bet } from 'common/bet' import { getProbability } from 'common/calculate' +import { getValueFromBucket } from 'common/calculate-dpm' import { Comment } from 'common/comment' import { Contract, FreeResponseContract } from 'common/contract' import { DPM_CREATOR_FEE } from 'common/fees' @@ -105,6 +106,9 @@ const toDisplayResolution = ( if (resolution === 'MKT' && resolutions) return 'MULTI' if (resolution === 'CANCEL') return 'N/A' + if (contract.outcomeType === 'NUMERIC') + return getValueFromBucket(resolution, contract).toString() + const answer = (contract as FreeResponseContract).answers?.find( (a) => a.id === resolution ) diff --git a/web/components/outcome-label.tsx b/web/components/outcome-label.tsx index d578247b..86b2486e 100644 --- a/web/components/outcome-label.tsx +++ b/web/components/outcome-label.tsx @@ -1,6 +1,7 @@ import clsx from 'clsx' import { Answer } from 'common/answer' import { getProbability } from 'common/calculate' +import { getValueFromBucket } from 'common/calculate-dpm' import { Binary, Contract, @@ -23,6 +24,13 @@ export function OutcomeLabel(props: { if (contract.outcomeType === 'BINARY') return + if (contract.outcomeType === 'NUMERIC') + return ( + + {getValueFromBucket(outcome, contract)} + + ) + return ( }