Skip to content

Commit

Permalink
Optimize stat page x2 (RocketMap#1205)
Browse files Browse the repository at this point in the history
* optimize stat page

* remove auto update of stat map

* fix style

* dont use init from map for stat

* hate js. js suck. heatmap suck.

* coomon parts of map extracted

* flake go away

* add even listener
  • Loading branch information
aldarund authored and FrostTheFox committed Sep 9, 2016
1 parent 73c68b2 commit 098f356
Show file tree
Hide file tree
Showing 11 changed files with 893 additions and 895 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"skel": true,
"setupPokemonMarker": true,

"isTouchDevice": true,
"pokemonSprites": true,
"noLabelsStyle": true,
"darkStyle": true,
"light2Style": true,
Expand Down
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = function(grunt) {
files: {
'static/dist/js/app.built.js': 'static/js/app.js',
'static/dist/js/map.built.js': 'static/js/map.js',
'static/dist/js/map.common.built.js': 'static/js/map.common.js',
'static/dist/js/mobile.built.js': 'static/js/mobile.js',
'static/dist/js/stats.built.js': 'static/js/stats.js',
'static/dist/js/statistics.built.js': 'static/js/statistics.js',
Expand All @@ -47,6 +48,7 @@ module.exports = function(grunt) {
files: {
'static/dist/js/app.min.js': 'static/dist/js/app.built.js',
'static/dist/js/map.min.js': 'static/dist/js/map.built.js',
'static/dist/js/map.common.min.js': 'static/dist/js/map.common.built.js',
'static/dist/js/mobile.min.js': 'static/dist/js/mobile.built.js',
'static/dist/js/stats.min.js': 'static/dist/js/stats.built.js',
'static/dist/js/statistics.min.js': 'static/dist/js/statistics.built.js',
Expand Down
3 changes: 1 addition & 2 deletions pogom/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def raw_data(self):
d['seen'] = Pokemon.get_seen(selected_duration)

if request.args.get('appearances', 'false') == 'true':
d['appearances'] = Pokemon.get_appearances(request.args.get('pokemonid'),
request.args.get('last', type=float), selected_duration)
d['appearances'] = Pokemon.get_appearances(request.args.get('pokemonid'), selected_duration)

if request.args.get('appearancesDetails', 'false') == 'true':
d['appearancesTimes'] = Pokemon.get_appearances_times_by_spawnpoint(request.args.get('pokemonid'),
Expand Down
12 changes: 7 additions & 5 deletions pogom/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from playhouse.migrate import migrate, MySQLMigrator, SqliteMigrator
from datetime import datetime, timedelta
from base64 import b64encode
from cachetools import TTLCache
from cachetools import cached

from . import config
from .utils import get_pokemon_name, get_pokemon_rarity, get_pokemon_types, get_args
Expand All @@ -26,6 +28,7 @@

args = get_args()
flaskDb = FlaskDB()
cache = TTLCache(maxsize=100, ttl=60 * 5)

db_schema_version = 7

Expand Down Expand Up @@ -157,6 +160,7 @@ def get_active_by_id(ids, swLat, swLng, neLat, neLng):
return pokemons

@classmethod
@cached(cache)
def get_seen(cls, timediff):
if timediff:
timediff = datetime.utcnow() - timediff
Expand Down Expand Up @@ -197,23 +201,21 @@ def get_seen(cls, timediff):
return {'pokemon': pokemons, 'total': total}

@classmethod
def get_appearances(cls, pokemon_id, last_appearance, timediff):
def get_appearances(cls, pokemon_id, timediff):
'''
:param pokemon_id: id of pokemon that we need appearances for
:param last_appearance: time of last appearance of pokemon after which we are getting appearances
:param timediff: limiting period of the selection
:return: list of pokemon appearances over a selected period
'''
if timediff:
timediff = datetime.utcnow() - timediff
query = (Pokemon
.select(Pokemon.latitude, Pokemon.longitude, Pokemon.pokemon_id, fn.Count(Pokemon.spawnpoint_id).alias('count'), Pokemon.spawnpoint_id, Pokemon.disappear_time)
.select(Pokemon.latitude, Pokemon.longitude, Pokemon.pokemon_id, fn.Count(Pokemon.spawnpoint_id).alias('count'), Pokemon.spawnpoint_id)
.where((Pokemon.pokemon_id == pokemon_id) &
(Pokemon.disappear_time > datetime.utcfromtimestamp(last_appearance / 1000.0)) &
(Pokemon.disappear_time > timediff)
)
.order_by(Pokemon.disappear_time.asc())
.group_by(Pokemon.spawnpoint_id)
.group_by(Pokemon.latitude, Pokemon.longitude, Pokemon.pokemon_id, Pokemon.spawnpoint_id)
.dicts()
)

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ requests==2.10.0
PySocks==1.5.6
git+https://github.com/maddhatter/Flask-CacheBust.git@38d940cc4f18b5fcb5687746294e0360640a107e#egg=flask_cachebust
protobuf_to_dict==0.1.0
cachetools==1.1.6

2 changes: 1 addition & 1 deletion static/css/statistics.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ table td{
}

.container .item .name{
height: 30px;
height: 36px;
line-height: 30px;
}

Expand Down
Loading

0 comments on commit 098f356

Please sign in to comment.