Example #1
0
    def set_weapon_accuracy(self):
        def parse_pct(pct):
            if isinstance(pct, int):
                return pct
            return eval(pct.split("%")[0]) / 100.

        heroes = self.hero_crawler("Combat", "Weapon Accuracy", evl=False)
        wpn_acc = HerosStats(
            "Combat: Weapon Accuracy",
            map(lambda hero: (hero.name, parse_pct(str(hero.value))), heroes))
        logging.debug("%s: %s" % (wpn_acc.stat_name, wpn_acc))
        self.wpn_acc = wpn_acc
Example #2
0
    def set_total_dmg(self):
        def remove_commas(seq):
            if isinstance(seq, int):
                return seq
            return eval("".join(seq.split(",")))

        heroes = self.hero_crawler("Combat", "All Damage Done", evl=False)
        total_dmg = HerosStats(
            "Combat: Damage Done",
            map(lambda hero: (hero.name, remove_commas(str(hero.value))),
                heroes))
        logging.debug("%s: %s" % (total_dmg.stat_name, total_dmg))
        self.total_dmg = total_dmg
Example #3
0
        def get_top_three(col):
            """
            Finds the top 3 heros in the stat specified by `col`. 
            Only looks for heros that have more than 5 games played. 

            :param col: The stat to reference
            :type col: str
            """
            top_stat = df[df['Games Played'] > 5][col].nlargest(3)
            logging.info("\n%s" % top_stat)
            top_stat_hs = HerosStats(col, zip(top_stat.index, top_stat))
            logging.debug("%s (Top 3): %s" %
                          (top_stat_hs.stat_name, top_stat_hs))
            return top_stat_hs
Example #4
0
        def data_packer(total_stat, mins_played):
            """
            This helper function serves to calculate a stat per minute, given by `total_stat`.

            :param total_stat: The HerosStats instance to calculate per minute on
            :param mis_played: The HeroStats instance of minutes played
            :type total_stat: HerosStats
            :type total_stat: HerosStats
            :returns: HerosStats 
            """
            logging.debug("...Data Packing stat: %s" % (total_stat.stat_name))
            stat_min = np.array(total_stat.values) / np.array(
                mins_played.values)
            stat_min_hs = HerosStats(total_stat.stat_name + "/Minute",
                                     zip(total_stat.values, stat_min))
            return stat_min_hs
Example #5
0
    def hero_crawler(self, cat, subcat, evl=True):
        """
        This method is intended to be used whenever data is requested in such 
        a way where a mapping is directly accomplished by response indexing.
        Populates a list of heros mapping heros to data, in this specified
        by the parameters. 

        Example return:

        >>> self.set_avg_elims()
        >>> [(u'Pharah', 23.13), (u'McCree', 22.38), (u'Widowmaker', 22.31)]

        .. note:: Need to subclass a sort of hero data class to better repr this data type. 

        Something like... when printed of course.
        HeroDataBin(stat=Average Eliminations Per Game, data=[(u'Pharah', 23.13), (u'McCree', 22.38), (u'Widowmaker', 22.31)])

        :param cat: The 'parent' category of the data, e.g. "Average" or "Game"
        :param subcat: The subcategory corresponging to param cat.
                       e.g. if cat is "Best", subcat can be "All Damage Done - Most in Game".

        :returns: HerosStats object 

        """
        values = []
        for hero in self.heros:

            try:
                val = self.data[hero][cat][subcat]

                if evl:
                    values.append(eval(val))  # need to use eval() for strings
                else:
                    values.append(val)
            except:
                logging.warning("NO DATA FOR %s ON KEYS %s AND/OR %s" %
                                (hero, cat, subcat))
                values.append(1)

        stat_name = cat + ": " + subcat
        hs = HerosStats(stat_name, zip(self.heros, values))
        return hs
Example #6
0
    def set_minutes_played(self):
        def strtime_eval(time_str):

            if "second" in time_str:
                return 1
            if time_str == "--":
                return 1
            assert "hour" in time_str or "minute" in time_str, "malformed input: '" + time_str + "'"
            split = time_str.split(" ")
            rawnum = eval(split[0])

            if "hour" in split[1]:
                time = rawnum * 60
            elif "minute" in split[1]:
                time = rawnum
            return float(time)

        mins_played = HerosStats(
            "Game: Time Played",
            map(lambda hero: (hero.name, strtime_eval(hero.value)),
                self.hero_crawler("Game", "Time Played", evl=False)))
        logging.debug("%s: %s" % (mins_played.stat_name, mins_played))
        self.mins_played = mins_played
Example #7
0
    def make_summary_table(self):
        """
        Summary will correspond to top 3 played heros in variety of stats.

        elims/min?
        deaths/min?
        dmg/min?
        solokills/min?
        weapon acc?
        winrate? 
        most dmg ingame?
        avg time on fire?
         
        """
        def data_packer(total_stat, mins_played):
            """
            This helper function serves to calculate a stat per minute, given by `total_stat`.

            :param total_stat: The HerosStats instance to calculate per minute on
            :param mis_played: The HeroStats instance of minutes played
            :type total_stat: HerosStats
            :type total_stat: HerosStats
            :returns: HerosStats 
            """
            logging.debug("...Data Packing stat: %s" % (total_stat.stat_name))
            stat_min = np.array(total_stat.values) / np.array(
                mins_played.values)
            stat_min_hs = HerosStats(total_stat.stat_name + "/Minute",
                                     zip(total_stat.values, stat_min))
            return stat_min_hs

        def get_top_three(col):
            """
            Finds the top 3 heros in the stat specified by `col`. 
            Only looks for heros that have more than 5 games played. 

            :param col: The stat to reference
            :type col: str
            """
            top_stat = df[df['Games Played'] > 5][col].nlargest(3)
            logging.info("\n%s" % top_stat)
            top_stat_hs = HerosStats(col, zip(top_stat.index, top_stat))
            logging.debug("%s (Top 3): %s" %
                          (top_stat_hs.stat_name, top_stat_hs))
            return top_stat_hs

        elims_min_hs = data_packer(self.total_elims, self.mins_played)
        deaths_min_hs = data_packer(self.total_deaths, self.mins_played)
        dmg_min_hs = data_packer(self.total_dmg, self.mins_played)
        solo_kills_hs = data_packer(self.total_solo_kills, self.mins_played)

        wpn_acc = self.wpn_acc
        games_played = self.games_played

        data = {
            "Elims/Min": elims_min_hs.values,
            "Deaths/Min": deaths_min_hs.values,
            "Dmg/Min": dmg_min_hs.values,
            "SoloKills/Min": solo_kills_hs.values,
            "Weapon Accuracy": wpn_acc.values,
            "Games Played": games_played.values
        }

        df = pd.DataFrame(data=data, index=self.heros)

        logging.info("\n%s" % df)

        self.elimspm = HerosStats("Elims/Min", zip(df.index, df['Elims/Min']))
        self.deathspm = HerosStats("Deaths/Min", zip(df.index,
                                                     df['Deaths/Min']))
        self.dmgpm = HerosStats("Dmg/Min", zip(df.index, df['Dmg/Min']))
        self.solokills = HerosStats("SoloKills/Min",
                                    zip(df.index, df['SoloKills/Min']))
        logging.debug("\n%s" % self.elimspm)
        logging.debug("\n%s" % self.deathspm)
        logging.debug("\n%s" % self.dmgpm)
        logging.debug("\n%s" % self.solokills)

        self.top_elimspm = get_top_three('Elims/Min')
        self.top_deathspm = get_top_three('Deaths/Min')
        self.top_dmgs = get_top_three('Dmg/Min')
        self.top_solokills = get_top_three('SoloKills/Min')
        self.top_wpnacc = get_top_three('Weapon Accuracy')
        self.top_played = get_top_three('Games Played')