Skip to content

Commit

Permalink
fix: Replace invalid getplayerinfo zero values for map stats prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Aug 23, 2024
1 parent afdb14e commit bba42ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
10 changes: 7 additions & 3 deletions aspxstats/bf2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,15 @@ def fix_getplayerinfo_zero_values(parsed: dict) -> dict:
vmrs (top opponent rank)
BF2Hub handles it better in most cases, but also has players with an empty string mvrs/vmrs or even more
interesting values such as "NOT VAILABLE" for tvcr (pid 10226681 asof 1617839795)
They also frequently return "NOT VAILABLE" for map stats values (pid 7568965 asof 1175020033)
=> replace any invalid values with 0 (but don't add it if the key is missing)
"""
for key in ['tvcr', 'topr', 'mvrs', 'vmrs']:
value = parsed['data'].get(key)
if value is not None and not is_numeric(value):
keys = {'tvcr', 'topr', 'mvrs', 'vmrs'}
prefixes = {'mtm-', 'mwn-', 'mls-'}
for key, value in parsed['data'].items():
matches_key = key in keys
matches_prefix = key[:4] in prefixes
if (matches_key or matches_prefix) and not is_numeric(value):
parsed['data'][key] = '0'

return parsed
Expand Down
28 changes: 23 additions & 5 deletions test/bf2_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,21 @@ class FixGetplayerinfoTestCase:
'tvcr': '',
'topr': ' ',
'mvrs': 'NOT VAILABLE',
'vmrs': '0'
'vmrs': '_',
'mtm-0': '',
'mwn-0': ' ',
'mls-0': 'NOT VAILABLE'
}
},
expected={
'data': {
'tvcr': '0',
'topr': '0',
'mvrs': '0',
'vmrs': '0'
'vmrs': '0',
'mtm-0': '0',
'mwn-0': '0',
'mls-0': '0'
}
}
),
Expand All @@ -678,15 +684,21 @@ class FixGetplayerinfoTestCase:
'tvcr': '1000',
'topr': '2000',
'mvrs': '3000',
'vmrs': '4000'
'vmrs': '4000',
'mtm-0': '5000',
'mwn-0': '6000',
'mls-0': '7000'
}
},
expected={
'data': {
'tvcr': '1000',
'topr': '2000',
'mvrs': '3000',
'vmrs': '4000'
'vmrs': '4000',
'mtm-0': '5000',
'mwn-0': '6000',
'mls-0': '7000'
}
}
),
Expand All @@ -697,7 +709,10 @@ class FixGetplayerinfoTestCase:
'tvcr': '',
'topr': ' ',
'mvrs': 'NOT VAILABLE',
'vmrs': '0',
'vmrs': '_',
'mtm-0': '',
'mwn-0': ' ',
'mls-0': 'NOT VAILABLE',
'some-other-key': 'some-value'
},
'some-other-key': 'some-value'
Expand All @@ -708,6 +723,9 @@ class FixGetplayerinfoTestCase:
'topr': '0',
'mvrs': '0',
'vmrs': '0',
'mtm-0': '0',
'mwn-0': '0',
'mls-0': '0',
'some-other-key': 'some-value'
},
'some-other-key': 'some-value'
Expand Down

0 comments on commit bba42ec

Please sign in to comment.