Skip to content

Commit

Permalink
Refactored Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfior committed Feb 14, 2025
1 parent e477e1f commit a3929ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions prediction_market_agent_tooling/markets/seer/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ class CreateCategoricalMarketsParams(BaseModel):


class SeerOutcomeEnum(str, Enum):
POSITIVE = "positive"
NEGATIVE = "negative"
NEUTRAL = "neutral"
YES = "yes"
NO = "no"
INVALID = "invalid"

@classmethod
def from_bool(cls, value: bool) -> "SeerOutcomeEnum":
return cls.POSITIVE if value else cls.NEGATIVE
return cls.YES if value else cls.NO

@classmethod
def from_string(cls, value: str) -> "SeerOutcomeEnum":
"""Convert a string (case-insensitive) to an Outcome enum."""
normalized = value.strip().lower()
patterns = {
r"^yes$": cls.POSITIVE,
r"^no$": cls.NEGATIVE,
r"^(invalid|invalid result)$": cls.NEUTRAL,
r"^yes$": cls.YES,
r"^no$": cls.NO,
r"^(invalid|invalid result)$": cls.INVALID,
}

# Search through patterns and return the first match
Expand Down Expand Up @@ -108,7 +108,7 @@ def has_valid_answer(self) -> bool:
# 2. Invalid payoutNumerator is 1.

try:
self.outcome_as_enums[SeerOutcomeEnum.NEUTRAL]
self.outcome_as_enums[SeerOutcomeEnum.INVALID]
except KeyError:
raise ValueError(
f"Market {self.id.hex()} has no invalid outcome. {self.outcomes}"
Expand Down Expand Up @@ -183,7 +183,7 @@ def current_p_yes(self) -> Probability:
)
price_data[idx] = price

yes_idx = self.outcome_as_enums[SeerOutcomeEnum.POSITIVE]
yes_idx = self.outcome_as_enums[SeerOutcomeEnum.YES]
price_yes = price_data[yes_idx] / sum(price_data.values())
return Probability(price_yes)

Expand Down
6 changes: 3 additions & 3 deletions tests_integration/markets/seer/test_seer_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def test_current_p_yes(
market = seer_subgraph_handler_test.get_binary_markets(
limit=100, sort_by=SortBy.HIGHEST_LIQUIDITY, filter_by=FilterBy.OPEN
)[0]
yes_idx = market.outcome_as_enums[SeerOutcomeEnum.POSITIVE]
yes_idx = market.outcome_as_enums[SeerOutcomeEnum.YES]
yes_token = market.wrapped_tokens[yes_idx]
yes_price = market._get_price_for_token(Web3.to_checksum_address(yes_token))

no_idx = market.outcome_as_enums[SeerOutcomeEnum.NEGATIVE]
no_idx = market.outcome_as_enums[SeerOutcomeEnum.NO]
no_token = market.wrapped_tokens[no_idx]
no_price = market._get_price_for_token(Web3.to_checksum_address(no_token))

invalid_idx = market.outcome_as_enums[SeerOutcomeEnum.NEUTRAL]
invalid_idx = market.outcome_as_enums[SeerOutcomeEnum.INVALID]
invalid_token = market.wrapped_tokens[invalid_idx]
invalid_price = market._get_price_for_token(Web3.to_checksum_address(invalid_token))

Expand Down
2 changes: 1 addition & 1 deletion tests_integration/markets/seer/test_seer_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test_seer_outcome(outcome: str) -> None:


def test_seer_outcome_invalid() -> None:
assert SeerOutcomeEnum.from_string("Invalid result") == SeerOutcomeEnum.NEUTRAL
assert SeerOutcomeEnum.from_string("Invalid result") == SeerOutcomeEnum.INVALID

0 comments on commit a3929ba

Please sign in to comment.