Skip to content

Commit

Permalink
Fix state code confusion leading to wrong states being assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
joaorb64 committed Sep 10, 2024
1 parent 83ba40c commit d8e12f4
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
82 changes: 81 additions & 1 deletion assets/characters.json
Original file line number Diff line number Diff line change
Expand Up @@ -110937,6 +110937,84 @@
],
"characterId": null,
"expand": []
},
{
"id": 2581,
"name": "Perilla",
"isCommon": null,
"videogameId": 48268,
"externalIdMap": null,
"images": [
{
"id": 7349959,
"width": 512,
"height": 512,
"ratio": 1,
"type": "icon",
"url": "https://images.start.gg/images/character/2581/image-f9458e5c35dbb7db88ec55e31c42f006.png?ehk=RJjYUbaEETmf3lw1UbgduN7PyvzPVPylAPEsZUhFhvI%3D&ehkOptimized=KMvtKwC86WJzgTEvpxFSjqsy7hMhaXqjPoh4g7Rcx4Q%3D",
"isOriginal": true,
"entity": null,
"entityId": null,
"uploadedBy": null,
"createdAt": null,
"updatedAt": null
},
{
"id": 7349960,
"width": 512,
"height": 512,
"ratio": 1,
"type": "stockIcon",
"url": "https://images.start.gg/images/character/2581/image-0c49091c1ec2cc340a584bfa1d835150.png?ehk=fkdEUu1ILcaJbP%2FQ4DG6jt0kJ4v%2FRKDTovyUvSiSfEk%3D&ehkOptimized=qIzc5GHNCDDweKCN379BSIzi784Unieji65Na6qF%2Fvk%3D",
"isOriginal": true,
"entity": null,
"entityId": null,
"uploadedBy": null,
"createdAt": null,
"updatedAt": null
}
],
"characterId": null,
"expand": []
},
{
"id": 2582,
"name": "Terrable",
"isCommon": null,
"videogameId": 48268,
"externalIdMap": null,
"images": [
{
"id": 7349962,
"width": 512,
"height": 512,
"ratio": 1,
"type": "icon",
"url": "https://images.start.gg/images/character/2582/image-60e9b88b9235c9b93a55b015134b5f3e.png?ehk=cC5fOPgQ7dC7Rcau8I0Vq%2FJ9P0UKHjlyVBq%2FugdjO40%3D&ehkOptimized=a5rWHbPZEfWJt%2BoNODYOzjx34XcUOZfXFAI8BP5IiZ4%3D",
"isOriginal": true,
"entity": null,
"entityId": null,
"uploadedBy": null,
"createdAt": null,
"updatedAt": null
},
{
"id": 7349963,
"width": 512,
"height": 512,
"ratio": 1,
"type": "stockIcon",
"url": "https://images.start.gg/images/character/2582/image-51d68859a4150c3bc281d44ef91e4d9a.png?ehk=5lWccokqSHoFftnN9Zo%2F%2Bk%2FWFeqQz8XAIEFwsowEaO0%3D&ehkOptimized=G2bw%2BHH%2BjZDNFRluFMTl4kYunmOvIQAaK2L52dyJ8I0%3D",
"isOriginal": true,
"entity": null,
"entityId": null,
"uploadedBy": null,
"createdAt": null,
"updatedAt": null
}
],
"characterId": null,
"expand": []
}
]
},
Expand Down Expand Up @@ -113278,7 +113356,9 @@
2577,
2578,
2579,
2580
2580,
2581,
2582
],
"resultEntity": "character",
"actionRecords": []
Expand Down
11 changes: 9 additions & 2 deletions src/Helpers/TSHCountryHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ def LoadCountries():

for s in c.get("states", []):
scode = s.get("state_code") if not s.get("state_code").isdigit() else "".join([
word[0] for word in re.split(r'\s+|-', s.get("name")) if len(word) > 0])
word[0] for word in re.split(r'\s+|-', s.get("name").strip()) if len(word) > 0])

TSHCountryHelper.countries[c["iso2"]]["states"][s["state_code"]] = {
"name": s.get("name"),
"code": scode,
"original_code": s.get("state_code"),
"latitude": s.get("latitude"),
"longitude": s.get("longitude"),
}
Expand Down Expand Up @@ -209,6 +210,8 @@ def FindState(countryCode, city):
# Normalize parts of city string
split = city.replace(" - ", ",").split(",")

logger.debug(f"Finding State from city string [{city}]")

for part in split[::-1]:
part = part.strip()

Expand All @@ -224,7 +227,9 @@ def FindState(countryCode, city):
None
)
if state is not None:
return state["code"]
logger.debug(f"State was explicit: [{
city}] -> [{part}] = {state}")
return state["original_code"]

# No, so get by City
for part in split[::-1]:
Expand All @@ -234,6 +239,8 @@ def FindState(countryCode, city):
TSHCountryHelper.remove_accents_lower(part), None)

if state is not None:
logger.debug(f"Got state from city name: [{
city}] -> [{part}] = {state}")
return state

return None
Expand Down
10 changes: 6 additions & 4 deletions src/TSHScoreboardPlayerWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ def LoadStates(self, index):
item = QStandardItem()
# Windows has some weird thing with files named CON.png. In case a state code is CON,
# we try to load _CON.png instead
path = f'./assets/state_flag/{countryData.get("code")}/{"_CON" if state_code == "CON" else state_code}.png'
path = f'./assets/state_flag/{countryData.get(
"code")}/{"_CON" if state_code == "CON" else state_code}.png'

if not os.path.exists(path):
path = None
Expand Down Expand Up @@ -599,7 +600,8 @@ def SetData(self, data, dontLoadFromDB=False, clear=True, no_mains=False):
"prefix")+" "+item.get("gamerTag") if item.get("prefix") else item.get("gamerTag")

if tag == dbTag:
self.SetData(item, dontLoadFromDB=True, clear=False, no_mains=no_mains)
self.SetData(item, dontLoadFromDB=True,
clear=False, no_mains=no_mains)
break

name = self.findChild(QWidget, "name")
Expand Down Expand Up @@ -670,7 +672,7 @@ def SetData(self, data, dontLoadFromDB=False, clear=True, no_mains=False):
for i in range(stateElement.model().rowCount()):
item = stateElement.model().item(i).data(Qt.ItemDataRole.UserRole)
if item:
if data.get("state_code") == item.get("code"):
if data.get("state_code") == item.get("original_code"):
stateIndex = i
break
if stateElement.currentIndex() != stateIndex:
Expand Down Expand Up @@ -807,7 +809,7 @@ def Clear(self, no_mains=False):
c.editingFinished.emit()

for c in self.findChildren(QComboBox):
if(no_mains):
if (no_mains):
for charelem in self.character_elements:
for i in range(len(charelem)):
if charelem[i] == c:
Expand Down

0 comments on commit d8e12f4

Please sign in to comment.