Open zepor opened 1 month ago
The task involves integrating new data feeds from SportsRadar and NFLLAKE into an existing backend system. This requires updating configuration files, adding new methods to handle the new data feeds, and ensuring proper error handling and logging. The solution involves modifying several files to include settings for the new data feeds, updating existing methods to handle new data structures, and adding new methods where necessary.
backend-container/src/sportsradar/simulation/config.py
Update the configuration to include settings for the new data feeds from SportsRadar and NFLLAKE.
import os
from dotenv import load_dotenv
load_dotenv("../../../.env")
class Config:
BASE_URL = "https://playback.sportradar.com"
CONTENT_TYPE = "json"
LEAGUE = "nfl"
SPORTSRADAR_API_KEY = os.environ.get('SPORTSRADAR_API_KEY')
NFLLAKE_API_KEY = os.environ.get('NFLLAKE_API_KEY')
SPORTSRADAR_BASE_URL = "https://api.sportradar.com"
NFLLAKE_BASE_URL = "https://api.nfllake.com"
backend-container/src/sportsradar/auth/providers.json
Create a new file to include settings for the new data feeds from SportsRadar and NFLLAKE.
{
"providers": {
"sportsradar": {
"api_key": "SPORTSRADAR_API_KEY",
"base_url": "https://api.sportradar.com",
"documentation_url": "https://developer.sportradar.com/football/docs/nfl-ig-getting-started"
},
"nfllake": {
"api_key": "NFLLAKE_API_KEY",
"base_url": "https://api.nfllake.com",
"documentation_url": "https://developer.nfllake.com/docs"
}
}
}
backend-container/src/sportsradar/realm_config.json
Create a new file to include configuration settings for the new data feeds from SportsRadar and NFLLAKE.
{
"data_feeds": {
"sportsradar": {
"api_key": "SPORTSRADAR_API_KEY",
"base_url": "https://api.sportradar.com",
"endpoints": {
"nfl": "/nfl/official/trial/v6/en",
"historical": "/nfl/official/trial/v6/en/historical"
}
},
"nfllake": {
"api_key": "NFLLAKE_API_KEY",
"base_url": "https://api.nfllake.com",
"endpoints": {
"nfl": "/nfl/v1",
"historical": "/nfl/v1/historical"
}
}
},
"settings": {
"cache_duration": 3600,
"retry_attempts": 3,
"timeout": 30
}
}
backend-container/src/sportsradar/requirements.txt
Ensure all necessary dependencies for handling the new data feeds are included.
annotated-types==0.6.0
Brotli
certifi
cffi
charset-normalizer
colorama
coloredlogs==15.0.1
cryptography
humanfriendly
idna
pycparser
pydantic==2.5.2
pydantic-settings==2.1.0
pydantic-core==2.14.5
pyOpenSSL
pyreadline3
PySocks
python-dotenv==1.0.0
requests
typing-extensions
urllib3
win-inet-pton
pymongo[srv]
flake8
black
pytest
pre-commit
httpx==0.21.1
backend-container/src/sportsradar/environments/testing.json
Create a new file to include configuration settings for the new data feeds in the testing environment.
{
"environment": "testing",
"sportsradar": {
"api_key": "YOUR_SPORTSRADAR_API_KEY",
"base_url": "https://api.sportradar.us",
"endpoints": {
"nfl": "/nfl/official/trial/v6/en/"
}
},
"nfllake": {
"api_key": "YOUR_NFLLAKE_API_KEY",
"base_url": "https://api.nfllake.com",
"endpoints": {
"nfl": "/v1/nfl/"
}
},
"logging": {
"level": "DEBUG",
"file": "logs/testing.log"
}
}
backend-container/src/sportsradar/auth/custom_user_data.json
Create a new file to include configuration settings for the new data feeds from SportsRadar and NFLLAKE.
{
"dataFeeds": {
"sportsRadar": {
"apiKey": "SPORTSRADAR_API_KEY",
"apiEndpoint": "https://api.sportradar.com/nfl/official/trial/v6/en/",
"documentation": "https://developer.sportradar.com/football/docs/nfl-ig-getting-started"
},
"nflLake": {
"apiKey": "NFLLAKE_API_KEY",
"apiEndpoint": "https://api.nfllake.com/v1/",
"documentation": "https://developer.nfllake.com/docs/getting-started"
}
}
}
backend-container/src/sportsradar/simulation/__init__.py
Initialize the necessary components and configurations for the simulation module to work with the new data feeds.
from .gamefeeds import GameFeedSimulator
from .playerfeeds import PlayerFeedSimulator
from .teamfeeds import TeamFeedSimulator
from .additionalfeeds import AdditionalFeedSimulator
from ..logging_helpers import setup_logging
logger = setup_logging(__name__)
def initialize_simulation():
logger.info("Initializing simulation module with new data feeds")
game_feed_simulator = GameFeedSimulator()
logger.info("Game feed simulator initialized")
player_feed_simulator = PlayerFeedSimulator()
logger.info("Player feed simulator initialized")
team_feed_simulator = TeamFeedSimulator()
logger.info("Team feed simulator initialized")
additional_feed_simulator = AdditionalFeedSimulator()
logger.info("Additional feed simulator initialized")
logger.info("Simulation module initialization complete")
initialize_simulation()
backend-container/src/sportsradar/environments/no-environment.json
Create a new file to include configuration settings for the new data feeds in a "no-environment" setup.
{
"environment": "no-environment",
"data_feeds": {
"sportsradar": {
"api_key": "YOUR_SPORTSRADAR_API_KEY",
"base_url": "https://api.sportradar.us",
"endpoints": {
"nfl": "/nfl/official/trial/v5/en/games/{game_id}/summary.json"
}
},
"nfllake": {
"api_key": "YOUR_NFLLAKE_API_KEY",
"base_url": "https://api.nfllake.com",
"endpoints": {
"nfl": "/nfl/v1/games/{game_id}/details"
}
}
},
"logging": {
"level": "INFO",
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
}
backend-container/src/sportsradar/extract/__init__.py
Initialize the necessary components and configurations for the extraction module to work with the new data feeds.
from .playerfeeds import extract_player_data
from .gamefeeds import extract_game_data
from .teamfeeds import extract_team_data
from .additionalfeeds import extract_additional_data
def initialize_extraction():
print("Initializing extraction module for SportsRadar and NFLLAKE data feeds.")
initialize_extraction()
backend-container/src/sportsradar/sync/config.json
Create a new configuration file that includes settings for the new data feeds from SportsRadar and NFLLAKE.
{
"sportsradar": {
"api_base_url": "https://api.sportradar.us/nfl/official/trial/v6/en/",
"api_key": "${{ secrets.SPORTSRADAR_API_KEY }}",
"update_interval": "15m",
"retry_attempts": 3,
"timeout": 5000
},
"nfllake": {
"api_base_url": "https://api.nfllake.com/v1/",
"api_key": "${{ secrets.NFLLAKE_API_KEY }}",
"update_interval": "15m",
"retry_attempts": 3,
"timeout": 5000
},
"logging": {
"level": "INFO",
"file": "/var/log/sportsradar_sync.log"
}
}
backend-container/src/sportsradar/__init__.py
Initialize the necessary components and configurations for handling the new data feeds from SportsRadar and NFLLAKE.
import os
import logging
from sportsradar.extract import initialize_sportsradar_client, initialize_nfllake_client
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
SPORTSRADAR_API_KEY = os.getenv('SPORTSRADAR_API_KEY')
NFLLAKE_API_KEY = os.getenv('NFLLAKE_API_KEY')
if not SPORTSRADAR_API_KEY or not NFLLAKE_API_KEY:
logger.error("API keys for SportsRadar or NFLLAKE are not set.")
raise EnvironmentError("API keys for SportsRadar or NFLLAKE are not set.")
sportsradar_client = initialize_sportsradar_client(SPORTSRADAR_API_KEY)
nfllake_client = initialize_nfllake_client(NFLLAKE_API_KEY)
logger.info("SportsRadar and NFLLAKE clients initialized successfully.")
backend-container/src/sportsradar/http_endpoints/config.json
Create and update the configuration to include settings for the new data feeds from SportsRadar and NFLLAKE.
{
"sportsradar": {
"api_base_url": "https://api.sportradar.com/nfl/official/trial/v6/en/",
"api_key": "${SPORTSRADAR_API_KEY}",
"endpoints": {
"player_feed": "players/{player_id}/profile.json",
"game_feed": "games/{game_id}/summary.json",
"team_feed": "teams/{team_id}/profile.json",
"additional_feed": "seasons/{season_id}/standings.json"
}
},
"nfllake": {
"api_base_url": "https://api.nfllake.com/v1/",
"api_key": "${NFLLAKE_API_KEY}",
"endpoints": {
"player_feed": "players/{player_id}/stats",
"game_feed": "games/{game_id}/details",
"team_feed": "teams/{team_id}/stats",
"additional_feed": "seasons/{season_id}/rankings"
}
}
}
backend-container/src/sportsradar/transform/__init__.py
Ensure the transformation module can handle the new data feeds and integrate them properly.
from .playerfeeds import transform_player_data
from .gamefeeds import transform_game_data
from .teamfeeds import transform_team_data
from .additionalfeeds import transform_additional_data
def initialize_transformation_module():
pass
initialize_transformation_module()
backend-container/src/sportsradar/graphql/config.json
Create and update the configuration to include settings for the new data feeds from SportsRadar and NFLLAKE.
{
"sportsradar": {
"api_key": "YOUR_SPORTSRADAR_API_KEY",
"base_url": "https://api.sportradar.com/nfl/official/trial/v6/en/",
"endpoints": {
"player_feed": "players/{player_id}/profile.json",
"game_feed": "games/{game_id}/summary.json",
"team_feed": "teams/{team_id}/profile.json",
"additional_feed": "additional_endpoint/{param}.json"
}
},
"nfllake": {
"api_key": "YOUR_NFLLAKE_API_KEY",
"base_url": "https://api.nfllake.com/v1/",
"endpoints": {
"player_feed": "players/{player_id}/data",
"game_feed": "games/{game_id}/data",
"team_feed": "teams/{team_id}/data",
"additional_feed": "additional_endpoint/{param}"
}
}
}
backend-container/src/sportsradar/simulation/session.py
Ensure the session management can handle the new data feeds from SportsRadar and NFLLAKE.
import requests
from src.sportsradar.simulation.config import Config
from src.sportsradar.logging_helpers import log_error, log_info
def create_session(url: str, recording_id: str, data_feed: str):
headers = {
"Content-Type": f"application/{Config.CONTENT_TYPE}",
"Data-Feed": data_feed
}
json_data = {
"query": "mutation CreateSession($input: CreateSessionInput!) {\n createSession(input: $input)\n }",
"variables": {
"input": {
"recordingId": recording_id,
"dataFeed": data_feed
},
},
}
try:
response = requests.post(url, headers=headers, json=json_data, timeout=60)
response.raise_for_status()
log_info(f"Session created successfully for recording ID {recording_id} with data feed {data_feed}")
except requests.RequestException as e:
log_error(f"Request failed with {e}")
return None
return response
backend-container/src/sportsradar/transform/teamfeeds.py
Update the transformation logic to include the new data feeds from SportsRadar and NFLLAKE.
from src.sportsradar import logging_helpers
logger = logging_helpers.get_logger(__name__)
class TeamFeedsTransformer:
UNWANTED_KEYS = ["_comment"]
def __init__(self, data: dict):
self.data = data
def _remove_unwanted_feeds(self):
for key in self.UNWANTED_KEYS:
if key in self.data:
self.data.pop(key)
def transform_team_roster(self):
self._remove_unwanted_feeds()
return self.data
def transform_seasonal_statistics(self):
self._remove_unwanted_feeds()
return self.data
def transform_team_profile(self):
self._remove_unwanted_feeds()
return self.data
def transform_new_data_feed(self):
self._remove_unwanted_feeds()
return self.data
backend-container/src/sportsradar/functions/config.json
Create a new configuration file that includes settings for the new data feeds from SportsRadar and NFLLAKE.
{
"data_feeds": {
"sportsradar": {
"api_key": "SPORTSRADAR_API_KEY",
"base_url": "https://api.sportradar.com",
"endpoints": {
"player_feeds": "/nfl/official/trial/v6/en/players/{player_id}/profile.json",
"game_feeds": "/nfl/official/trial/v6/en/games/{game_id}/summary.json",
"team_feeds": "/nfl/official/trial/v6/en/teams/{team_id}/profile.json",
"additional_feeds": "/nfl/official/trial/v6/en/{additional_feed}.json"
}
},
"nfllake": {
"api_key": "NFLLAKE_API_KEY",
"base_url": "https://api.nfllake.com",
"endpoints": {
"player_feeds": "/v1/players/{player_id}",
"game_feeds": "/v1/games/{game_id}",
"team_feeds": "/v1/teams/{team_id}",
"additional_feeds": "/v1/{additional_feed}"
}
}
}
}
backend-container/src/sportsradar/logging_helpers.py
Update the logging to include the new data feeds and ensure proper logging of any issues.
import logging
import coloredlogs
def get_logger(name: str):
return logging.getLogger(f"sportsradar.{name}")
def configure_root_logger(logfile: str | None = None, loglevel: str = "INFO"):
logger = logging.getLogger("sportsradar")
log_format = "%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s"
coloredlogs.install(fmt=log_format, level=loglevel, logger=logger)
logger.addHandler(logging.NullHandler())
if logfile is not None:
file_logger = logging.FileHandler(logfile)
file_logger.setFormatter(logging.Formatter(log_format))
logger.addHandler(file_logger)
configure_feed_logger("sportsradar.sportsradar_feed", loglevel)
configure_feed_logger("sportsradar.nfllake_feed", loglevel)
def configure_feed_logger(feed_name: str, loglevel: str):
feed_logger = logging.getLogger(feed_name)
log_format = "%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s"
coloredlogs.install(fmt=log_format, level=loglevel, logger=feed_logger)
feed_logger.addHandler(logging.NullHandler())
backend-container/src/sportsradar/transform/playerfeeds.py
Update the transformation logic to include the new data feeds from SportsRadar and NFLLAKE.
from src.sportsradar import logging_helpers
logger = logging_helpers.get_logger(__name__)
class PlayerFeedsTransformer:
UNWANTED_KEYS = ["_comment"]
def __init__(self, data: dict):
self.data = data
def _remove_unwanted_feeds(self):
for key in self.UNWANTED_KEYS:
if key in self.data:
self.data.pop(key)
def transform_player_profile(self
[Click here to create a Pull Request with the proposed solution](https://api.codeautopilot.com/create-pr?task=29597&hash=13eb54af1691a10b0fd48570bdf7d34f544f5d90d5d776d8dee43e8ec08b85a0)
**Files used for this task:**
<details>
<summary>Changes on backend-container/src/sportsradar/simulation/config.py</summary>
To update the configuration in `backend-container/src/sportsradar/simulation/config.py` to include settings for the new data feeds from SportsRadar and NFLLAKE, you should add new configuration parameters that will handle the new API keys and any other necessary settings. Here is a practical proposal for updating this file:
1. **Load Environment Variables**: Ensure that the new API keys are loaded from the environment variables.
2. **Add New Configuration Parameters**: Add new class attributes to store the API keys and any other relevant settings.
Here is the updated code:
```python
import os
from dotenv import load_dotenv
load_dotenv("../../../.env")
class Config:
"""Class to handle configuration settings"""
BASE_URL = "https://playback.sportradar.com"
CONTENT_TYPE = "json"
LEAGUE = "nfl"
# Load API keys from environment variables
SPORTSRADAR_API_KEY = os.environ.get('SPORTSRADAR_API_KEY')
NFLLAKE_API_KEY = os.environ.get('NFLLAKE_API_KEY')
# Example of additional settings that might be needed
SPORTSRADAR_BASE_URL = "https://api.sportradar.com"
NFLLAKE_BASE_URL = "https://api.nfllake.com"
#MONGODB_URL = f"{os.environ.get('MONGODB_URL')}"
SPORTSRADAR_API_KEY
and NFLLAKE_API_KEY
are added to your environment variables or .env
file.SPORTSRADAR_API_KEY
and NFLLAKE_API_KEY
.This update ensures that the configuration file is prepared to handle the new data feeds by including the necessary API keys and any additional settings required for integration.
○ Time: 2 weeks ○ Details Needed: Partnership agreements with SportsRadar ○ Tasks:
Partner with NFL Data Providers
Description: Establish partnerships with SportsRadar, and NFLLAKE for continuous data feeds. Tasks:
SPORTSRADAR_API_KEY
,NFLLAKE_API_KEY
.