Skip to content
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

Fix PlayerUsageUsage validation for string inputs and hireDate null value handling for coaches #14

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

AjJ132
Copy link

@AjJ132 AjJ132 commented Oct 14, 2024

Fixes Issue #13 and #15

Problem

The PlayerUsageUsage class was failing to validate inputs when the API returned numeric values as strings.

Solution

Added a validator to convert string inputs to floats, allowing the model to handle both string and numeric inputs. This makes the PlayerUsageUsage class more robust and able to handle different input formats without breaking.

Changes

  • Added a @validator decorator to convert string inputs to floats

Testing

Tested with test files in ./test folder

Backwards Compatibility

This change maintains backwards compatibility as it will still work with numeric inputs.


Fix hireDate parsing in Coach model

Changes

Modified the hire_date field in the Coach model to be an optional string.

File changed: models/coach.py

This PR addresses the issue with parsing the hireDate field in the Coach model. It changes the field to an optional string to avoid validation errors with null or improperly formatted dates.

from typing import Optional
from pydantic import BaseModel, Field

class Coach(BaseModel):
    first_name: str = Field(..., alias="firstName")
    last_name: str = Field(..., alias="lastName")
    hire_date: Optional[str] = Field(default=None, alias="hireDate")
    # ... other fields remain unchanged ...

    class Config:
        allow_population_by_field_name = True

# ... rest of the file remains unchanged ...

Testing

Tested with test files in ./test folder

@AjJ132
Copy link
Author

AjJ132 commented Oct 14, 2024

Please feel free to edit my changes if needed. Love the work so far!!

@AjJ132 AjJ132 changed the title Fix PlayerUsageUsage validation for string inputs Fix PlayerUsageUsage validation for string inputs and hireDate null value handling for coaches Oct 14, 2024
@AjJ132
Copy link
Author

AjJ132 commented Oct 14, 2024

I found another issue with parsing the coaches hireDate. Some coaches have a null hireDate. Example below

[
  {
    "firstName": "Steve",
    "lastName": "Addazio",
    "hireDate": null,
    "seasons": [
      {
        "school": "Temple",
        "year": 2011,
        "games": 13,
        "wins": 9,
        "losses": 4,
        "ties": 0,
        "preseasonRank": null,
        "postseasonRank": null,
        "srs": 5.4,
        "spOverall": 4.6,
        "spOffense": 26.4,
        "spDefense": 22.5
      },
      ..................
    ]
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant