Fuyukai / OWAPI

Overwatch JSON API
https://owapi.net
MIT License
456 stars 74 forks source link

Hero-specific stats merged into general_stats #282

Closed EndBug closed 5 years ago

EndBug commented 5 years ago

Issue

Just noticed that the stats that previously were in hero_stast are now displayed in general_stats, while hero_stats is just an empty object. At the moment hero-specific stats are still shown on the Overwatch website in a separate category: maybe they changed the page and the API doesn't manage to recognize them as hero-specific? Is it by design? @Fuyukai

Links that cause the issue

(Surround the links with backticks. Use triple backticks for multiple lines.)

https://owapi.net/api/v3/u/Kharumaan-2976/blob

E.g.: this is how heroes.stats.competitive.brigitte looks like:

"average_stats": {},
"general_stats": {
  ...
  "armor_provided": 1190.0,
  "armor_provided_most_in_game": 1190.0,
  "barrier_damage_done": 35.0,
  "barrier_damage_done_most_in_game": 35.0,
  "damage_blocked": 2526.0,
  "damage_blocked_most_in_game": 2526.0,
  "inspire_uptime_percentage": 0.46,
  ...
},
"hero_stats": {}, // This is empty!
"rolling_average_stats": {
  ...
}
zerefel commented 5 years ago

Did you solve this?

EndBug commented 5 years ago

Nope, they're still merged.

zerefel commented 5 years ago

After a lot of digging, learning the basics of python and trial and error, I managed to fix it. The problem seems to come from the assumption OWAPI made that hero specific stats will always be the first DOM element to come, but apparently Blizzard changed it.

In parsing.py, This is the new code around line 460:

        for idx, sg in enumerate(stat_groups):
            sg_name = stat_groups[idx].find('.//*[@class="stat-title"]').text

            if sg_name == "Hero Specific":
                try:
                    hero_specific_box = stat_groups[idx]
                    trs = hero_specific_box.findall(".//tbody/tr")

                    # Update the dict with [0]: [1]
                    for subval in trs:
                        name, value = util.sanitize_string(subval[0].text), subval[1].text

                        # Put averages into average_stats
                        if "average" in name:
                            into = _average_stats
                        elif '_avg_per_10_min' in name.lower():
                            name = name.lower().replace("_avg_per_10_min", "")
                            into = _rolling_avgs
                        else:
                            into = _t_d
                        nvl = util.try_extract(value)
                        into[name] = nvl
                    break
                except IndexError:
                    pass

Now, the stats are still merged in general_stats, however this is a simple fix to get rid of them.

EndBug commented 5 years ago

It would be fantastic if you could open a PR with those changes so that the author can merge them into the repo :)

jp1337 commented 5 years ago

This should be fixed in Commit 5d2fb53be0f246ad7ecbc0a39eafb050209f242a. Can you vertify this and share the results in the issue?

EndBug commented 5 years ago

Closed by #290 The hero-specific stats are now back in their section 👍 Thanks to everyone that worked to this issue 🎉