Player
PlayerDataSchema
Bases: DataFrameModel
A panderas.DataFrameModel for player information.
Provider-specific player identifier fields are added before validation during PlayerSyncableContent.validate_data_schema().
Source code in src/glass_onion/player.py
birth_date = Field(nullable=True)
class-attribute
instance-attribute
The player's date of birth. Preferably in YYYY-MM-DD format, but required to be in a date format that can be parsed by pandas.Timestamp. If null/NA values are provided, this column will be ignored in synchronization.
jersey_number = Field(nullable=True, coerce=True)
class-attribute
instance-attribute
The player's jersey number. If null/NA values are provided, this column will be ignored in synchronization.
player_name = Field(nullable=False)
class-attribute
instance-attribute
The name of the player. In general, this should be the full (or legal) name of the player provided by the provider.
player_nickname = Field(nullable=True)
class-attribute
instance-attribute
The nickname of the player. In general, this should be the common/public name or a shorthand for the player.
team_id = Field(nullable=False, coerce=True)
class-attribute
instance-attribute
The player's team's identifier. This is assumed to be universally unique across the MatchSyncableContent objects provided to MatchSyncEngine.
PlayerSyncEngine
Bases: SyncEngine
A subclass of SyncEngine to use for player objects.
See synchronize_pair()[glass_onion.player.PlayerSyncEngine.synchronize_pair] for methodology details.
Source code in src/glass_onion/player.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
__init__(content, verbose=False)
Creates a new PlayerSyncEngine object.
Unlike other SyncEngine subclasses, this subclass does not accept any explicit join_columns. Player synchronization is a more finicky task than team or match synchronization, and as a result, the columns used in synchronization have to be checked for null values and validity before synchronization can be attempted.
For example, the base set of columns is ["jersey_number", "team_id", "player_name"], but since some providers may not provide a player's jersey number, we remove this column so that the logic in SyncEngine.synchronize() does not use it to group, aggregate, and deduplicate results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
list[str]
|
a list of SyncableContent objects. |
required |
verbose
|
bool
|
a flag to verbose logging. This will be |
False
|
Source code in src/glass_onion/player.py
synchronize_pair(input1, input2)
Synchronizes two PlayerSyncableContent objects.
Methodology
- Attempt to join pair using
player_namewith a minimum 75% cosine similarity threshold for player name. Additionally, require thatjersey_numberandteam_idare equal for matches that meet the similarity threshold. - Account for players with different birth dates across data providers (timezones, human error, etc) by adjusting
birth_datein one dataset in the pair by -1 to 1 days and/or swapping the month and day, then attempting synchronization usingbirth_date,team_id, and a combination ofplayer_nameandplayer_nickname. This process is then repeated for the other dataset in the pair. - Attempt to join remaining records using combinations of
player_nameandplayer_nicknamewith a minimum 75% cosine similarity threshold for player name. Additionally, require thatteam_idis equal for matches that meet the similarity threshold. - Attempt to join remaining records using "naive similarity": looking for normalized parts of one record's
player name(orplayer_nickname) that exist in another's. Additionally, require thatteam_idis equal for matches found via this method. - Attempt to join remaining records using combinations of
player_nameandplayer_nicknamewith no minimum cosine similarity threshold. Additionally, require thatteam_idis equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input1
|
SyncableContent
|
a PlayerSyncableContent object from |
required |
input2
|
SyncableContent
|
a PlayerSyncableContent object from |
required |
Returns:
| Type | Description |
|---|---|
SyncableContent
|
If |
SyncableContent
|
If |
SyncableContent
|
If both dataframes are non-empty, returns a new PlayerSyncableContent object with synchronized identifiers from |
Source code in src/glass_onion/player.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
synchronize_using_layer(input1, input2, layer)
Synchronizes two PlayerSyncableContent objects using options from layer and returns a pandas.DataFrame of synchronized identifiers.
This method also prevents the propagation of duplicate synchronized identifiers by ensuring that the resulting dataframe only contains identifiers that are only used once per input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input1
|
PlayerSyncableContent
|
a PlayerSyncableContent object. |
required |
input2
|
PlayerSyncableContent
|
a PlayerSyncableContent object. |
required |
layer
|
glass_onion.player.PlayerSyncLayer`
|
a PlayerSyncLayer` object. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: a |
Source code in src/glass_onion/player.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
PlayerSyncLayer
A helper class that encapsulates a set of synchronization options for player objects.
Source code in src/glass_onion/player.py
__init__(title, match_methodology=PlayerSyncSimilarityMethod.COSINE, date_adjustment=pd.Timedelta(0), swap_birth_month_day=False, input_fields=('player_name', 'player_name'), other_equal_fields=['birth_date', 'team_id'], threshold=0.75)
Creates a new synchronization layer object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
match_methodology
|
PlayerSyncSimilarityMethod
|
see PlayerSyncSimilarityMethod for options. |
COSINE
|
date_adjustment
|
Timedelta
|
a time period to adjust |
Timedelta(0)
|
swap_birth_month_day
|
bool
|
a flag for if this layer should swap birth day and month AFTER date adjustment. |
False
|
input_fields
|
Tuple[str, str]
|
a two-tuple containing the column names to use for player name similarity. Possible options for tuple values: |
('player_name', 'player_name')
|
other_equal_fields
|
list[str]
|
a list of columns that must be equal between the two PlayerSyncableContent datasets in order for an identifier to be synchronized validly. |
['birth_date', 'team_id']
|
threshold
|
float
|
the threshold to use for string similarity when match_methodology is PlayerSyncSimilarityMethod.COSINE |
0.75
|
Source code in src/glass_onion/player.py
PlayerSyncSimilarityMethod
Bases: Enum
Used to calculate similarity between player name (or nickname) strings.
Source code in src/glass_onion/player.py
COSINE = 'cosine_similarity'
class-attribute
instance-attribute
Use cosine similarity via synchronize_with_cosine_similarity. The methodology is explained at https://unravelsports.com/post.html?id=2022-07-11-player-id-matching-system.
FUZZY = 'fuzzy'
class-attribute
instance-attribute
Use fuzzy similarity via synchronize_with_fuzzy_match, which is a wrapper around thefuzz.process().
NAIVE = 'naive'
class-attribute
instance-attribute
Use 'naive' similarity via synchronize_with_naive_match. TL;DR: split the two player name strings on spaces into sets and consider the intersection of the two sets.
PlayerSyncableContent
Bases: SyncableContent
A subclass of SyncableContent to use for player objects.
Source code in src/glass_onion/player.py
validate_data_schema()
Checks if this object's data meets the schema requirements for this object type. See PlayerDataSchema for more details.
Raises:
| Type | Description |
|---|---|
SchemaError
|
if |
Returns:
| Type | Description |
|---|---|
bool
|
True, if |