Add unique traders rule (untested)

This commit is contained in:
Olivia Appleton 2022-10-24 15:39:52 -04:00
parent 3d820da6d3
commit 91de305dd5
GPG Key ID: AF65A9CA0FF7FD69
3 changed files with 28 additions and 0 deletions

View File

@ -40,12 +40,14 @@ AVAILABLE_RULES = [
"github.ResolveToPR",
"github.ResolveToPRDelta",
"manifold.this.CurrentValueRule",
"manifold.this.UniqueTradersRule",
"manifold.this.FibonacciValueRule",
"manifold.this.PopularValueRule",
"manifold.this.ThisMarketClosed",
"manifold.other.AmplifiedOddsRule",
"manifold.other.OtherMarketClosed",
"manifold.other.OtherMarketResolved",
"manifold.other.OtherMarketUniqueTraders",
"manifold.other.OtherMarketValue",
"manifold.user.ResolveToUserProfit",
"manifold.user.ResolveToUserCreatedVolume"

View File

@ -48,6 +48,19 @@ class OtherMarketResolved(DoResolveRule, ManifoldMarketMixin):
return f"{' ' * indent}- If `{self.id_}` is resolved ({self.api_market().question}).\n"
@define(slots=False)
class OtherMarketUniqueTraders(ManifoldMarketMixin, Rule[int]):
"""A rule that checks whether another market is resolved."""
def _value(self, market: Market) -> int:
return len(
{bet.userId for bet in self.api_market().bets} - {None}
)
def _explain_abstract(self, indent: int = 0, **kwargs: Any) -> str:
return f"{' ' * indent}- The number of unique traders on `{self.id_}` ({self.api_market().question}).\n"
@define(slots=False)
class OtherMarketValue(ManifoldMarketMixin, Rule[T]):
"""A rule that resolves to the value of another rule."""

View File

@ -56,6 +56,19 @@ class CurrentValueRule(AbstractRule[AnyResolution]):
return market_to_answer_map(market)
@define(slots=False)
class UniqueTradersRule(AbstractRule[int]):
"""Resolve to the current market-consensus value."""
_explainer_stub: ClassVar[str] = "Resolves to the current number of unique traders"
def _value(self, market: Market) -> int:
market.refresh()
return len(
{bet.userId for bet in market.market.bets} - {None}
)
@define(slots=False)
class FibonacciValueRule(Rule[Union[float, Mapping[int, float]]]):
"""Resolve each value with a fibonacci weight, ranked by probability."""