Fixed cap

parent ec9fe6b6
......@@ -385,6 +385,10 @@ class GamesThread(ThreadedComponent):
# Calculate result using betting CAP logic
result = self._calculate_match_result(fixture_id, match_id)
# Store the under/over result from video selection calculation
logger.info(f"Storing under_over_result '{result}' for match {match_id}")
self._store_under_over_result(match_id, result)
# Send PLAY_VIDEO_MATCH with calculated result
self._send_play_video_match(fixture_id, match_id, result)
......@@ -403,6 +407,9 @@ class GamesThread(ThreadedComponent):
fixture_id = message.data.get("fixture_id")
match_id = message.data.get("match_id")
result = self._weighted_random_selection(1.0, 1.0) # Equal weights
# Store the fallback under/over result
logger.info(f"Storing fallback under_over_result '{result}' for match {match_id}")
self._store_under_over_result(match_id, result)
self._send_play_video_match(fixture_id, match_id, result)
except Exception as fallback_e:
logger.error(f"Fallback betting calculation also failed: {fallback_e}")
......@@ -1790,25 +1797,26 @@ class GamesThread(ThreadedComponent):
return None, None
def _get_redistribution_cap(self) -> float:
"""Get redistribution CAP percentage from configuration"""
"""Get redistribution CAP percentage from game configuration"""
try:
session = self.db_manager.get_session()
try:
# Get global CAP configuration
# Get CAP from game_config table (same as web dashboard saves it)
cap_config = session.query(GameConfigModel).filter_by(
config_key='redistribution_cap'
config_key='extraction_redistribution_cap'
).first()
if cap_config:
cap_value = cap_config.get_typed_value()
if isinstance(cap_value, (int, float)) and 10 <= cap_value <= 100:
logger.debug(f"Using redistribution CAP: {cap_value}%")
return float(cap_value)
else:
logger.warning(f"Invalid CAP value: {cap_value}, using default 70%")
return 70.0
else:
logger.debug("No CAP configuration found, using default 70%")
return 70.0 # Default CAP
logger.debug("No redistribution CAP configuration found, using default 70%")
return 70.0
finally:
session.close()
......@@ -2074,6 +2082,23 @@ class GamesThread(ThreadedComponent):
import traceback
logger.error(f"Full traceback: {traceback.format_exc()}")
def _store_under_over_result(self, match_id: int, under_over_result: str):
"""Store the under/over result from video selection calculation"""
try:
session = self.db_manager.get_session()
try:
match = session.query(MatchModel).filter_by(id=match_id).first()
if match:
match.under_over_result = under_over_result
session.commit()
logger.info(f"Stored under_over_result '{under_over_result}' for match {match_id}")
else:
logger.error(f"Match {match_id} not found for storing under_over_result")
finally:
session.close()
except Exception as e:
logger.error(f"Failed to store under_over_result for match {match_id}: {e}")
def _set_match_status(self, match_id: int, status: str):
"""Set match status in database"""
try:
......@@ -2355,12 +2380,12 @@ class GamesThread(ThreadedComponent):
win_coefficient = self._get_outcome_coefficient(match_id, selected_result, session)
logger.info(f"DEBUG _update_bet_results: win_coefficient = {win_coefficient}")
# Update UNDER/OVER bets - they win if they match the UNDER/OVER outcome
under_over_outcome = 'UNDER' if selected_result == 'UNDER' else 'OVER' if selected_result == 'OVER' else None
logger.info(f"DEBUG _update_bet_results: under_over_outcome = '{under_over_outcome}'")
# Get the stored UNDER/OVER result from video selection calculation
match = session.query(MatchModel).filter_by(id=match_id).first()
under_over_outcome = match.under_over_result if match else None
logger.info(f"DEBUG _update_bet_results: under_over_outcome from stored value = '{under_over_outcome}'")
# DEBUG: Log the current match result before updating
match = session.query(MatchModel).filter_by(id=match_id).first()
if match:
logger.info(f"DEBUG _update_bet_results: Current match.result before formatting = '{match.result}'")
......@@ -2424,12 +2449,23 @@ class GamesThread(ThreadedComponent):
if match:
logger.info(f"DEBUG _update_bet_results: Before update - match.result = '{match.result}'")
# Get winning outcomes for the selected result
winning_outcomes = session.query(ExtractionAssociationModel.outcome_name).filter(
# Get winning outcomes for the selected result from extraction associations
extraction_winning_outcomes = session.query(ExtractionAssociationModel.outcome_name).filter(
ExtractionAssociationModel.extraction_result == selected_result
).distinct().all()
winning_outcome_names = [outcome.outcome_name for outcome in winning_outcomes]
logger.info(f"DEBUG _update_bet_results: Found {len(winning_outcomes)} winning outcomes for '{selected_result}': {winning_outcome_names}")
extraction_winning_outcome_names = [outcome.outcome_name for outcome in extraction_winning_outcomes]
logger.info(f"DEBUG _update_bet_results: Found {len(extraction_winning_outcomes)} winning outcomes from extraction associations for '{selected_result}': {extraction_winning_outcome_names}")
# Get possible outcomes for this match
possible_outcomes = session.query(MatchOutcomeModel.column_name).filter(
MatchOutcomeModel.match_id == match_id
).all()
possible_outcome_names = [outcome.column_name for outcome in possible_outcomes]
logger.info(f"DEBUG _update_bet_results: Match {match_id} has {len(possible_outcomes)} possible outcomes: {possible_outcome_names}")
# Filter winning outcomes to only include those that are possible for this match
winning_outcome_names = [outcome for outcome in extraction_winning_outcome_names if outcome in possible_outcome_names]
logger.info(f"DEBUG _update_bet_results: After filtering against possible outcomes, {len(winning_outcome_names)} winning outcomes remain: {winning_outcome_names}")
# Set the main result (selected_result)
match.result = selected_result
......@@ -2643,6 +2679,12 @@ class GamesThread(ThreadedComponent):
try:
session = self.db_manager.get_session()
try:
# First, check if we have a stored under_over_result from video selection
match = session.query(MatchModel).filter_by(id=match_id).first()
if match and match.under_over_result:
logger.info(f"Using stored under_over_result '{match.under_over_result}' for match {match_id}")
return match.under_over_result
# If the main result is already UNDER or OVER, return it
if main_result in ['UNDER', 'OVER']:
return main_result
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment