Limited support for predictions with > 2 outcomes

This commit is contained in:
rdavydov
2022-12-02 19:56:40 +03:00
parent 5617580e27
commit af2057e61f
4 changed files with 39 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "1.5.2"
__version__ = "1.5.3"
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner
__all__ = [

View File

@@ -542,7 +542,7 @@ class Twitch(object):
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}",
@@ -571,7 +571,8 @@ class Twitch(object):
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,

View File

@@ -4,7 +4,8 @@ from random import uniform
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):
@@ -154,33 +155,32 @@ class Bet(object):
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()
@@ -189,7 +189,8 @@ class Bet(object):
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
@@ -224,8 +225,15 @@ class Bet(object):
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:
@@ -244,7 +252,8 @@ class Bet(object):
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
@@ -286,7 +295,8 @@ class Bet(object):
)
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)),

View File

@@ -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: