Filter out resolved markets from daily movers
This commit is contained in:
parent
546b0231e7
commit
9e4f41253f
|
@ -12,8 +12,9 @@ import { formatNumericProbability } from 'common/pseudo-numeric'
|
||||||
export function ProfitChangeTable(props: {
|
export function ProfitChangeTable(props: {
|
||||||
contracts: CPMMBinaryContract[]
|
contracts: CPMMBinaryContract[]
|
||||||
metrics: ContractMetrics[]
|
metrics: ContractMetrics[]
|
||||||
|
maxRows?: number
|
||||||
}) {
|
}) {
|
||||||
const { contracts, metrics } = props
|
const { contracts, metrics, maxRows } = props
|
||||||
|
|
||||||
const contractProfit = metrics.map(
|
const contractProfit = metrics.map(
|
||||||
(m) => [m.contractId, m.from?.day.profit ?? 0] as const
|
(m) => [m.contractId, m.from?.day.profit ?? 0] as const
|
||||||
|
@ -27,7 +28,7 @@ export function ProfitChangeTable(props: {
|
||||||
positiveProfit.map(([contractId]) =>
|
positiveProfit.map(([contractId]) =>
|
||||||
contracts.find((c) => c.id === contractId)
|
contracts.find((c) => c.id === contractId)
|
||||||
)
|
)
|
||||||
)
|
).slice(0, maxRows)
|
||||||
|
|
||||||
const negativeProfit = sortBy(
|
const negativeProfit = sortBy(
|
||||||
contractProfit.filter(([, profit]) => profit < 0),
|
contractProfit.filter(([, profit]) => profit < 0),
|
||||||
|
@ -37,7 +38,7 @@ export function ProfitChangeTable(props: {
|
||||||
negativeProfit.map(([contractId]) =>
|
negativeProfit.map(([contractId]) =>
|
||||||
contracts.find((c) => c.id === contractId)
|
contracts.find((c) => c.id === contractId)
|
||||||
)
|
)
|
||||||
)
|
).slice(0, maxRows)
|
||||||
|
|
||||||
if (positive.length === 0 && negative.length === 0)
|
if (positive.length === 0 && negative.length === 0)
|
||||||
return <div className="px-4 text-gray-500">None</div>
|
return <div className="px-4 text-gray-500">None</div>
|
||||||
|
|
|
@ -47,10 +47,7 @@ export const usePrefetchUsers = (userIds: string[]) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUserContractMetricsByProfit = (
|
export const useUserContractMetricsByProfit = (userId: string, count = 50) => {
|
||||||
userId: string,
|
|
||||||
count: number
|
|
||||||
) => {
|
|
||||||
const positiveResult = useFirestoreQueryData<ContractMetrics>(
|
const positiveResult = useFirestoreQueryData<ContractMetrics>(
|
||||||
['contract-metrics-descending', userId, count],
|
['contract-metrics-descending', userId, count],
|
||||||
getUserContractMetricsQuery(userId, count, 'desc')
|
getUserContractMetricsQuery(userId, count, 'desc')
|
||||||
|
@ -71,10 +68,13 @@ export const useUserContractMetricsByProfit = (
|
||||||
if (!positiveResult.data || !negativeResult.data || !contracts)
|
if (!positiveResult.data || !negativeResult.data || !contracts)
|
||||||
return undefined
|
return undefined
|
||||||
|
|
||||||
const filteredContracts = filterDefined(contracts) as CPMMBinaryContract[]
|
const filteredContracts = filterDefined(contracts).filter(
|
||||||
const filteredMetrics = metrics.filter(
|
(c) => !c.isResolved
|
||||||
(m) => m.from && Math.abs(m.from.day.profit) >= 0.5
|
) as CPMMBinaryContract[]
|
||||||
)
|
const filteredMetrics = metrics
|
||||||
|
.filter((m) => m.from && Math.abs(m.from.day.profit) >= 0.5)
|
||||||
|
.filter((m) => filteredContracts.find((c) => c.id === m.contractId))
|
||||||
|
|
||||||
return { contracts: filteredContracts, metrics: filteredMetrics }
|
return { contracts: filteredContracts, metrics: filteredMetrics }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default function DailyMovers() {
|
||||||
function ProbChangesWrapper(props: { userId: string }) {
|
function ProbChangesWrapper(props: { userId: string }) {
|
||||||
const { userId } = props
|
const { userId } = props
|
||||||
|
|
||||||
const data = useUserContractMetricsByProfit(userId, 50)
|
const data = useUserContractMetricsByProfit(userId)
|
||||||
|
|
||||||
if (!data) return <LoadingIndicator />
|
if (!data) return <LoadingIndicator />
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,7 @@ export default function Home() {
|
||||||
}, [user, sections])
|
}, [user, sections])
|
||||||
|
|
||||||
const contractMetricsByProfit = useUserContractMetricsByProfit(
|
const contractMetricsByProfit = useUserContractMetricsByProfit(
|
||||||
user?.id ?? '_',
|
user?.id ?? '_'
|
||||||
3
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const trendingContracts = useTrendingContracts(6)
|
const trendingContracts = useTrendingContracts(6)
|
||||||
|
@ -494,7 +493,7 @@ function DailyMoversSection(props: {
|
||||||
return (
|
return (
|
||||||
<Col className="gap-2">
|
<Col className="gap-2">
|
||||||
<SectionHeader label="Daily movers" href="/daily-movers" />
|
<SectionHeader label="Daily movers" href="/daily-movers" />
|
||||||
<ProfitChangeTable contracts={contracts} metrics={metrics} />
|
<ProfitChangeTable contracts={contracts} metrics={metrics} maxRows={3} />
|
||||||
</Col>
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -530,8 +529,7 @@ export function DailyProfit(props: { user: User | null | undefined }) {
|
||||||
const { user } = props
|
const { user } = props
|
||||||
|
|
||||||
const contractMetricsByProfit = useUserContractMetricsByProfit(
|
const contractMetricsByProfit = useUserContractMetricsByProfit(
|
||||||
user?.id ?? '_',
|
user?.id ?? '_'
|
||||||
100
|
|
||||||
)
|
)
|
||||||
const profit = sum(
|
const profit = sum(
|
||||||
contractMetricsByProfit?.metrics.map((m) =>
|
contractMetricsByProfit?.metrics.map((m) =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user