def shiny_stats_data(self): # 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) 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(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)
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.statistics_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': dat[9] }) #print(shiny_count) global_shiny_stats_v2 = [] data = self._db.statistics_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)
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)