mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
game filtering logic
This commit is contained in:
14
README.md
14
README.md
@@ -105,7 +105,7 @@ python test_odds_ticker.py
|
||||
|
||||
The LEDMatrix system uses persistent caching to improve performance and reduce API calls. When running with `sudo`, the system needs a persistent cache directory that survives restarts.
|
||||
|
||||
**Automatic Setup:**
|
||||
**First-Time Setup:**
|
||||
Run the setup script to create a persistent cache directory:
|
||||
```bash
|
||||
chmod +x setup_cache.sh
|
||||
@@ -115,14 +115,22 @@ chmod +x setup_cache.sh
|
||||
This will:
|
||||
- Create `/var/cache/ledmatrix/` directory
|
||||
- Set proper ownership to your user account
|
||||
- Set appropriate permissions (755)
|
||||
- Set permissions to allow the daemon user (which the system runs as) to write
|
||||
- Test writability for both your user and the daemon user
|
||||
|
||||
**If You Still See Cache Warnings:**
|
||||
If you see warnings about using temporary cache directory, run the permissions fix:
|
||||
```bash
|
||||
chmod +x fix_cache_permissions.sh
|
||||
./fix_cache_permissions.sh
|
||||
```
|
||||
|
||||
**Manual Setup:**
|
||||
If you prefer to set up manually:
|
||||
```bash
|
||||
sudo mkdir -p /var/cache/ledmatrix
|
||||
sudo chown $USER:$USER /var/cache/ledmatrix
|
||||
sudo chmod 755 /var/cache/ledmatrix
|
||||
sudo chmod 777 /var/cache/ledmatrix
|
||||
```
|
||||
|
||||
**Cache Locations (in order of preference):**
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
"live_odds_update_interval": 3600,
|
||||
"odds_update_interval": 3600,
|
||||
"fetch_past_games": 1,
|
||||
"fetch_future_games": 5,
|
||||
"fetch_future_games": 2,
|
||||
"favorite_teams": ["TB", "DAL"],
|
||||
"logo_dir": "assets/sports/nfl_logos",
|
||||
"show_records": true,
|
||||
@@ -196,7 +196,7 @@
|
||||
"live_odds_update_interval": 3600,
|
||||
"odds_update_interval": 3600,
|
||||
"fetch_past_games": 1,
|
||||
"fetch_future_games": 5,
|
||||
"fetch_future_games": 2,
|
||||
"favorite_teams": ["UGA", "AUB"],
|
||||
"logo_dir": "assets/sports/ncaa_fbs_logos",
|
||||
"show_records": true,
|
||||
|
||||
@@ -11,24 +11,35 @@ sudo mkdir -p /var/cache/ledmatrix
|
||||
# Get the real user (not root when running with sudo)
|
||||
REAL_USER=${SUDO_USER:-$USER}
|
||||
|
||||
# Set ownership to the real user
|
||||
# Set ownership to the real user first
|
||||
sudo chown $REAL_USER:$REAL_USER /var/cache/ledmatrix
|
||||
|
||||
# Set permissions
|
||||
sudo chmod 755 /var/cache/ledmatrix
|
||||
# Set permissions to 777 to allow daemon user to write
|
||||
sudo chmod 777 /var/cache/ledmatrix
|
||||
|
||||
echo "Cache directory created: /var/cache/ledmatrix"
|
||||
echo "Ownership set to: $REAL_USER"
|
||||
echo "Permissions set to: 755"
|
||||
echo "Permissions set to: 777 (writable by all users including daemon)"
|
||||
|
||||
# Test if the directory is writable
|
||||
# Test if the directory is writable by the current user
|
||||
if [ -w /var/cache/ledmatrix ]; then
|
||||
echo "✓ Cache directory is writable"
|
||||
echo "✓ Cache directory is writable by current user"
|
||||
else
|
||||
echo "✗ Cache directory is not writable"
|
||||
echo "✗ Cache directory is not writable by current user"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test if the directory is writable by daemon user (which the system runs as)
|
||||
if sudo -u daemon test -w /var/cache/ledmatrix; then
|
||||
echo "✓ Cache directory is writable by daemon user"
|
||||
else
|
||||
echo "✗ Cache directory is not writable by daemon user"
|
||||
echo "This might cause issues when running with sudo"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Setup complete! LEDMatrix will now use persistent caching."
|
||||
echo "The cache will survive system restarts."
|
||||
echo "The cache will survive system restarts."
|
||||
echo ""
|
||||
echo "If you see warnings about using temporary cache directory,"
|
||||
echo "the system will automatically fall back to /tmp/ledmatrix_cache/"
|
||||
@@ -220,6 +220,10 @@ class BaseNCAAFBManager: # Renamed class
|
||||
# Track games found for each favorite team
|
||||
favorite_team_games = {team: [] for team in self.favorite_teams} if self.favorite_teams else {}
|
||||
|
||||
# Debug: Log what we're looking for
|
||||
if self.favorite_teams and need_future_games:
|
||||
BaseNCAAFBManager.logger.info(f"[NCAAFB] Looking for {actual_future_games} games for each favorite team: {self.favorite_teams}")
|
||||
|
||||
# Check for cached search ranges and last successful date
|
||||
range_cache_key = f"search_ranges_ncaafb_{actual_past_games}_{actual_future_games}"
|
||||
cached_ranges = BaseNCAAFBManager.cache_manager.get(range_cache_key, max_age=86400) # Cache for 24 hours
|
||||
@@ -257,6 +261,17 @@ class BaseNCAAFBManager: # Renamed class
|
||||
while (len(past_events) < actual_past_games or
|
||||
(need_future_games and self.favorite_teams and
|
||||
not all(len(games) >= actual_future_games for games in favorite_team_games.values()))) and days_to_check <= max_days_to_check:
|
||||
|
||||
# Debug: Log search loop condition
|
||||
if need_future_games and self.favorite_teams:
|
||||
past_games_needed = len(past_events) < actual_past_games
|
||||
future_games_needed = not all(len(games) >= actual_future_games for games in favorite_team_games.values())
|
||||
days_limit_ok = days_to_check <= max_days_to_check
|
||||
BaseNCAAFBManager.logger.debug(f"[NCAAFB] Search loop condition: past_needed={past_games_needed}, future_needed={future_games_needed}, days_ok={days_limit_ok}")
|
||||
if not future_games_needed:
|
||||
BaseNCAAFBManager.logger.info(f"[NCAAFB] Stopping search - found enough games for all favorite teams")
|
||||
break
|
||||
|
||||
# Check dates in both directions
|
||||
dates_to_check = []
|
||||
|
||||
@@ -336,18 +351,39 @@ class BaseNCAAFBManager: # Renamed class
|
||||
home_abbr = home_team['team']['abbreviation']
|
||||
away_abbr = away_team['team']['abbreviation']
|
||||
|
||||
# Debug: Log all teams found
|
||||
BaseNCAAFBManager.logger.debug(f"[NCAAFB] Found game: {away_abbr}@{home_abbr}")
|
||||
|
||||
# Check if this game involves a favorite team
|
||||
for team in self.favorite_teams:
|
||||
if team in [home_abbr, away_abbr]:
|
||||
if len(favorite_team_games[team]) < actual_future_games:
|
||||
favorite_team_games[team].append(event)
|
||||
BaseNCAAFBManager.logger.debug(f"[NCAAFB] Found game for {team}: {away_abbr}@{home_abbr}")
|
||||
else:
|
||||
# Debug: Log all teams found even when not tracking favorite teams
|
||||
competition = event.get('competitions', [{}])[0]
|
||||
competitors = competition.get('competitors', [])
|
||||
home_team = next((c for c in competitors if c.get('homeAway') == 'home'), None)
|
||||
away_team = next((c for c in competitors if c.get('homeAway') == 'away'), None)
|
||||
|
||||
if home_team and away_team:
|
||||
home_abbr = home_team['team']['abbreviation']
|
||||
away_abbr = away_team['team']['abbreviation']
|
||||
BaseNCAAFBManager.logger.debug(f"[NCAAFB] Found game (not tracking favorites): {away_abbr}@{home_abbr}")
|
||||
except Exception as e:
|
||||
BaseNCAAFBManager.logger.warning(f"[NCAAFB] Could not parse event date: {e}")
|
||||
continue
|
||||
|
||||
days_to_check += 1
|
||||
|
||||
# Debug: Log what we found for each favorite team
|
||||
if self.favorite_teams and need_future_games:
|
||||
BaseNCAAFBManager.logger.info(f"[NCAAFB] Search completed. Games found for each favorite team:")
|
||||
for team in self.favorite_teams:
|
||||
games_found = len(favorite_team_games.get(team, []))
|
||||
BaseNCAAFBManager.logger.info(f"[NCAAFB] {team}: {games_found}/{actual_future_games} games")
|
||||
|
||||
# Cache the search ranges for next time
|
||||
if len(past_events) >= actual_past_games and len(future_events) >= actual_future_games:
|
||||
# Calculate how many days we actually needed
|
||||
@@ -588,6 +624,9 @@ class BaseNCAAFBManager: # Renamed class
|
||||
competitors = competition["competitors"]
|
||||
game_date_str = game_event["date"]
|
||||
|
||||
# Debug: Log the game we're processing
|
||||
self.logger.debug(f"[NCAAFB] Processing game event: {game_event.get('id')}")
|
||||
|
||||
start_time_utc = None
|
||||
try:
|
||||
start_time_utc = datetime.fromisoformat(game_date_str.replace("Z", "+00:00"))
|
||||
@@ -603,6 +642,10 @@ class BaseNCAAFBManager: # Renamed class
|
||||
|
||||
home_abbr = home_team["team"]["abbreviation"]
|
||||
away_abbr = away_team["team"]["abbreviation"]
|
||||
|
||||
# Debug: Log the teams found
|
||||
self.logger.debug(f"[NCAAFB] Found teams: {away_abbr}@{home_abbr}, Status: {status['type']['name']}")
|
||||
|
||||
home_record = home_team.get('records', [{}])[0].get('summary', '') if home_team.get('records') else ''
|
||||
away_record = away_team.get('records', [{}])[0].get('summary', '') if away_team.get('records') else ''
|
||||
|
||||
@@ -1321,6 +1364,11 @@ class NCAAFBUpcomingManager(BaseNCAAFBManager): # Renamed class
|
||||
all_teams.add(game['home_abbr'])
|
||||
self.logger.debug(f"[NCAAFB Upcoming] All teams found in API: {sorted(all_teams)}")
|
||||
|
||||
# Debug: Log what events we received and what we extracted
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Received {len(events)} events from shared data")
|
||||
for i, event in enumerate(events):
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Event {i}: ID={event.get('id')}, Status={event.get('competitions', [{}])[0].get('status', {}).get('type', {}).get('name', 'unknown')}")
|
||||
|
||||
# Filter for favorite teams
|
||||
if self.favorite_teams:
|
||||
team_games = [game for game in processed_games
|
||||
|
||||
Reference in New Issue
Block a user