Esempio n. 1
0
    def game_stats_mon(self):
        minutes_spawn = request.args.get('minutes_spawn', 10)

        # Spawn
        iv = []
        noniv = []
        sumg = []
        sumup = {}

        data = self._db_stats_reader.get_pokemon_count(minutes_spawn)
        for dat in data:
            if dat[2] == 1:
                iv.append([(self.utc2local(dat[0]) * 1000), dat[1]])
            else:
                noniv.append([(self.utc2local(dat[0]) * 1000), dat[1]])

            if (self.utc2local(dat[0]) * 1000) in sumup:
                sumup[(self.utc2local(dat[0]) * 1000)] += dat[1]
            else:
                sumup[(self.utc2local(dat[0]) * 1000)] = dat[1]

        for dat in sumup:
            sumg.append([dat, sumup[dat]])

        spawn = {'iv': iv, 'noniv': noniv, 'sum': sumg}

        # good_spawns avg
        good_spawns = []
        data = self._db_stats_reader.get_best_pokemon_spawns()
        if data is not None:
            for dat in data:
                mon = "%03d" % dat[1]
                monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_00.png'
                monName_raw = (get_raid_boss_cp(dat[1]))
                monName = i8ln(monName_raw['name'])
                if self._args.db_method == "rm":
                    lvl = calculate_mon_level(dat[6])
                else:
                    lvl = dat[6]
                good_spawns.append({
                    'id':
                    dat[1],
                    'iv':
                    round(calculate_iv(dat[3], dat[4], dat[5]), 0),
                    'lvl':
                    lvl,
                    'cp':
                    dat[7],
                    'img':
                    monPic,
                    'name':
                    monName,
                    'periode':
                    datetime.datetime.fromtimestamp(self.utc2local(
                        dat[2])).strftime(self._datetimeformat)
                })

        stats = {'spawn': spawn, 'good_spawns': good_spawns}
        return jsonify(stats)
Esempio n. 2
0
    def game_stats(self):
        minutes_usage = request.args.get('minutes_usage', 10)
        minutes_spawn = request.args.get('minutes_spawn', 10)

        data = self._db.statistics_get_location_info()
        location_info = []
        for dat in data:
            location_info.append({'worker': str(dat[0]), 'locations': str(dat[1]), 'locationsok': str(dat[2]),
                                  'locationsnok': str(dat[3]), 'ratio': str(dat[4]), })

        # empty scans
        data = self._db.statistics_get_all_empty_scanns()
        detection_empty = []
        for dat in data:
            detection_empty.append({'lat': str(dat[1]), 'lng': str(dat[2]), 'worker': str(dat[3]),
                                    'count': str(dat[0]), 'type': str(dat[4]), 'lastscan': str(dat[5]),
                                    'countsuccess': str(dat[6])})

        # statistics_get_detection_count
        data = self._db.statistics_get_detection_count(grouped=False)
        detection = []
        for dat in data:
            detection.append({'worker': str(dat[1]), 'mons': str(dat[2]), 'mons_iv': str(dat[3]),
                              'raids': str(dat[4]), 'quests': str(dat[5])})

        # Stop
        stop = []
        data = self._db.statistics_get_stop_quest()
        for dat in data:
            stop.append({'label': dat[0], 'data': dat[1]})

        # Quest
        quest: list = []
        quest_db = self._db.statistics_get_quests_count(1)
        for ts, count in quest_db:
            quest_raw = (ts * 1000, count)
            quest.append(quest_raw)

        # Usage
        insta = {}
        usage = []
        idx = 0
        usa = self._db.statistics_get_usage_count(minutes_usage)

        for dat in usa:
            if 'CPU-' + dat[4] not in insta:
                insta['CPU-' + dat[4]] = {}
                insta['CPU-' + dat[4]]["axis"] = 1
                insta['CPU-' + dat[4]]["data"] = []
            if 'MEM-' + dat[4] not in insta:
                insta['MEM-' + dat[4]] = {}
                insta['MEM-' + dat[4]]['axis'] = 2
                insta['MEM-' + dat[4]]["data"] = []
            if self._args.stat_gc:
                if 'CO-' + dat[4] not in insta:
                    insta['CO-' + dat[4]] = {}
                    insta['CO-' + dat[4]]['axis'] = 3
                    insta['CO-' + dat[4]]["data"] = []

            insta['CPU-' + dat[4]]['data'].append([dat[3] * 1000, dat[0]])
            insta['MEM-' + dat[4]]['data'].append([dat[3] * 1000, dat[1]])
            if self._args.stat_gc:
                insta['CO-' + dat[4]]['data'].append([dat[3] * 1000, dat[2]])

        for label in insta:
            usage.append(
                {'label': label, 'data': insta[label]['data'], 'yaxis': insta[label]['axis'], 'idx': idx})
            idx += 1

        # Gym
        gym = []
        data = self._db.statistics_get_gym_count()
        for dat in data:
            if dat[0] == 'WHITE':
                color = '#999999'
                text = 'Uncontested'
            elif dat[0] == 'BLUE':
                color = '#0051CF'
                text = 'Mystic'
            elif dat[0] == 'RED':
                color = '#FF260E'
                text = 'Valor'
            elif dat[0] == 'YELLOW':
                color = '#FECC23'
                text = 'Instinct'
            gym.append({'label': text, 'data': dat[1], 'color': color})

        # Spawn
        iv = []
        noniv = []
        sum = []
        sumup = {}

        data = self._db.statistics_get_pokemon_count(minutes_spawn)
        for dat in data:
            if dat[2] == 1:
                iv.append([(self.utc2local(dat[0]) * 1000), dat[1]])
            else:
                noniv.append([(self.utc2local(dat[0]) * 1000), dat[1]])

            if (self.utc2local(dat[0]) * 1000) in sumup:
                sumup[(self.utc2local(dat[0]) * 1000)] += dat[1]
            else:
                sumup[(self.utc2local(dat[0]) * 1000)] = dat[1]

        for dat in sumup:
            sum.append([dat, sumup[dat]])

        spawn = {'iv': iv, 'noniv': noniv, 'sum': sum}

        # good_spawns avg
        good_spawns = []
        data = self._db.get_best_pokemon_spawns()
        for dat in data:
            mon = "%03d" % dat[1]
            monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_00.png'
            monName_raw = (get_raid_boss_cp(dat[1]))
            monName = i8ln(monName_raw['name'])
            if self._args.db_method == "rm":
                lvl = calculate_mon_level(dat[6])
            else:
                lvl = dat[6]
            good_spawns.append({'id': dat[1], 'iv': round(calculate_iv(dat[3], dat[4], dat[5]), 0),
                                'lvl': lvl, 'cp': dat[7], 'img': monPic,
                                'name': monName,
                                'periode': datetime.datetime.fromtimestamp(dat[2]).strftime(self._datetimeformat)})

        stats = {'spawn': spawn, 'gym': gym, 'detection': detection, 'detection_empty': detection_empty,
                 'quest': quest, 'stop': stop, 'usage': usage, 'good_spawns': good_spawns,
                 'location_info': location_info}
        return jsonify(stats)
Esempio n. 3
0
    def __prepare_mon_data(self, mon_data):
        ret = []

        for mon in mon_data:
            if mon["pokemon_id"] in self.__IV_MON and (
                    mon["individual_attack"] is None
                    and mon["individual_defense"] is None
                    and mon["individual_stamina"] is None):
                # skipping this mon since IV has not been scanned yet
                continue

            mon_payload = {
                "encounter_id": mon["encounter_id"],
                "pokemon_id": mon["pokemon_id"],
                "spawnpoint_id": mon["spawnpoint_id"],
                "latitude": mon["latitude"],
                "longitude": mon["longitude"],
                "disappear_time": mon["disappear_time"],
                "verified": mon["spawn_verified"]
            }

            # get rarity
            pokemon_rarity = self.__rarity.rarity_by_id(
                pokemonid=mon["pokemon_id"])

            # used by RM
            if mon.get("cp_multiplier", None) is not None:
                mon_payload["cp_multiplier"] = mon["cp_multiplier"]
                mon_payload["pokemon_level"] = calculate_mon_level(
                    mon["cp_multiplier"])

            # used by Monocle
            if mon.get("level", None) is not None:
                mon_payload["pokemon_level"] = mon["level"]

            if mon["form"] is not None and mon["form"] > 0:
                mon_payload["form"] = mon["form"]

            if mon["cp"] is not None:
                mon_payload["cp"] = mon["cp"]

            if mon["individual_attack"] is not None:
                mon_payload["individual_attack"] = mon["individual_attack"]

            if mon["individual_defense"] is not None:
                mon_payload["individual_defense"] = mon["individual_defense"]

            if mon["individual_stamina"] is not None:
                mon_payload["individual_stamina"] = mon["individual_stamina"]

            if mon["move_1"] is not None:
                mon_payload["move_1"] = mon["move_1"]

            if mon["move_2"] is not None:
                mon_payload["move_2"] = mon["move_2"]

            if mon.get("height", None) is not None:
                mon_payload["height"] = mon["height"]

            if mon["weight"] is not None:
                mon_payload["weight"] = mon["weight"]

            if mon["gender"] is not None:
                mon_payload["gender"] = mon["gender"]

            if pokemon_rarity is not None:
                mon_payload["rarity"] = pokemon_rarity

            if (mon["weather_boosted_condition"] is not None
                    and mon["weather_boosted_condition"] > 0):
                mon_payload["boosted_weather"] = mon[
                    "weather_boosted_condition"]

            entire_payload = {"type": "pokemon", "message": mon_payload}
            ret.append(entire_payload)

        return ret
Esempio n. 4
0
    def game_stats_mon(self):
        minutes_spawn = request.args.get('minutes_spawn', 10)

        # Spawn
        iv = []
        noniv = []
        sumg = []
        sumup = {}

        data = self._db.statistics_get_pokemon_count(minutes_spawn)
        for dat in data:
            if dat[2] == 1:
                iv.append([(self.utc2local(dat[0]) * 1000), dat[1]])
            else:
                noniv.append([(self.utc2local(dat[0]) * 1000), dat[1]])

            if (self.utc2local(dat[0]) * 1000) in sumup:
                sumup[(self.utc2local(dat[0]) * 1000)] += dat[1]
            else:
                sumup[(self.utc2local(dat[0]) * 1000)] = dat[1]

        for dat in sumup:
            sumg.append([dat, sumup[dat]])

        spawn = {'iv': iv, 'noniv': noniv, 'sum': sumg}

        #shiny hour

        shiny_hour_temp = {}
        shiny_hour_calc = {}
        shiny_hour = []
        data = self._db.statistics_get_shiny_stats_hour()
        for dat in data:
            if dat[1] not in shiny_hour_temp:
                shiny_hour_temp[dat[1]] = dat[0]

        for dat in shiny_hour_temp:
            if shiny_hour_temp[dat] not in shiny_hour_calc:
                shiny_hour_calc[shiny_hour_temp[dat]] = 0
            shiny_hour_calc[shiny_hour_temp[dat]] += 1

        for dat in sorted(shiny_hour_calc):
            sht = ([
                self.utc2local(dat * 60 * 60) * 1000, shiny_hour_calc[dat]
            ])
            shiny_hour.append(sht)

        # good_spawns avg
        good_spawns = []
        data = self._db.get_best_pokemon_spawns()
        for dat in data:
            mon = "%03d" % dat[1]
            monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_00.png'
            monName_raw = (get_raid_boss_cp(dat[1]))
            monName = i8ln(monName_raw['name'])
            if self._args.db_method == "rm":
                lvl = calculate_mon_level(dat[6])
            else:
                lvl = dat[6]
            good_spawns.append({
                'id':
                dat[1],
                'iv':
                round(calculate_iv(dat[3], dat[4], dat[5]), 0),
                'lvl':
                lvl,
                'cp':
                dat[7],
                'img':
                monPic,
                'name':
                monName,
                'periode':
                datetime.datetime.fromtimestamp(self.utc2local(
                    dat[2])).strftime(self._datetimeformat)
            })

        shiny_stats = []
        shiny_worker = {}
        shiny_avg = {}
        data = self._db.statistics_get_shiny_stats()
        for dat in data:
            form_suffix = "%02d" % form_mapper(dat[2], dat[5])
            mon = "%03d" % dat[2]
            monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_' + form_suffix + '_shiny.png'
            monName_raw = (get_raid_boss_cp(dat[2]))
            monName = i8ln(monName_raw['name'])
            diff: int = dat[0]
            if diff == 0:
                logger.warning(
                    'No deeper mon stats are possible - not enought data '
                    '(check config.ini // game_stats_raw)')
                diff = 1

            ratio = round(dat[1] * 100 / diff, 2)
            if dat[3] not in shiny_worker: shiny_worker[dat[3]] = 0
            shiny_worker[dat[3]] += dat[1]

            if dat[2] not in shiny_avg: shiny_avg[dat[2]] = {}
            if dat[5] not in shiny_avg[dat[2]]:
                shiny_avg[dat[2]][dat[5]] = {}
                shiny_avg[dat[2]][dat[5]]['total_shiny'] = []
                shiny_avg[dat[2]][dat[5]]['total_nonshiny'] = []

            shiny_avg[dat[2]][dat[5]]['total_shiny'].append(dat[1])
            shiny_avg[dat[2]][dat[5]]['total_nonshiny'].append(diff)

            shiny_stats.append({
                'sum':
                dat[0],
                'shiny':
                dat[1],
                'img':
                monPic,
                'name':
                monName,
                'ratio':
                ratio,
                'worker':
                dat[3],
                'encounterid':
                dat[4],
                'periode':
                datetime.datetime.fromtimestamp(self.utc2local(
                    dat[6])).strftime(self._datetimeformat)
            })

        shiny_stats_avg = []
        for dat in shiny_avg:
            for form_dat in shiny_avg[dat]:

                form_suffix = "%02d" % form_mapper(dat, form_dat)
                mon = "%03d" % dat
                monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_' + form_suffix + '_shiny.png'
                monName_raw = (get_raid_boss_cp(dat))
                monName = i8ln(monName_raw['name'])

                total_shiny_encounters = sum(
                    shiny_avg[dat][form_dat]['total_shiny'])
                total_nonshiny_encounters = sum(
                    shiny_avg[dat][form_dat]['total_nonshiny'])
                shiny_avg_click = round(
                    total_nonshiny_encounters / total_shiny_encounters, 0)

                shiny_stats_avg.append({
                    'name': monName,
                    'img': monPic,
                    'total_shiny_encounters': total_shiny_encounters,
                    'total_nonshiny_encounters': total_nonshiny_encounters,
                    'click_for_shiny': shiny_avg_click
                })

        shiny_stats_worker = []
        for dat in shiny_worker:
            shiny_stats_worker.append({
                'sum': shiny_worker[dat],
                'worker': dat
            })

        stats = {
            'spawn': spawn,
            'good_spawns': good_spawns,
            'shiny': shiny_stats,
            'shiny_worker': shiny_stats_worker,
            'shiny_hour': shiny_hour,
            'shiny_stats_avg': shiny_stats_avg
        }
        return jsonify(stats)
Esempio n. 5
0
    def __prepare_mon_data(self, mon_data):
        ret = []

        for mon in mon_data:
            if self.__is_in_excluded_area([mon["latitude"], mon["longitude"]]):
                continue

            if (not self.__args.pokemon_webhook_nonivs
                    and mon["pokemon_id"] in self.__IV_MON
                    and (mon["individual_attack"] is None)):
                # skipping this mon since IV has not been scanned yet
                continue

            mon_payload = {
                "encounter_id": mon["encounter_id"],
                "pokemon_id": mon["pokemon_id"],
                "spawnpoint_id": mon["spawnpoint_id"],
                "latitude": mon["latitude"],
                "longitude": mon["longitude"],
                "disappear_time": mon["disappear_time"],
                "verified": mon["spawn_verified"],
            }

            # get rarity
            pokemon_rarity = self.__rarity.rarity_by_id(
                pokemonid=mon["pokemon_id"])

            if mon.get("cp_multiplier", None) is not None:
                mon_payload["cp_multiplier"] = mon["cp_multiplier"]
                mon_payload["pokemon_level"] = calculate_mon_level(
                    mon["cp_multiplier"])

            if mon["form"] is not None and mon["form"] > 0:
                mon_payload["form"] = mon["form"]

            if mon["costume"] is not None:
                mon_payload["costume"] = mon["costume"]

            if mon["cp"] is not None:
                mon_payload["cp"] = mon["cp"]

            if mon["individual_attack"] is not None:
                mon_payload["individual_attack"] = mon["individual_attack"]

            if mon["individual_defense"] is not None:
                mon_payload["individual_defense"] = mon["individual_defense"]

            if mon["individual_stamina"] is not None:
                mon_payload["individual_stamina"] = mon["individual_stamina"]

            if mon["move_1"] is not None:
                mon_payload["move_1"] = mon["move_1"]

            if mon["move_2"] is not None:
                mon_payload["move_2"] = mon["move_2"]

            if mon.get("height", None) is not None:
                mon_payload["height"] = mon["height"]

            if mon["weight"] is not None:
                mon_payload["weight"] = mon["weight"]

            if mon["gender"] is not None:
                mon_payload["gender"] = mon["gender"]

            if pokemon_rarity is not None:
                mon_payload["rarity"] = pokemon_rarity

            if (mon["weather_boosted_condition"] is not None
                    and mon["weather_boosted_condition"] > 0):
                if self.__args.quest_webhook_flavor == "default":
                    mon_payload["boosted_weather"] = mon[
                        "weather_boosted_condition"]
                if self.__args.quest_webhook_flavor == "poracle":
                    mon_payload["weather"] = mon["weather_boosted_condition"]

            entire_payload = {"type": "pokemon", "message": mon_payload}
            ret.append(entire_payload)

        return ret