[879b32]: / qiita_pet / handlers / stats.py

Download this file

75 lines (65 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from random import choice
from tornado.gen import coroutine, Task
from qiita_core.util import execute_as_transaction
from qiita_core.qiita_settings import qiita_config, r_client
from qiita_db.study import Study
from .base_handlers import BaseHandler
class StatsHandler(BaseHandler):
@execute_as_transaction
def _get_stats(self, callback):
stats = {}
# checking values from redis
portal = qiita_config.portal
vals = [
('number_studies', r_client.hgetall),
('number_of_samples', r_client.hgetall),
('num_users', r_client.get),
('per_data_type_stats', r_client.hgetall),
('lat_longs', r_client.get),
('num_studies_ebi', r_client.get),
('num_samples_ebi', r_client.get),
('number_samples_ebi_prep', r_client.get),
('img', r_client.get),
('time', r_client.get),
('num_processing_jobs', r_client.get)]
for k, f in vals:
redis_key = '%s:stats:%s' % (portal, k)
stats[k] = f(redis_key)
callback(stats)
@coroutine
@execute_as_transaction
def get(self):
stats = yield Task(self._get_stats)
# Pull a random public study from the database
public_studies = Study.get_by_status('public')
study = choice(list(public_studies)) if public_studies else None
if study is None:
random_study_info = None
random_study_title = None
random_study_id = None
else:
random_study_info = study.info
random_study_title = study.title
random_study_id = study.id
self.render('stats.html',
number_studies=stats['number_studies'],
number_of_samples=stats['number_of_samples'],
num_users=stats['num_users'],
per_data_type_stats=stats['per_data_type_stats'],
lat_longs=eval(
stats['lat_longs']) if stats['lat_longs'] else [],
num_studies_ebi=stats['num_studies_ebi'],
num_samples_ebi=stats['num_samples_ebi'],
number_samples_ebi_prep=stats['number_samples_ebi_prep'],
img=stats['img'], time=stats['time'],
num_processing_jobs=stats['num_processing_jobs'],
random_study_info=random_study_info,
random_study_title=random_study_title,
random_study_id=random_study_id)