示例#1
0
文件: map.py 项目: rgeyer/MAD
    def get_map_mons(self):
        neLat, neLon, swLat, swLon, oNeLat, oNeLon, oSwLat, oSwLon = getBoundParameter(
            request)
        timestamp = request.args.get("timestamp", None)

        data = self._db.get_mons_in_rectangle(neLat=neLat,
                                              neLon=neLon,
                                              swLat=swLat,
                                              swLon=swLon,
                                              oNeLat=oNeLat,
                                              oNeLon=oNeLon,
                                              oSwLat=oSwLat,
                                              oSwLon=oSwLon,
                                              timestamp=timestamp)

        mons_raw = {}

        for i, mon in enumerate(data):
            try:
                id = data[i]["mon_id"]
                if str(id) in mons_raw:
                    mon_raw = mons_raw[str(id)]
                else:
                    mon_raw = get_raid_boss_cp(id)
                    mons_raw[str(id)] = mon_raw

                data[i]["encounter_id"] = str(data[i]["encounter_id"])
                data[i]["name"] = i8ln(mon_raw["name"])
            except Exception:
                pass

        return jsonify(data)
示例#2
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)
示例#3
0
    def game_stats_shiny_v2(self):
        logger.debug('game_stats_shiny_v2')
        timestamp_from = request.args.get('from', None)
        if (timestamp_from):
            timestamp_from = self.local2utc(int(timestamp_from))
            logger.debug('using timestamp_from: {}', timestamp_from)

        timestamp_to = request.args.get('to', None)
        if (timestamp_to):
            timestamp_to = self.local2utc(int(timestamp_to))
            logger.debug('using timestamp_to: {}', timestamp_to)

        tmp_perworker_v2 = {}
        data = self._db_stats_reader.get_shiny_stats_v2(
            timestamp_from, timestamp_to)
        # SELECT pokemon.pokemon_id, pokemon.form, pokemon.latitude, pokemon.longitude, pokemon.gender, pokemon.costume, tr.count, tr.timestamp_scan, tr.worker, pokemon.encounter_id
        found_shiny_mon_id = []
        shiny_count = {}
        mon_names = {}
        tmp_perhour_v2 = {}

        if data is None or len(data) == 0:
            return jsonify({'empty': True})

        shiny_stats_v2 = []
        for dat in data:
            form_suffix = "%02d" % form_mapper(dat[0], dat[1])
            mon = "%03d" % dat[0]
            monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_' + form_suffix + '_shiny.png'
            monName_raw = (get_raid_boss_cp(dat[0]))
            monName = i8ln(monName_raw['name'])
            mon_names[dat[0]] = monName
            found_shiny_mon_id.append(
                mon
            )  # append everything now, we will set() it later to remove duplicates
            if dat[8] not in tmp_perworker_v2:
                tmp_perworker_v2[dat[8]] = 0
            tmp_perworker_v2[dat[8]] += 1

            if dat[0] not in shiny_count:
                shiny_count[dat[0]] = {}
            if dat[1] not in shiny_count[dat[0]]:
                shiny_count[dat[0]][dat[1]] = 0
            shiny_count[dat[0]][dat[1]] += 1

            # there is later strftime which converts to local time too, can't use utc2local - it will do double shift
            timestamp = datetime.datetime.fromtimestamp(dat[7])

            if timestamp.hour in tmp_perhour_v2:
                tmp_perhour_v2[timestamp.hour] += 1
            else:
                tmp_perhour_v2[timestamp.hour] = 1

            shiny_stats_v2.append({
                'img':
                monPic,
                'name':
                monName,
                'worker':
                dat[8],
                'lat':
                dat[2],
                'lat_5':
                "{:.5f}".format(dat[2]),
                'lng_5':
                "{:.5f}".format(dat[3]),
                'lng':
                dat[3],
                'timestamp':
                timestamp.strftime(self._datetimeformat),
                'form':
                dat[1],
                'mon_id':
                dat[0],
                'encounter_id':
                str(dat[9])
            })

        global_shiny_stats_v2 = []
        data = self._db_stats_reader.get_shiny_stats_global_v2(
            set(found_shiny_mon_id), timestamp_from, timestamp_to)
        for dat in data:
            if dat[1] in shiny_count and dat[2] in shiny_count[dat[1]]:
                odds = round(dat[0] / shiny_count[dat[1]][dat[2]], 0)
                form_suffix = "%02d" % form_mapper(dat[1], dat[2])
                mon = "%03d" % dat[1]
                monPic = 'asset/pokemon_icons/pokemon_icon_' + mon + '_' + form_suffix + '_shiny.png'
                global_shiny_stats_v2.append({
                    'name':
                    mon_names[dat[1]],
                    'count':
                    dat[0],
                    'img':
                    monPic,
                    'shiny':
                    shiny_count[dat[1]][dat[2]],
                    'odds':
                    odds,
                    'mon_id':
                    dat[1],
                    'form':
                    dat[2],
                    'gender':
                    dat[3],
                    'costume':
                    dat[4]
                })

        shiny_stats_perworker_v2 = []
        for worker in tmp_perworker_v2:
            shiny_stats_perworker_v2.append({
                'name': worker,
                'count': tmp_perworker_v2[worker]
            })

        shiny_stats_perhour_v2 = []
        for hour in tmp_perhour_v2:
            shiny_stats_perhour_v2.append([hour, tmp_perhour_v2[hour]])

        stats = {
            'empty': False,
            'shiny_statistics': shiny_stats_v2,
            'global_shiny_statistics': global_shiny_stats_v2,
            'per_worker': shiny_stats_perworker_v2,
            'per_hour': shiny_stats_perhour_v2
        }
        return jsonify(stats)
示例#4
0
    def shiny_stats_data(self):
        # shiny hour

        shiny_hour_temp = {}
        shiny_hour_calc = {}
        shiny_hour = []
        data = self._db_stats_reader.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)

        shiny_stats = []
        shiny_worker = {}
        shiny_avg = {}
        data = self._db_stats_reader.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(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 = {
            'shiny': shiny_stats,
            'shiny_worker': shiny_stats_worker,
            'shiny_hour': shiny_hour,
            'shiny_stats_avg': shiny_stats_avg
        }
        return jsonify(stats)
示例#5
0
    def __prepare_raid_data(self, raid_data):
        ret = []

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

            # skip ex raid mon if disabled
            is_exclusive = (raid["is_exclusive"] is not None
                            and raid["is_exclusive"] != 0)
            if not self.__args.webhook_submit_exraids and is_exclusive:
                continue

            raid_payload = {
                "latitude": raid["latitude"],
                "longitude": raid["longitude"],
                "level": raid["level"],
                "pokemon_id": raid["pokemon_id"],
                "team_id": raid["team_id"],
                "cp": raid["cp"],
                "start": raid["start"],
                "end": raid["end"],
                "name": raid["name"],
            }

            if raid["move_1"] is not None:
                raid_payload["move_1"] = raid["move_1"]

            if raid["move_2"] is not None:
                raid_payload["move_2"] = raid["move_2"]

            if raid["cp"] is None:
                raid_payload["cp"] = get_raid_boss_cp(raid["pokemon_id"])

            if raid["pokemon_id"] is None:
                raid_payload["pokemon_id"] = 0

            if raid["gym_id"] is not None:
                raid_payload["gym_id"] = raid["gym_id"]

            if raid["url"] is not None and raid["url"]:
                raid_payload["url"] = raid["url"]

            if raid["weather_boosted_condition"] is not None:
                raid_payload["weather"] = raid["weather_boosted_condition"]

            if raid["form"] is not None:
                raid_payload["form"] = raid["form"]

            if raid["is_ex_raid_eligible"] is not None:
                raid_payload["is_ex_raid_eligible"] = raid[
                    "is_ex_raid_eligible"]

            if raid["is_exclusive"] is not None:
                raid_payload["is_exclusive"] = raid["is_exclusive"]

            if raid["gender"] is not None:
                raid_payload["gender"] = raid["gender"]

            if raid["costume"] is not None:
                raid_payload["costume"] = raid["costume"]

            # create final message
            entire_payload = {"type": "raid", "message": raid_payload}

            # add to payload
            ret.append(entire_payload)

        return ret