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


Python Exercise.all方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import all [as 别名]
    def get(self):
        # task name token
        uid = self.request_string('uid', uuid.uuid4())

        yesterday = dt.date.today() - dt.timedelta(days=1)
        yesterday_dt = dt.datetime.combine(yesterday, dt.time())
        date = self.request_date('date', "%Y/%m/%d", yesterday_dt)
        start_dt, end_dt = ExerciseStatistic.date_to_bounds(date)

        exercises = self.request_string('exercises', '')
        exercises = [e for e in exercises.split(',') if e]
        if not exercises:
            exercises = [e.name for e in Exercise.all()]

        for exercise in exercises:
            logging.info("Creating task chain for %s", exercise)
            enqueue_task(exercise, start_dt, end_dt, None, uid, 0)
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:19,代码来源:__init__.py

示例2: get

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import all [as 别名]
   def get(self):
       exid = self.request.get('exid')
       exercise = Exercise.all().filter('name =', exid).get()

       exercise_videos = []
       for exercise_video in ExerciseVideo.all().filter('exercise =', exercise):
            v = exercise_video.video
            video_dict = {'youtube_id':  v.youtube_id,
                          'youtube_url': v.url,
                          'title': v.title, 
                          'description': v.description,
                          'keywords': v.keywords,                         
                          'readable_id': v.readable_id,
                          'ka_url': "http://www.khanacademy.org/video/%s" % (v.readable_id,)
                         }         
            exercise_videos.append(video_dict)

       self.response.out.write(json.dumps(exercise_videos, indent=4))
开发者ID:adamwulf,项目名称:old-khan,代码行数:20,代码来源:api.py

示例3: get

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import all [as 别名]
    def get(self):
        from exercises import attempt_problem

        login_user = UserData.current()
        exercises_list = [exercise for exercise in Exercise.all()]
        videos_list = [video for video in Video.all()]

        user_count = self.request_int('users', 5)
        for user_id in xrange(0, user_count):
            # Create a new user
            first_name = random.choice(CreateRandomGoalData.first_names)
            last_name = random.choice(CreateRandomGoalData.last_names)
            nickname = "%s %s" % (first_name, last_name)
            email = 'test_%[email protected]' % user_id
            user = users.User(email)

            logging.info("Creating user %s: (%i/%i)"
                % (nickname, user_id + 1, user_count))

            user_data = UserData.get_or_insert(
                key_name="test_user_%i" % user_id,
                user=user,
                current_user=user,
                user_id=str(user_id),
                moderator=False,
                last_login=datetime.now(),
                proficient_exercises=[],
                suggested_exercises=[],
                need_to_reassess=True,
                points=0,
                coaches=[login_user.user_email],
                user_email=email,
                user_nickname=nickname,
                )
            user_data.put()

            # Delete user exercise & video progress
            query = UserExercise.all()
            query.filter('user = ', user)
            for user_exercise in query:
                user_exercise.delete()

            query = VideoLog.all()
            query.filter('user = ', user)
            for user_video in query:
                user_video.delete()

            # Delete existing goals
            GoalList.delete_all_goals(user_data)

            for goal_idx in xrange(1, random.randint(-1, 4)):
                # Create a random goal
                obj_descriptors = []

                for objective in xrange(1, random.randint(2, 4)):
                    obj_descriptors.append({
                        'type': 'GoalObjectiveExerciseProficiency',
                        'exercise': random.choice(exercises_list)})

                for objective in xrange(1, random.randint(2, 4)):
                    obj_descriptors.append({
                        'type': 'GoalObjectiveWatchVideo',
                        'video': random.choice(videos_list)})

                title = first_name + "'s Goal #" + str(goal_idx)
                logging.info("Creating goal " + title)

                objectives = GoalObjective.from_descriptors(obj_descriptors,
                    user_data)
                goal = Goal(parent=user_data, title=title,
                    objectives=objectives)
                user_data.save_goal(goal)

                for objective in obj_descriptors:
                    if objective['type'] == 'GoalObjectiveExerciseProficiency':
                        user_exercise = user_data.get_or_insert_exercise(
                            objective['exercise'])
                        chooser = random.randint(1, 120)
                        if chooser >= 60:
                            continue
                        elif chooser > 15:
                            count = 1
                            hints = 0
                        elif chooser < 7:
                            count = 20
                            hints = 0
                        else:
                            count = 25
                            hints = 1
                        logging.info(
                            "Starting exercise: %s (%i problems, %i hints)" %
                            (objective['exercise'].name, count, hints * count))
                        for i in xrange(1, count):
                            attempt_problem(user_data, user_exercise, i, 1,
                                'TEST', 'TEST', 'TEST', True, hints, 0, False,
                                "TEST", 'TEST', '0.0.0.0')

                    elif objective['type'] == 'GoalObjectiveWatchVideo':
                        seconds = random.randint(1, 1200)
                        logging.info("Watching %i seconds of video %s"
#.........这里部分代码省略.........
开发者ID:johnfelipe,项目名称:server,代码行数:103,代码来源:handlers.py


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