• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python users.get_leaderboard函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pybossa.cache.users.get_leaderboard函数的典型用法代码示例。如果您正苦于以下问题:Python get_leaderboard函数的具体用法?Python get_leaderboard怎么用?Python get_leaderboard使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_leaderboard函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: warm_cache

def warm_cache(): # pragma: no cover
    """Background job to warm cache."""
    from pybossa.core import create_app
    app = create_app(run_as_server=False)
    # Cache 3 pages
    apps_cached = []
    pages = range(1, 4)
    import pybossa.cache.apps as cached_apps
    import pybossa.cache.categories as cached_cat
    import pybossa.cache.users as cached_users
    import pybossa.cache.project_stats as stats

    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)

    # Cache top projects
    apps = cached_apps.get_top()
    for a in apps:
        warm_app(a['id'], a['short_name'])
    for page in pages:
        apps = cached_apps.get_featured('featured', page,
                                        app.config['APPS_PER_PAGE'])
        for a in apps:
            warm_app(a['id'], a['short_name'], featured=True)

    # Categories
    categories = cached_cat.get_used()
    for c in categories:
        for page in pages:
            apps = cached_apps.get(c['short_name'],
                                   page,
                                   app.config['APPS_PER_PAGE'])
            for a in apps:
                warm_app(a['id'], a['short_name'])
    # Users
    cached_users.get_leaderboard(app.config['LEADERBOARD'], 'anonymous')
    cached_users.get_top()

    return True
开发者ID:IdahoInstitute,项目名称:pybossa,代码行数:51,代码来源:jobs.py


示例2: warm_cache

def warm_cache():
    '''Warm cache'''
    # Disable cache, so we can refresh the data in Redis
    os.environ['PYBOSSA_REDIS_CACHE_DISABLED'] = '1'
    # Cache 3 pages
    apps_cached = []
    pages = range(1, 4)
    with app.app_context():
        import pybossa.cache.projects as cached_apps
        import pybossa.cache.categories as cached_cat
        import pybossa.cache.users as cached_users
        import pybossa.cache.project_stats  as stats

        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)

        # Cache top projects
        apps = cached_apps.get_top()
        for a in apps:
            warm_app(a['id'], a['short_name'])
        for page in pages:
            apps = cached_apps.get_featured('featured', page,
                                            app.config['APPS_PER_PAGE'])
            for a in apps:
                warm_app(a['id'], a['short_name'], featured=True)

        # Categories
        categories = cached_cat.get_used()
        for c in categories:
            for page in pages:
                 apps = cached_apps.get(c['short_name'],
                                        page,
                                        app.config['APPS_PER_PAGE'])
                 for a in apps:
                     warm_app(a['id'], a['short_name'])
        # Users
        cached_users.get_leaderboard(app.config['LEADERBOARD'], 'anonymous')
        cached_users.get_top()
开发者ID:Skytim,项目名称:pybossa,代码行数:49,代码来源:warm.py


示例3: index

def index(window=0):
    """Get the last activity from users and projects."""
    if current_user.is_authenticated():
        user_id = current_user.id
    else:
        user_id = None

    if window >= 10:
        window = 10

    info = request.args.get('info')

    leaderboards = current_app.config.get('LEADERBOARDS')

    if info is not None:
        if leaderboards is None or info not in leaderboards:
            return abort(404)

    top_users = cached_users.get_leaderboard(current_app.config['LEADERBOARD'],
                                             user_id=user_id,
                                             window=window,
                                             info=info)

    response = dict(template='/stats/index.html',
                    title="Community Leaderboard",
                    top_users=top_users)
    return handle_content_type(response)
开发者ID:fiorda,项目名称:pybossa,代码行数:27,代码来源:leaderboard.py


示例4: index

def index(page):
    """
    Index page for all PyBossa registered users.

    Returns a Jinja2 rendered template with the users.

    """
    update_feed = get_update_feed()
    per_page = 24
    count = cached_users.get_total_users()
    accounts = cached_users.get_users_page(page, per_page)
    if not accounts and page != 1:
        abort(404)
    pagination = Pagination(page, per_page, count)
    if current_user.is_authenticated():
        user_id = current_user.id
    else:
        user_id = None
    top_users = cached_users.get_leaderboard(current_app.config['LEADERBOARD'],
                                             user_id)
    return render_template('account/index.html', accounts=accounts,
                           total=count,
                           top_users=top_users,
                           title="Community", pagination=pagination,
                           update_feed=update_feed)
开发者ID:bluetropic,项目名称:pybossa,代码行数:25,代码来源:account.py


示例5: test_get_leaderboard_no_users_returns_empty_list

    def test_get_leaderboard_no_users_returns_empty_list(self):
        """Test CACHE USERS get_leaderboard returns an empty list if there are no
        users"""

        users = cached_users.get_leaderboard(10)

        assert users == [], users
开发者ID:ronaldlcheung,项目名称:pybossa,代码行数:7,代码来源:test_cache_users.py


示例6: index

def index():
    """Return Global Statistics for the site."""
    title = "Statistics"
    description = """Statistical analysis of contributions made via the
                  LibCrowds crowdsourcing platform."""

    # User stats
    n_anon = extra_stats.n_anon_users()
    n_auth = site_stats.n_auth_users()
    top_5_users_1_week = extra_stats.get_top_n_users_k_days(5, 7)
    n_tr_top_10_percent = extra_stats.get_top_n_percent(10)
    users_daily = extra_stats.get_users_daily()
    leaderboard = cached_users.get_leaderboard(10)
    n_avg_days_active = extra_stats.n_avg_days_active()

    # Task stats
    n_tasks = site_stats.n_tasks_site()
    n_task_runs = site_stats.n_task_runs_site()
    n_auth_task_runs = extra_stats.n_auth_task_runs_site()
    n_tasks_completed = extra_stats.n_tasks_completed()
    task_runs_daily = extra_stats.get_task_runs_daily()
    dow = extra_stats.get_dow()
    hourly_activity = extra_stats.site_hourly_activity()

    # Project stats
    n_published_projects = cached_projects.n_published()
    top_5_pr_1_week = extra_stats.get_top_n_projects_k_days(5, 7)

    # Location stats
    locs = extra_stats.get_locations()
    n_continents = extra_stats.n_continents()
    n_cities = extra_stats.n_cities()
    n_countries = extra_stats.n_countries()
    top_countries = extra_stats.get_top_n_countries()

    stats = dict(n_auth=n_auth,
                 n_anon=n_anon,
                 n_published_projects=n_published_projects,
                 n_tasks=n_tasks,
                 n_task_runs=n_task_runs,
                 n_auth_task_runs=n_auth_task_runs,
                 n_tasks_completed=n_tasks_completed,
                 n_countries=n_countries,
                 n_cities=n_cities,
                 n_continents=n_continents,
                 n_avg_days_active=n_avg_days_active,
                 n_tr_top_10_percent=n_tr_top_10_percent)

    return render_template('/stats.html', title=title,
                           description=description,
                           stats=json.dumps(stats),
                           locs=json.dumps(locs),
                           users_daily=json.dumps(users_daily),
                           task_runs_daily=json.dumps(task_runs_daily),
                           top_countries=json.dumps(top_countries),
                           top_5_pr_1_week=json.dumps(top_5_pr_1_week),
                           top_5_users_1_week=json.dumps(top_5_users_1_week),
                           hourly_activity=json.dumps(hourly_activity),
                           dow=json.dumps(dow),
                           leaderboard=json.dumps(leaderboard))
开发者ID:LibCrowds,项目名称:libcrowds-statistics,代码行数:60,代码来源:view.py


示例7: warm_cache

def warm_cache():  # pragma: no cover
    """Background job to warm cache."""
    from pybossa.core import create_app
    app = create_app(run_as_server=False)
    projects_cached = []
    import pybossa.cache.projects as cached_projects
    import pybossa.cache.categories as cached_cat
    import pybossa.cache.users as cached_users
    import pybossa.cache.project_stats as stats
    from pybossa.util import rank
    from pybossa.core import user_repo

    def warm_project(_id, short_name, featured=False):
        if _id not in projects_cached:
            #cached_projects.get_project(short_name)
            #cached_projects.n_tasks(_id)
            #n_task_runs = cached_projects.n_task_runs(_id)
            #cached_projects.overall_progress(_id)
            #cached_projects.last_activity(_id)
            #cached_projects.n_completed_tasks(_id)
            #cached_projects.n_volunteers(_id)
            #cached_projects.browse_tasks(_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.update_stats(_id, app.config.get('GEO'))
            projects_cached.append(_id)

    # Cache top projects
    projects = cached_projects.get_top()
    for p in projects:
        warm_project(p['id'], p['short_name'])

    # Cache 3 pages
    to_cache = 3 * app.config['APPS_PER_PAGE']
    projects = rank(cached_projects.get_all_featured('featured'))[:to_cache]
    for p in projects:
        warm_project(p['id'], p['short_name'], featured=True)

    # Categories
    categories = cached_cat.get_used()
    for c in categories:
        projects = rank(cached_projects.get_all(c['short_name']))[:to_cache]
        for p in projects:
            warm_project(p['id'], p['short_name'])
    # Users
    users = cached_users.get_leaderboard(app.config['LEADERBOARD'])
    for user in users:
        # print "Getting stats for %s" % user['name']
        print user_repo
        u = user_repo.get_by_name(user['name'])
        cached_users.get_user_summary(user['name'])
        cached_users.projects_contributed_cached(u.id)
        cached_users.published_projects_cached(u.id)
        cached_users.draft_projects_cached(u.id)

    return True
开发者ID:fiorda,项目名称:pybossa,代码行数:57,代码来源:jobs.py


示例8: render_leaderboard

def render_leaderboard():
    """Renders the leaderboard page.

    Returns:
        unicode: The page's rendered HTML.
    """
    user_id = current_user.id if current_user.is_authenticated() else None
    users = cached_users.get_leaderboard(current_app.config["LEADERBOARD"], user_id=user_id)
    return render_template("/community/leaderboard.html", users=users)
开发者ID:geotagx,项目名称:geotagx-plugin,代码行数:9,代码来源:community.py


示例9: test_get_leaderboard_returns_fields

    def test_get_leaderboard_returns_fields(self):
        """Test CACHE USERS get_leaderboard returns user fields"""
        user = UserFactory.create()
        TaskRunFactory.create(user=user)
        fields = ('rank', 'id', 'name', 'fullname', 'email_addr',
                 'info', 'created', 'score')

        leaderboard = cached_users.get_leaderboard(1)

        for field in fields:
            assert field in leaderboard[0].keys(), field
        assert len(leaderboard[0].keys()) == len(fields)
开发者ID:ronaldlcheung,项目名称:pybossa,代码行数:12,代码来源:test_cache_users.py


示例10: test_get_leaderboard_returns_fields

    def test_get_leaderboard_returns_fields(self):
        """Test CACHE USERS get_leaderboard returns user fields"""
        user = UserFactory.create()
        TaskRunFactory.create(user=user)
        fields = User.public_attributes()

        update_leaderboard()
        leaderboard = cached_users.get_leaderboard(1)

        for field in fields:
            assert field in leaderboard[0].keys(), field
        assert len(leaderboard[0].keys()) == len(fields)
开发者ID:PyBossa,项目名称:pybossa,代码行数:12,代码来源:test_cache_users.py


示例11: test_get_leaderboard_includes_specific_user_even_is_not_in_top

    def test_get_leaderboard_includes_specific_user_even_is_not_in_top(self):
        leader = UserFactory.create()
        second = UserFactory.create()
        third = UserFactory.create()
        project = ProjectFactory.create()
        tasks = TaskFactory.create_batch(3, project=project)
        i = 3
        for user in [leader, second, third]:
            TaskRunFactory.create_batch(i, user=user, task=tasks[i-1])
            i -= 1
        user_out_of_top = UserFactory.create()

        leaderboard = cached_users.get_leaderboard(3, user_id=user_out_of_top.id)

        assert len(leaderboard) is 4
        assert leaderboard[-1]['id'] == user_out_of_top.id
开发者ID:ronaldlcheung,项目名称:pybossa,代码行数:16,代码来源:test_cache_users.py


示例12: test_get_leaderboard_returns_users_ordered_by_rank

    def test_get_leaderboard_returns_users_ordered_by_rank(self):
        leader = UserFactory.create()
        second = UserFactory.create()
        third = UserFactory.create()
        project = ProjectFactory.create()
        tasks = TaskFactory.create_batch(3, project=project)
        i = 3
        for user in [leader, second, third]:
            TaskRunFactory.create_batch(i, user=user, task=tasks[i-1])
            i -= 1

        leaderboard = cached_users.get_leaderboard(3)

        assert leaderboard[0]['id'] == leader.id
        assert leaderboard[1]['id'] == second.id
        assert leaderboard[2]['id'] == third.id
开发者ID:ronaldlcheung,项目名称:pybossa,代码行数:16,代码来源:test_cache_users.py


示例13: index

def index(page=1):
    """Index page for all PYBOSSA registered users."""

    update_feed = get_update_feed()
    per_page = 24
    count = cached_users.get_total_users()
    accounts = cached_users.get_users_page(page, per_page)
    if not accounts and page != 1:
        abort(404)
    pagination = Pagination(page, per_page, count)
    if current_user.is_authenticated():
        user_id = current_user.id
    else:
        user_id = None
    top_users = cached_users.get_leaderboard(current_app.config['LEADERBOARD'],
                                             user_id)
    tmp = dict(template='account/index.html', accounts=accounts,
               total=count,
               top_users=top_users,
               title="Community", pagination=pagination,
               update_feed=update_feed)
    return handle_content_type(tmp)
开发者ID:keyinfluencerplus,项目名称:tinybee.ai,代码行数:22,代码来源:account.py



注:本文中的pybossa.cache.users.get_leaderboard函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python users.get_user_summary函数代码示例发布时间:2022-05-25
下一篇:
Python users.delete_user_summary函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap