1a6afaf44f
* create pseudo-numeric contracts * graph and bet panel for pseudo numeric * pseudo numeric market layout, quick betting * Estimated value * sell panel * fix graph * pseudo numeric resolution * bets tab * redemption for pseudo numeric markets * create log scale market, validation * log scale * create: initial value can't be min or max * don't allow log scale for ranges with negative values (b/c of problem with graph library) * prettier delenda est * graph: handle min value of zero * bet labeling * validation * prettier * pseudo numeric embeds * update disclaimer * validation * validation
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { BinaryContract, PseudoNumericContract } from './contract'
|
|
import { formatLargeNumber, formatPercent } from './util/format'
|
|
|
|
export function formatNumericProbability(
|
|
p: number,
|
|
contract: PseudoNumericContract
|
|
) {
|
|
const value = getMappedValue(contract)(p)
|
|
return formatLargeNumber(value)
|
|
}
|
|
|
|
export const getMappedValue =
|
|
(contract: PseudoNumericContract | BinaryContract) => (p: number) => {
|
|
if (contract.outcomeType === 'BINARY') return p
|
|
|
|
const { min, max, isLogScale } = contract
|
|
|
|
if (isLogScale) {
|
|
const logValue = p * Math.log10(max - min)
|
|
return 10 ** logValue + min
|
|
}
|
|
|
|
return p * (max - min) + min
|
|
}
|
|
|
|
export const getFormattedMappedValue =
|
|
(contract: PseudoNumericContract | BinaryContract) => (p: number) => {
|
|
if (contract.outcomeType === 'BINARY') return formatPercent(p)
|
|
|
|
const value = getMappedValue(contract)(p)
|
|
return formatLargeNumber(value)
|
|
}
|
|
|
|
export const getPseudoProbability = (
|
|
value: number,
|
|
min: number,
|
|
max: number,
|
|
isLogScale = false
|
|
) => {
|
|
if (isLogScale) {
|
|
return Math.log10(value - min) / Math.log10(max - min)
|
|
}
|
|
|
|
return (value - min) / (max - min)
|
|
}
|