当前位置: 首页>>代码示例>>Python>>正文


Python General.get_q_list方法代码示例

本文整理汇总了Python中oasis.lib.General.get_q_list方法的典型用法代码示例。如果您正苦于以下问题:Python General.get_q_list方法的具体用法?Python General.get_q_list怎么用?Python General.get_q_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oasis.lib.General的用法示例。


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

示例1: get_q_list

# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import get_q_list [as 别名]
def get_q_list(topic_id):
    """
    Return a list of questions, sorted by position.
    """
    # TODO: Duplicated in General.get_q_list ?

    def cmp_question_position(a, b):
        """Order questions by the absolute value of their positions
           since we use -'ve to indicate hidden.
        """
        return cmp(abs(a['position']), abs(b['position']))

    questionlist = General.get_q_list(topic_id, None, False)
    if questionlist:
        # At the moment we use -'ve positions to indicate that a question is
        # hidden but when displaying them we want to maintain the sort order.
        for question in questionlist:
            # Usually questions with position 0 are broken or uninteresting
            # so put them at the bottom.
            if question['position'] == 0:
                question['position'] = -10000
        questionlist.sort(cmp_question_position)
    else:
        questionlist = []

    return questionlist
开发者ID:colincoghill,项目名称:oasisqe,代码行数:28,代码来源:API.py

示例2: get_sorted_questions

# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import get_q_list [as 别名]
def get_sorted_questions(course_id, topic_id, user_id=None):
    """ Return a list of questions, sorted by position
    """

    def cmp_question_position(a, b):
        """Order questions by the absolute value of their positions
           since we use -'ve to indicate hidden.
        """
        return cmp(abs(a['position']), abs(b['position']))

    questionlist = General.get_q_list(topic_id, user_id, numdone=False)
    if questionlist:
        # Filter out the questions without a positive position unless
        # the user has prevew permission.
        canpreview = check_perm(user_id, course_id, "questionpreview")
        if not canpreview:
            questionlist = [question for question in questionlist
                            if question['position'] > 0]
        else:
            # At the moment we use -'ve positions to indicate that a question
            # is hidden but when displaying them we want to maintain the sort
            # order.
            for question in questionlist:
                # Usually questions with position 0 are broken or
                # uninteresting so put them at the bottom.
                if question['position'] == 0:
                    question['position'] = -10000
            questionlist.sort(cmp_question_position)
    else:
        questionlist = []
    return questionlist
开发者ID:colincoghill,项目名称:oasisqe,代码行数:33,代码来源:Practice.py

示例3: get_next_prev

# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import get_q_list [as 别名]
def get_next_prev(qt_id, topic_id):
    """ Find the "next" and "previous" qtemplates, by topic, position. """
    if not topic_id:
        return None, None
        # This is very inefficient, but with the way questions are stored,
        # I didn't see a better way. Could maybe be revisited some time?
    questionlist = General.get_q_list(topic_id, numdone=False)
    if questionlist:
        # Filter out the questions without a positive position
        questionlist = [question
                        for question in questionlist
                        if question['position'] > 0]
    else:
        questionlist = []
        # We need to step through the list finding the "next and previous" id's
    nextid = None
    foundprev = None
    previd = None
    foundcurrent = None
    for i in questionlist:
        if foundcurrent:
            nextid = int(i['qtid'])
            break
        if int(i['qtid']) == int(qt_id):
            foundprev = True
            foundcurrent = True
        if not foundprev:
            previd = int(i['qtid'])
        # previd and nextid should now contain the correct values
    # or None, if they are not valid (current_qtid is the first or
    # last question)
    return previd, nextid
开发者ID:tkanesh,项目名称:oasisqe,代码行数:34,代码来源:Practice.py

示例4: get_sorted_qlist_wstats

# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import get_q_list [as 别名]
def get_sorted_qlist_wstats(course_id, topic_id, user_id=None):
    """ Return a list of questions, sorted by position. With
        some statistics (may be expensive to calculate).
    """
    def cmp_question_position(a, b):
        """Order questions by the absolute value of their positions
           since we use -'ve to indicate hidden.
        """
        return cmp(abs(a['position']), abs(b['position']))

    questionlist = General.get_q_list(topic_id, user_id, numdone=False)
    if not questionlist:
        return []
        # Filter out the questions without a positive position unless
    # the user has prevew permission.
    questions = [question for question in questionlist
                 if question['position'] > 0]
    questions.sort(cmp_question_position)
    for question in questions:
        try:
            question['maxscore'] = DB.get_qt_maxscore(question['qtid'])
        except KeyError:
            question['maxscore'] = 0

        stats_1 = DB.get_student_q_practice_stats(user_id, question['qtid'], 3)
        if stats_1:  # Last practices
            # Date of last practice
            question['age'] = stats_1[(len(stats_1) - 1)]['age']
            question['ageseconds'] = stats_1[(len(stats_1) - 1)]['ageseconds']
            # Fetch last three scores and rate them as good, average or poor
            for attempt in stats_1:
                if question['maxscore'] > 0:
                    attempt['pscore'] = "%d%%" % ((attempt['score'] / question['maxscore']) * 100,)
                    attempt['rating'] = 2  # average
                    if attempt['score'] == question['maxscore']:
                        attempt['rating'] = 3  # good
                    if attempt['score'] == 0:
                        attempt['rating'] = 1  # poor

                else:  # don't have maxscore so don't make score a percentage
                    attempt['pscore'] = "%2.1f " % (attempt['score'],)
                    if attempt['score'] == 0:
                        attempt['rating'] = 1
            question['stats'] = stats_1
        else:
            question['stats'] = None
        stats_2 = DB.get_q_stats_class(course_id, question['qtid'])
        if not stats_2:  # no stats, make some up
            stats_2 = {'num': 0, 'max': 0, 'min': 0, 'avg': 0}
            percentage = 0
        else:
            if stats_2['max'] == 0:
                percentage = 0
            else:
                percentage = int(stats_2['avg'] / stats_2['max'] * 100)
        question['classpercent'] = str(percentage) + "%"
        user_stats = DB.get_prac_stats_user_qt(user_id, question['qtid'])
        if not user_stats:
            indivpercentage = 0
        else:
            if stats_2['max'] == 0:
                indivpercentage = 0
            else:
                indivpercentage = int(user_stats['avg'] / stats_2['max'] * 100)
        question['indivpercent'] = str(indivpercentage) + "%"
    return questions
开发者ID:colincoghill,项目名称:oasisqe,代码行数:68,代码来源:Practice.py


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