Exemplo n.º 1
0
 def warm_app(id, short_name, featured=False):
     if id not in apps_cached:
         cached_apps.get_app(short_name)
         cached_apps.n_tasks(id)
         n_task_runs = cached_apps.n_task_runs(id)
         cached_apps.overall_progress(id)
         cached_apps.last_activity(id)
         cached_apps.n_completed_tasks(id)
         cached_apps.n_volunteers(id)
         if n_task_runs >= 1000 or featured:
             print "Getting stats for %s as it has %s task runs" % (short_name, n_task_runs)
             stats.get_stats(id, app.config.get('GEO'))
         apps_cached.append(id)
Exemplo n.º 2
0
 def warm_app(id, short_name):
     if id not in apps_cached:
         cached_apps.get_app(short_name)
         cached_apps.n_tasks(id)
         n_task_runs = cached_apps.n_task_runs(id)
         cached_apps.overall_progress(id)
         cached_apps.last_activity(id)
         cached_apps.n_completed_tasks(id)
         cached_apps.n_volunteers(id)
         if n_task_runs >= 1000:
             print "Getting stats for %s as it has %s" % (id,
                                                          n_task_runs)
             stats.get_stats(id, app.config.get('GEO'))
         apps_cached.append(id)
Exemplo n.º 3
0
def show_stats(short_name):
    """Returns App Stats"""
    app = app_by_shortname(short_name)
    title = app_title(app, "Statistics")

    if not (len(app.tasks) > 0 and len(app.task_runs) > 0):
        return render_template('/applications/non_stats.html',
                               title=title,
                               app=app)

    dates_stats, hours_stats, users_stats = stats.get_stats(
        app.id, current_app.config['GEO'])
    anon_pct_taskruns = int((users_stats['n_anon'] * 100) /
                            (users_stats['n_anon'] + users_stats['n_auth']))
    userStats = dict(geo=current_app.config['GEO'],
                     anonymous=dict(users=users_stats['n_anon'],
                                    taskruns=users_stats['n_anon'],
                                    pct_taskruns=anon_pct_taskruns,
                                    top5=users_stats['anon']['top5']),
                     authenticated=dict(users=users_stats['n_auth'],
                                        taskruns=users_stats['n_auth'],
                                        pct_taskruns=100 - anon_pct_taskruns,
                                        top5=users_stats['auth']['top5']))

    tmp = dict(userStats=users_stats['users'],
               userAnonStats=users_stats['anon'],
               userAuthStats=users_stats['auth'],
               dayStats=dates_stats,
               hourStats=hours_stats)

    return render_template('/applications/stats.html',
                           title=title,
                           appStats=json.dumps(tmp),
                           userStats=userStats,
                           app=app)
Exemplo n.º 4
0
def show_stats(short_name):
    """Returns App Stats"""
    app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name)
    title = app_title(app, "Statistics")

    try:
        require.app.read(app)
    except HTTPException:
        if app.hidden:
            raise abort(403)
        else:
            raise

    if not ((n_tasks > 0) and (n_task_runs > 0)):
        return render_template('/applications/non_stats.html',
                               title=title,
                               app=app)

    dates_stats, hours_stats, users_stats = stats.get_stats(
        app.id,
        current_app.config['GEO'])
    anon_pct_taskruns = int((users_stats['n_anon'] * 100) /
                            (users_stats['n_anon'] + users_stats['n_auth']))
    userStats = dict(
        geo=current_app.config['GEO'],
        anonymous=dict(
            users=users_stats['n_anon'],
            taskruns=users_stats['n_anon'],
            pct_taskruns=anon_pct_taskruns,
            top5=users_stats['anon']['top5']),
        authenticated=dict(
            users=users_stats['n_auth'],
            taskruns=users_stats['n_auth'],
            pct_taskruns=100 - anon_pct_taskruns,
            top5=users_stats['auth']['top5']))

    tmp = dict(userStats=users_stats['users'],
               userAnonStats=users_stats['anon'],
               userAuthStats=users_stats['auth'],
               dayStats=dates_stats,
               hourStats=hours_stats)

    return render_template('/applications/stats.html',
                           title=title,
                           appStats=json.dumps(tmp),
                           userStats=userStats,
                           app=app)
Exemplo n.º 5
0
def show_stats(short_name):
    """Returns App Stats"""
    app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name)
    title = app_title(app, "Statistics")

    try:
        require.app.read(app)
    except HTTPException:
        if app.hidden:
            raise abort(403)
        else: # pragma: no cover
            raise

    if not ((n_tasks > 0) and (n_task_runs > 0)):
        return render_template('/applications/non_stats.html',
                               title=title,
                               app=app)

    dates_stats, hours_stats, users_stats = stats.get_stats(
        app.id,
        current_app.config['GEO'])
    anon_pct_taskruns = int((users_stats['n_anon'] * 100) /
                            (users_stats['n_anon'] + users_stats['n_auth']))
    userStats = dict(
        geo=current_app.config['GEO'],
        anonymous=dict(
            users=users_stats['n_anon'],
            taskruns=users_stats['n_anon'],
            pct_taskruns=anon_pct_taskruns,
            top5=users_stats['anon']['top5']),
        authenticated=dict(
            users=users_stats['n_auth'],
            taskruns=users_stats['n_auth'],
            pct_taskruns=100 - anon_pct_taskruns,
            top5=users_stats['auth']['top5']))

    tmp = dict(userStats=users_stats['users'],
               userAnonStats=users_stats['anon'],
               userAuthStats=users_stats['auth'],
               dayStats=dates_stats,
               hourStats=hours_stats)

    return render_template('/applications/stats.html',
                           title=title,
                           appStats=json.dumps(tmp),
                           userStats=userStats,
                           app=app)
Exemplo n.º 6
0
def show_stats(short_name):
    """Returns App Stats"""
    app = app_by_shortname(short_name)
    title = app_title(app, "Statistics")

    if not (len(app.tasks) > 0 and len(app.task_runs) > 0):
        return render_template('/applications/non_stats.html',
                               title=title,
                               app=app)

    dates_stats, hours_stats, users_stats = stats.get_stats(
        app.id,
        current_app.config['GEO'])
    anon_pct_taskruns = int((users_stats['n_anon'] * 100) /
                            (users_stats['n_anon'] + users_stats['n_auth']))
    userStats = dict(
        geo=current_app.config['GEO'],
        anonymous=dict(
            users=users_stats['n_anon'],
            taskruns=users_stats['n_anon'],
            pct_taskruns=anon_pct_taskruns,
            top5=users_stats['anon']['top5']),
        authenticated=dict(
            users=users_stats['n_auth'],
            taskruns=users_stats['n_auth'],
            pct_taskruns=100 - anon_pct_taskruns,
            top5=users_stats['auth']['top5']))

    tmp = dict(userStats=users_stats['users'],
               userAnonStats=users_stats['anon'],
               userAuthStats=users_stats['auth'],
               dayStats=dates_stats,
               hourStats=hours_stats)

    return render_template('/applications/stats.html',
                           title=title,
                           appStats=json.dumps(tmp),
                           userStats=userStats,
                           app=app)
Exemplo n.º 7
0
    def test_03_stats(self):
        """Test STATS stats method works"""
        today = unicode(datetime.date.today())
        hour = int(datetime.datetime.utcnow().strftime('%H'))
        date_ms = time.mktime(time.strptime(today, "%Y-%m-%d")) * 1000
        anon = 0
        auth = 0
        with self.app.test_request_context('/'):
            dates_stats, hours_stats, user_stats = stats.get_stats(1)
            for item in dates_stats:
                if item['label'] == 'Anon + Auth':
                    assert item['values'][0][0] == date_ms, item['values'][0][0]
                    assert item['values'][0][1] == 10, "There should be 10 answers"
                if item['label'] == 'Anonymous':
                    assert item['values'][0][0] == date_ms, item['values'][0][0]
                    anon = item['values'][0][1]
                if item['label'] == 'Authenticated':
                    assert item['values'][0][0] == date_ms, item['values'][0][0]
                    auth = item['values'][0][1]
                if item['label'] == 'Total':
                    assert item['values'][0][0] == date_ms, item['values'][0][0]
                    assert item['values'][0][1] == 10, "There should be 10 answers"
                if item['label'] == 'Expected Answers':
                    assert item['values'][0][0] == date_ms, item['values'][0][0]
                    for i in item['values']:
                        assert i[1] == 100, "Each date should have 100 answers"
                    assert item['values'][0][1] == 100, "There should be 10 answers"
                if item['label'] == 'Estimation':
                    assert item['values'][0][0] == date_ms, item['values'][0][0]
                    v = 10
                    for i in item['values']:
                        assert i[1] == v, "Each date should have 10 extra answers"
                        v = v + 10
            assert auth + anon == 10, "date stats sum of auth and anon should be 10"

            max_hours = 0
            for item in hours_stats:
                if item['label'] == 'Anon + Auth':
                    max_hours = item['max']
                    print item
                    assert item['max'] == 10, item['max']
                    assert item['max'] == 10, "Max hours value should be 10"
                    for i in item['values']:
                        if i[0] == hour:
                            assert i[1] == 10, "There should be 10 answers"
                            assert i[2] == 5, "The size of the bubble should be 5"
                        else:
                            assert i[1] == 0, "There should be 0 answers"
                            assert i[2] == 0, "The size of the buggle should be 0"
                if item['label'] == 'Anonymous':
                    anon = item['max']
                    for i in item['values']:
                        if i[0] == hour:
                            assert i[1] == anon, "There should be anon answers"
                            assert i[2] == (anon * 5) / max_hours, "The size of the bubble should be 5"
                        else:
                            assert i[1] == 0, "There should be 0 answers"
                            assert i[2] == 0, "The size of the buggle should be 0"
                if item['label'] == 'Authenticated':
                    auth = item['max']
                    for i in item['values']:
                        if i[0] == hour:
                            assert i[1] == auth, "There should be anon answers"
                            assert i[2] == (auth * 5) / max_hours, "The size of the bubble should be 5"
                        else:
                            assert i[1] == 0, "There should be 0 answers"
                            assert i[2] == 0, "The size of the buggle should be 0"
            assert auth + anon == 10, "date stats sum of auth and anon should be 10"

            err_msg = "date stats sum of auth and anon should be 10"
            assert user_stats['n_anon'] + user_stats['n_auth'], err_msg
Exemplo n.º 8
0
    def test_03_stats(self):
        """Test STATS stats method works"""
        today = unicode(datetime.date.today())
        hour = int(datetime.datetime.utcnow().strftime('%H'))
        date_ms = time.mktime(time.strptime(today, "%Y-%m-%d")) * 1000
        anon = 0
        auth = 0
        with self.app.test_request_context('/'):
            dates_stats, hours_stats, user_stats = stats.get_stats(1)
            for item in dates_stats:
                if item['label'] == 'Anon + Auth':
                    assert item['values'][0][0] == date_ms, item['values'][0][
                        0]
                    assert item['values'][0][
                        1] == 10, "There should be 10 answers"
                if item['label'] == 'Anonymous':
                    assert item['values'][0][0] == date_ms, item['values'][0][
                        0]
                    anon = item['values'][0][1]
                if item['label'] == 'Authenticated':
                    assert item['values'][0][0] == date_ms, item['values'][0][
                        0]
                    auth = item['values'][0][1]
                if item['label'] == 'Total':
                    assert item['values'][0][0] == date_ms, item['values'][0][
                        0]
                    assert item['values'][0][
                        1] == 10, "There should be 10 answers"
                if item['label'] == 'Expected Answers':
                    assert item['values'][0][0] == date_ms, item['values'][0][
                        0]
                    for i in item['values']:
                        assert i[1] == 100, "Each date should have 100 answers"
                    assert item['values'][0][
                        1] == 100, "There should be 10 answers"
                if item['label'] == 'Estimation':
                    assert item['values'][0][0] == date_ms, item['values'][0][
                        0]
                    v = 10
                    for i in item['values']:
                        assert i[
                            1] == v, "Each date should have 10 extra answers"
                        v = v + 10
            assert auth + anon == 10, "date stats sum of auth and anon should be 10"

            max_hours = 0
            for item in hours_stats:
                if item['label'] == 'Anon + Auth':
                    max_hours = item['max']
                    print item
                    assert item['max'] == 10, item['max']
                    assert item['max'] == 10, "Max hours value should be 10"
                    for i in item['values']:
                        if i[0] == hour:
                            assert i[1] == 10, "There should be 10 answers"
                            assert i[
                                2] == 5, "The size of the bubble should be 5"
                        else:
                            assert i[1] == 0, "There should be 0 answers"
                            assert i[
                                2] == 0, "The size of the buggle should be 0"
                if item['label'] == 'Anonymous':
                    anon = item['max']
                    for i in item['values']:
                        if i[0] == hour:
                            assert i[1] == anon, "There should be anon answers"
                            assert i[2] == (
                                anon * 5
                            ) / max_hours, "The size of the bubble should be 5"
                        else:
                            assert i[1] == 0, "There should be 0 answers"
                            assert i[
                                2] == 0, "The size of the buggle should be 0"
                if item['label'] == 'Authenticated':
                    auth = item['max']
                    for i in item['values']:
                        if i[0] == hour:
                            assert i[1] == auth, "There should be anon answers"
                            assert i[2] == (
                                auth * 5
                            ) / max_hours, "The size of the bubble should be 5"
                        else:
                            assert i[1] == 0, "There should be 0 answers"
                            assert i[
                                2] == 0, "The size of the buggle should be 0"
            assert auth + anon == 10, "date stats sum of auth and anon should be 10"

            err_msg = "date stats sum of auth and anon should be 10"
            assert user_stats['n_anon'] + user_stats['n_auth'], err_msg
Exemplo n.º 9
0
    def test_03_stats(self):
        """Test STATS stats method works"""
        today = unicode(datetime.date.today())
        hour = int(datetime.datetime.utcnow().strftime('%H'))
        date_ms = time.mktime(time.strptime(today, "%Y-%m-%d")) * 1000
        anon = 0
        auth = 0
        TaskRunFactory.create(task=self.project.tasks[0])
        TaskRunFactory.create(task=self.project.tasks[1])
        dates_stats, hours_stats, user_stats = stats.get_stats(self.project.id)
        for item in dates_stats:
            if item['label'] == 'Anon + Auth':
                assert item['values'][0][0] == date_ms, item['values'][0][0]
                assert item['values'][0][1] == 10, "There should be 10 answers"
            if item['label'] == 'Anonymous':
                assert item['values'][0][0] == date_ms, item['values'][0][0]
                anon = item['values'][0][1]
            if item['label'] == 'Authenticated':
                assert item['values'][0][0] == date_ms, item['values'][0][0]
                auth = item['values'][0][1]
            if item['label'] == 'Total Tasks':
                assert item['values'][0][0] == date_ms, item['values'][0][0]
                assert item['values'][0][1] == 4, "There should be 4 tasks"
            if item['label'] == 'Expected Answers':
                assert item['values'][0][0] == date_ms, item['values'][0][0]
                for i in item['values']:
                    assert i[1] == 100, "Each date should have 100 answers"
                assert item['values'][0][1] == 100, "There should be 10 answers"
        assert auth + anon == 10, "date stats sum of auth and anon should be 10"

        max_hours = 0
        for item in hours_stats:
            if item['label'] == 'Anon + Auth':
                max_hours = item['max']
                print item
                assert item['max'] == 10, item['max']
                assert item['max'] == 10, "Max hours value should be 10"
                for i in item['values']:
                    if i[0] == hour:
                        assert i[1] == 10, "There should be 10 answers"
                        assert i[2] == 5, "The size of the bubble should be 5"
                    else:
                        assert i[1] == 0, "There should be 0 answers"
                        assert i[2] == 0, "The size of the buggle should be 0"
            if item['label'] == 'Anonymous':
                anon = item['max']
                for i in item['values']:
                    if i[0] == hour:
                        assert i[1] == anon, "There should be anon answers"
                        assert i[2] == (anon * 5) / max_hours, "The size of the bubble should be 5"
                    else:
                        assert i[1] == 0, "There should be 0 answers"
                        assert i[2] == 0, "The size of the buggle should be 0"
            if item['label'] == 'Authenticated':
                auth = item['max']
                for i in item['values']:
                    if i[0] == hour:
                        assert i[1] == auth, "There should be anon answers"
                        assert i[2] == (auth * 5) / max_hours, "The size of the bubble should be 5"
                    else:
                        assert i[1] == 0, "There should be 0 answers"
                        assert i[2] == 0, "The size of the buggle should be 0"
        assert auth + anon == 10, "date stats sum of auth and anon should be 8"

        err_msg = "user stats sum of auth and anon should be 7"
        assert user_stats['n_anon'] + user_stats['n_auth'] == 7, err_msg