コード例 #1
0
ファイル: reporting.py プロジェクト: span007/paideia
def calendar():
    '''
    Provides a calendar with user activity information for a given month/year.
    Intended to be used via an ajax component on the user's profile and the
    instructor's user reports.
    '''
    user_id = request.args[0]
    year = request.args[1]
    month = request.args[2]

    s = Stats(user_id)
    cal = s.monthcal(year, month)

    return {'cal': cal}
コード例 #2
0
ファイル: default.py プロジェクト: monotasker/paideia
def get_chart1_data(user_id=None, set=None, tag=None):
    '''
    Fetch raw data to present in first user profile chart.

    This function is isolated so that it can be called directly from ajax
    controls on the chart itself, as well as programmatically from info().

    Returns:
        dict:

    '''
    # def milliseconds(dt):
    #     return (dt-datetime.datetime(1970,1,1)).total_seconds() * 1000
    user_id = user_id if user_id else auth.user_id
    stats = Stats(user_id)

    badge_set_milestones = stats.get_badge_set_milestones()
    answer_counts = stats.get_answer_counts(set=set, tag=tag)

    chart1_data = {'badge_set_reached': [{'date': dict['my_date'],
                                          'set': dict['badge_set']} for dict
                                         in badge_set_milestones],
                   'answer_counts': [{'date': dict['my_date'],
                                      'total': dict['right'] + dict['wrong'],
                                      'ys': [{'class': 'right',
                                              'y0': 0,
                                              'y1': dict['right']},
                                             {'class': 'wrong',
                                              'y0': dict['right'],
                                              'y1': dict['right'] +
                                              dict['wrong']}
                                             ],
                                      'ids': dict['ids']
                                      } for dict in answer_counts],
                   # above includes y values for stacked bar graph
                   # and 'ids' for modal presentation of daily attempts
                   }

    return {'chart1_data': chart1_data,
            'badge_set_milestones': badge_set_milestones,
            'answer_counts': answer_counts}
コード例 #3
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
            }
コード例 #4
0
ファイル: default.py プロジェクト: monotasker/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:
        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
            }