예제 #1
0
파일: default.py 프로젝트: span007/paideia
def info():
    """
    Return data reporting on a user's performance record.

    This controller is intended to serve the view profile.load as a modular
    page component, to be embedded in other views such as:
        default/user.html
        reporting/user.html

    Returns a dict with the following keys:

    'the_name':             User's name from auth.user as lastname, firstname (str)
    'tz':                   User's time zone from auth.user (extended in db.py)
    'email':                User's email (str)
    'cal':                  html calendar with user path stats (from stats.monthcal)
    'blist':                list of User's bug reports
    'max_set':              Badge set reached by user (int)
    'goal':
    'badge_levels':         Dictionary with badle levels (int) as keys and
                            a list of badge names (or tag: int) as each value.
    'badge_table_data':
    'badges_active_over_time':
    'badges_tested_over_time':
    'sets_tested_over_time':
    'steps_most_wrong':

    """
    # Allow passing explicit user but default to current user
    if 'id' in request.vars:
        user = db.auth_user[request.vars['id']]
    else:
        user = db.auth_user[auth.user_id]

    stats = Stats(user.id, cache=cache)

    # tab1
    name = stats.get_name()
    tz = user.time_zone
    email = user.email
    max_set = stats.get_max()
    goal = stats.get_goal()
    badge_levels = stats.get_badge_levels()
    badge_table_data = stats.active_tags()
    # badges_active_over_time = stats.badges_active_over_time(badge_table_data)

    # tab2
    mycal = stats.monthcal()
    # badges_tested_over_time = stats.badges_tested_over_time(badge_table_data)
    # sets_tested_over_time = stats.sets_tested_over_time(badge_table_data)
    # steps_most_wrong = stats.steps_most_wrong(badge_table_data)

    # tab3
    b = Bug()
    blist = b.bugresponses(user.id)

    return {'the_name': name,
            'tz': tz,
            'email': email,
            'cal': mycal,
            'blist': blist,
            'max_set': max_set,
            'goal': goal,
            'badge_levels': badge_levels,
            'badge_table_data': badge_table_data,
            # 'badges_active_over_time': badges_active_over_time,
            # 'badges_tested_over_time': badges_tested_over_time,
            # 'sets_tested_over_time': sets_tested_over_time,
            # 'steps_most_wrong': steps_most_wrong
            }
예제 #2
0
def info():
    """
    Return data reporting on a user's performance record.

    This controller is intended to serve the view profile.load as a modular
    page component, to be embedded in other views such as:
        default/user.html
        reporting/user.html

    Returns:
        dict: with the following keys:
            the_name (str):             User's name from auth.user as lastname,
                                            firstname
            user_id(int):               The requested user's id.
            tz(str??):                  User's time zone from auth.user
                                            (extended in db.py)
            email(str):                 User's email
            starting_set(int):          badge set at which the user began
                                            his/her current course section
            end_date(str??):            ending date for user's current course
                                            section
            cal(html helper obj):       html calendar with user path stats
                                            (from Stats.monthcal)
            blist(list):                list of User's bug reports
            max_set(int):               Furthest badge set reached to date by
                                            user (from Stats.max)
            badge_levels(dict):         Dictionary with badle levels (int) as
                                            keys and a list of badge names (or
                                            tag: int) as each value.
            badge_table_data(list):     A list of dictionaries with info on
                                            user badge progress (from
                                            Stats.active_tags)
            badge_set_milestones(list): List of 'upgrades' of the highest badge
                                            set and their dates
            answer_counts(list):        List of counts of right and wrong
                                            answers for each active day
            chart1_data(dict):          dictionary of data to build stats chart
                                            in view (from get_chart1_data)
            reviewing_set():            session.set_review,
            badge_set_dict():           badge_set_dict
    """
    debug = False
    if debug:
        print('===================================')
        print('starting controller default.info')
    # Allow passing explicit user but default to current user
    if 'id' in request.vars:
        user = db.auth_user[request.vars['id']]
    else:
        user = db.auth_user[auth.user_id]

    stats = Stats(user.id)
    now = datetime.datetime.utcnow()
    if debug:
        print('now is', now)

    # get user's current course
    myc = get_current_class(user.id, datetime.datetime.utcnow())
    if debug:
        print('myc is', myc)

    # tab1

    name = stats.get_name()
    tz = user.time_zone
    email = user.email
    max_set = stats.get_max()
    badge_levels = stats.get_badge_levels()
    badge_table_data = stats.active_tags()

    start_date, fmt_start, end_date, fmt_end = None, None, None, None
    if myc:
        start_date, fmt_start, end_date, fmt_end, \
            prevend, fmt_prevend = get_term_bounds(
                myc.class_membership.as_dict(),
                myc.classes.start_date,
                myc.classes.end_date)
        try:
            starting_set = int(myc.class_membership.starting_set)
        except ValueError:
            starting_set = None
        if not starting_set:
            starting_set = get_set_at_date(user.id, start_date)
        goal = myc.classes.a_target

        if myc.class_membership.custom_a_cap:  # allow personal targets
            target_set = myc.class_membership.custom_a_cap
        else:  # default to class target/cap
            cap = myc.classes.a_cap
            target_set = starting_set + goal
            if cap and target_set > cap:
                target_set = cap
    else:
        starting_set = None
        goal = None
        target_set = None

    # tab2
    mycal = stats.monthcal()
    # badges_tested_over_time = stats.badges_tested_over_time(badge_table_data)
    # sets_tested_over_time = stats.sets_tested_over_time(badge_table_data)
    # steps_most_wrong = stats.steps_most_wrong(badge_table_data)

    # tab3
    b = Bug()
    blist = b.bugresponses(user.id)

    # tab5
    mydata = get_chart1_data(user_id=user.id)
    chart1_data = mydata['chart1_data']
    badge_set_milestones = mydata['badge_set_milestones']
    answer_counts = mydata['answer_counts']
    badge_set_dict = {}
    set_list_rows = db().select(db.tags.tag_position, distinct=True)
    set_list = sorted([row.tag_position for row in set_list_rows
                       if row.tag_position < 90])
    all_tags = db((db.tags.id > 0) &
                  (db.badges.tag == db.tags.id)
                  ).select()
    for set in set_list:
        set_tags = all_tags.find(lambda r: r.tags.tag_position == set)
        set_tags_info = [{'tag': r.tags.id, 'badge_title': r.badges.badge_name}
                         for r in set_tags]
        badge_set_dict[set] = set_tags_info

    query_visibility = user['hide_read_queries']
    print('QV is', query_visibility)

    return {'the_name': name,
            'user_id': user.id,
            'tz': tz,
            'email': email,
            'starting_set': starting_set,
            'target_set': target_set,
            'end_date': fmt_end,
            'cal': mycal,
            'blist': blist,
            'max_set': max_set,
            'badge_levels': badge_levels,
            'badge_table_data': badge_table_data,
            'badge_set_milestones': badge_set_milestones,
            'answer_counts': answer_counts,
            'chart1_data': chart1_data,
            'reviewing_set': session.set_review,
            'badge_set_dict': badge_set_dict,
            'query_visibility': query_visibility
            }