-
Notifications
You must be signed in to change notification settings - Fork 112
Fix: Incomplete player stats due to header and data mismatch in stats parser #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Incomplete player stats due to header and data mismatch in stats parser #108
Conversation
WalkthroughThree new optional integer fields— Changes
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
app/schemas/players/stats.py (1)
24-24: Missing trailing newline at end of fileAccording to the static analysis hint, there should be a newline at the end of the file.
class PlayerStats(TransfermarktBaseModel, AuditMixin): id: str - stats: list[PlayerStat] + stats: list[PlayerStat] +🧰 Tools
🪛 Ruff (0.8.2)
24-24: No newline at end of file
Add trailing newline
(W292)
app/schemas/base.py (1)
93-93: Missing trailing newline at end of fileThe static analysis tool has identified that there's no newline at the end of the file. This should be added to comply with PEP 8 standards.
@field_validator("days", mode="before", check_fields=False) def parse_days(cls, v: str) -> Optional[int]: days = "".join(filter(str.isdigit, v)) - return int(days) if days else None + return int(days) if days else None +🧰 Tools
🪛 Ruff (0.8.2)
93-93: No newline at end of file
Add trailing newline
(W292)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
app/schemas/base.py(2 hunks)app/schemas/players/stats.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/schemas/players/stats.py (1)
app/schemas/base.py (2)
TransfermarktBaseModel(14-93)AuditMixin(10-11)
🪛 Ruff (0.8.2)
app/schemas/players/stats.py
24-24: No newline at end of file
Add trailing newline
(W292)
app/schemas/base.py
93-93: No newline at end of file
Add trailing newline
(W292)
🔇 Additional comments (2)
app/schemas/players/stats.py (1)
15-15: Added the missing player statistics fieldsThese new fields align with the PR objective to fix the missing statistics. The fields
second_yellow_cards,goals_conceded, andclean_sheetsare now properly added to thePlayerStatmodel with appropriate defaults.Also applies to: 17-18
app/schemas/base.py (1)
49-52: Validator updated to handle the new fieldsThe
parse_str_to_intvalidator has been correctly updated to include the three new fields added to thePlayerStatmodel:second_yellow_cards,goals_conceded, andclean_sheets. This ensures that string representations of these values will be properly parsed into integers.
This PR resolves an issue in the
/players/{player_id}/statsendpoint where certain player statistics fields—specificallygoalsConceded,cleanSheets, andsecondYellowCards—were missing from the returned data despite being present on the Transfermarkt page.Root Cause
In
TransfermarktPlayerStats.__parse_player_stats(inservices/stats.py), the list of extractedheadersalways included all potential stat fields, but the actualstatsrows extracted from the DOM could vary in length depending on the player's position or available data (e.g., goalkeepers havegoalsConcededwhile outfield players may not).This mismatch caused the final zipped dictionaries to omit trailing fields when the row length didn't match the header length.
Fix
Example of issue (before fix):
Resulted in:
Now, such rows are padded and aligned properly.
Summary by CodeRabbit