示例#1
0
def undo_bug():
    '''
    Controller to receive ajax signal and trigger the Bug class method to undo
    the effects of a reported bug on the user's performance record.
    '''
    b = Bug(request.vars.step, request.vars.in_path, request.vars.map_location)
    u = b.undo(request.vars.id, request.vars.log_id, float(request.vars.score),
               request.vars.bug_status, request.vars.user_name,
               request.vars.admin_comment)
    return u
示例#2
0
def bug():
    """
    Create a new bug report for a step.
    """
    print 'controller.bug:'
    rvars = request.vars
    print 'vars are', rvars
    b = Bug(step_id=rvars.step_id, path_id=rvars.path_id, loc_id=rvars.loc_id)
    print 'created bug object successfully'
    print 'bug is', b
    logged = b.log_new(rvars.answer, rvars.log_id, rvars.score)
    print 'logged bug - response is', logged
    return dict(success=logged)
示例#3
0
def mark_bug_deleted():
    """
    Set the 'deleted' field for provided bug report based on boolean provided.

    Expects one value in request.args
    0:      The id of the bug (str)
    """
    bugid = int(request.args[0])
    return Bug.delete_bug(bugid)
示例#4
0
def submit_bug():
    """
    Create a new bug report for a step.
    The step_id is now being passed in as bug_step_id instead of step_id as it was
    Apparently conflicting with some other step id:  JOB <*****@*****.**> 20141003
    """
    vbs = True
    rvars = request.vars
    if vbs: print('creating::submit_bug: vars are', rvars)
    b = Bug(step_id=rvars.bug_step_id,
            path_id=rvars.path_id,
            loc_id=rvars.loc_id)
    if vbs: print('creating::submit_bug: created bug object successfully')
    # if vbs: print 'creating::submit_bug: bug is', b
    logged = b.log_new(rvars.answer,
                       rvars.log_id,
                       rvars.score,
                       rvars.bug_reporter_comment)
    if vbs: print('creating::submit_bug: logged bug - response is', logged)
    return {'success': logged}
示例#5
0
def update_bug_user_comment():
    """
    Update the user_comment field of the specified bugs record.

    Expects two request.args
    0:      The id of the bug (str)
    1:      A string containing the updated user comment text.
    """
    bugid = int(request.args[0])
    new_comment = {'user_comment': request.vars['mytext']}
    result = Bug.update_bug(bugid, new_comment)
    return 'false' if result is False else result
示例#6
0
def mark_bug_read():
    """
    Set the 'hidden' field for provided bug report based on boolean provided.

    Expects two request.args
    0:      The id of the bug (str)
    1:      A string representing a boolean value (str)
    """
    bugid = int(request.args[0])
    myval = True if request.args[1] == 'true' else False
    new_status = {'hidden': myval}
    result = Bug.update_bug(bugid, new_status)
    return 'false' if result is False else result
示例#7
0
def update_bug():
    """
    Update any field(s) of the specified bugs record.

    Expects one request.args
    0:      The id of the bug (str)

    Excpects one request.vars value for each field to be updated. The key for
    each value must be identical to the desired field in db.bugs.
    """
    bugid = int(request.args[0])
    new_vals = {'bug_status': int(request.vars['bug_status']),
                'admin_comment': request.vars['admin_comment'],
                'adjusted_score': float(request.vars['adjusted_score']) if
                request.vars['adjusted_score'] not in
                ['none', 'None'] else None
                }
    if 'score' in list(request.vars.keys()) and \
            request.vars['log_id'] not in ['None', 'none', None]:
        logrow = db.attempt_log(int(request.vars['log_id']))
        if logrow and logrow.score <= new_vals['adjusted_score']:
            undo_vals = copy(new_vals)
            extra_vals = {'step': int(request.vars['step']),
                          'in_path': int(request.vars['in_path']),
                          'map_location': int(request.vars['map_location']),
                          'id': int(bugid),
                          'log_id': int(request.vars['log_id']),
                          'score': float(request.vars['score']),
                          'user_name': int(request.vars['user_name']),
                          'user_comment': request.vars['user_comment'],
                          'user_response': request.vars['user_response']
                          }
            undo_vals.update(extra_vals)
            trigger_bug_undo(**undo_vals)

    result = Bug.update_bug(bugid, new_vals)

    return 'false' if result is False else result
示例#8
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 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
            }
示例#9
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
            }