Skip to content

Commit

Permalink
Limited support for predictions with > 2 outcomes
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavydov committed Dec 2, 2022
1 parent 5617580 commit af2057e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion TwitchChannelPointsMiner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "1.5.2"
__version__ = "1.5.3"
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner

__all__ = [
Expand Down
5 changes: 3 additions & 2 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def load_channel_points_context(self, streamer):

def make_predictions(self, event):
decision = event.bet.calculate(event.streamer.channel_points)
selector_index = 0 if decision["choice"] == "A" else 1
#selector_index = 0 if decision["choice"] == "A" else 1

logger.info(
f"Going to complete bet for {event}",
Expand Down Expand Up @@ -571,7 +571,8 @@ def make_predictions(self, event):
else:
if decision["amount"] >= 10:
logger.info(
f"Place {_millify(decision['amount'])} channel points on: {event.bet.get_outcome(selector_index)}",
#f"Place {_millify(decision['amount'])} channel points on: {event.bet.get_outcome(selector_index)}",
f"Place {_millify(decision['amount'])} channel points on: {event.bet.get_outcome(decision['choice'])}",
extra={
"emoji": ":four_leaf_clover:",
"event": Events.BET_GENERAL,
Expand Down
56 changes: 33 additions & 23 deletions TwitchChannelPointsMiner/classes/entities/Bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from millify import millify

from TwitchChannelPointsMiner.utils import char_decision_as_index, float_round
#from TwitchChannelPointsMiner.utils import char_decision_as_index, float_round
from TwitchChannelPointsMiner.utils import float_round


class Strategy(Enum):
Expand Down Expand Up @@ -154,33 +155,32 @@ def update_outcomes(self, outcomes):
top_points = outcomes[index]["top_predictors"][0]["points"]
self.outcomes[index][OutcomeKeys.TOP_POINTS] = top_points

self.total_users = (
self.outcomes[0][OutcomeKeys.TOTAL_USERS]
+ self.outcomes[1][OutcomeKeys.TOTAL_USERS]
)
self.total_points = (
self.outcomes[0][OutcomeKeys.TOTAL_POINTS]
+ self.outcomes[1][OutcomeKeys.TOTAL_POINTS]
)
# Inefficient, but otherwise outcomekeys are represented wrong
self.total_points = 0
self.total_users = 0
for index in range(0, len(self.outcomes)):
self.total_users += self.outcomes[index][OutcomeKeys.TOTAL_USERS]
self.total_points += self.outcomes[index][OutcomeKeys.TOTAL_POINTS]

if (
self.total_users > 0
and self.outcomes[0][OutcomeKeys.TOTAL_POINTS] > 0
and self.outcomes[1][OutcomeKeys.TOTAL_POINTS] > 0
and self.total_points > 0
):
for index in range(0, len(self.outcomes)):
self.outcomes[index][OutcomeKeys.PERCENTAGE_USERS] = float_round(
(100 * self.outcomes[index][OutcomeKeys.TOTAL_USERS])
#/ self.total_users
/ max(self.total_users, 1)
(100 * self.outcomes[index][OutcomeKeys.TOTAL_USERS]) / self.total_users
)
self.outcomes[index][OutcomeKeys.ODDS] = float_round(
#self.total_points / self.outcomes[index][OutcomeKeys.TOTAL_POINTS]
self.total_points / max(self.outcomes[index][OutcomeKeys.TOTAL_POINTS], 1)
#self.total_points / max(self.outcomes[index][OutcomeKeys.TOTAL_POINTS], 1)
0
if self.outcomes[index][OutcomeKeys.TOTAL_POINTS] == 0
else self.total_points / self.outcomes[index][OutcomeKeys.TOTAL_POINTS]
)
self.outcomes[index][OutcomeKeys.ODDS_PERCENTAGE] = float_round(
#100 / self.outcomes[index][OutcomeKeys.ODDS]
100 / max(self.outcomes[index][OutcomeKeys.ODDS], 1)
#100 / max(self.outcomes[index][OutcomeKeys.ODDS], 1)
0
if self.outcomes[index][OutcomeKeys.ODDS] == 0
else 100 / self.outcomes[index][OutcomeKeys.ODDS]
)

self.__clear_outcomes()
Expand All @@ -189,7 +189,8 @@ def __repr__(self):
return f"Bet(total_users={millify(self.total_users)}, total_points={millify(self.total_points)}), decision={self.decision})\n\t\tOutcome A({self.get_outcome(0)})\n\t\tOutcome B({self.get_outcome(1)})"

def get_decision(self, parsed=False):
decision = self.outcomes[0 if self.decision["choice"] == "A" else 1]
#decision = self.outcomes[0 if self.decision["choice"] == "A" else 1]
decision = self.outcomes[self.decision["choice"]]
return decision if parsed is False else Bet.__parse_outcome(decision)

@staticmethod
Expand Down Expand Up @@ -224,8 +225,15 @@ def __clear_outcomes(self):
if key not in self.outcomes[index]:
self.outcomes[index][key] = 0

def __return_choice(self, key) -> str:
return "A" if self.outcomes[0][key] > self.outcomes[1][key] else "B"
'''def __return_choice(self, key) -> str:
return "A" if self.outcomes[0][key] > self.outcomes[1][key] else "B"'''

def __return_choice(self, key) -> int:
largest=0
for index in range(0, len(self.outcomes)):
if self.outcomes[index][key] > self.outcomes[largest][key]:
largest = index
return largest

def skip(self) -> bool:
if self.settings.filter_condition is not None:
Expand All @@ -244,7 +252,8 @@ def skip(self) -> bool:
self.outcomes[0][fixed_key] + self.outcomes[1][fixed_key]
)
else:
outcome_index = char_decision_as_index(self.decision["choice"])
#outcome_index = char_decision_as_index(self.decision["choice"])
outcome_index = self.decision["choice"]
compared_value = self.outcomes[outcome_index][fixed_key]

# Check if condition is satisfied
Expand Down Expand Up @@ -286,7 +295,8 @@ def calculate(self, balance: int) -> dict:
)

if self.decision["choice"] is not None:
index = char_decision_as_index(self.decision["choice"])
#index = char_decision_as_index(self.decision["choice"])
index = self.decision["choice"]
self.decision["id"] = self.outcomes[index]["id"]
self.decision["amount"] = min(
int(balance * (self.settings.percentage / 100)),
Expand Down
5 changes: 2 additions & 3 deletions TwitchChannelPointsMiner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ def set_default_settings(settings, defaults):
)


def char_decision_as_index(char):
return 0 if char == "A" else 1

'''def char_decision_as_index(char):
return 0 if char == "A" else 1'''

def internet_connection_available(host="8.8.8.8", port=53, timeout=3):
try:
Expand Down

0 comments on commit af2057e

Please sign in to comment.