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


Python Exercise.select方法代码示例

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


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

示例1: handle_average

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import select [as 别名]
def handle_average(argv, Class, class_str, call_print_averages=True):
    '''Pass the appropriate data to get the corresponding averages.

    Keyword arguments:
    argv -- An array of command line arguments.
    Class -- The class in which to find the averages.
    class_str -- The stringified Classname (e.g., a Student class would be
    "Student").
    call_print_averages -- Boolean value to optionally print the averages
    '''
    arr = []
    for i in mean:
        i["pts_total"] = 0.0
        i["mean"] = 0.0
        i["num"] = 0
    for exercise in Exercise.select():
        compare = {"Student": exercise.student.id,
                   "Batch": exercise.student.batch.id,
                   "School": exercise.student.batch.school.id}
        if str(compare.get(class_str)) == str(argv[2]):
            get_average(exercise, argv)
    for i in range(0, len(mean)):
        if call_print_averages is True:
            print_averages(i)
        else:
            if print_averages(i, False) is not None:
                arr.append(print_averages(i, False))
    for student in Class.select():
        if str(student.id) == str(argv[2]):
            return arr
    print class_str + " not found"
开发者ID:bennettbuchanan,项目名称:holbertonschool-higher_level_programming,代码行数:33,代码来源:main.py

示例2: export_json

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import select [as 别名]
def export_json(argv):
    '''Export all data in JSON format.

    Keyword arguments:
    argv -- An array of command line arguments.
    '''
    data = []
    for school in School.select():
        dict = {"name": school.name}
        data.append(dict)

    '''Add the batches.'''
    for dict in data:
        batches = []
        for batch in Batch.select():
            if batch.school.name == dict["name"]:
                batch_dict = {}
                dict["batches"] = batches
                batch_dict["name"] = batch.name
                batches.append(batch_dict)

    '''Add the students in their batch.'''
    for dict in data:
        if dict.get("batches") is not None:
            for batch in dict.get("batches"):
                students = []
                for student in Student.select():
                    if str(student.batch.name) == str(batch["name"]):
                        student_dict = {}
                        batch["students"] = students
                        student_dict["first_name"] = student.first_name
                        student_dict["last_name"] = student.last_name
                        student_dict["age"] = student.age
                        students.append(student_dict)

    '''Add the exercises to the corresponding student.'''
    for dict in data:
        if dict.get("batches") is not None:
            for batch in dict.get("batches"):
                for student in batch["students"]:
                    exercises = []
                    for e in Exercise.select():
                        if e.student.first_name == student.get("first_name"):
                            exercsie_dict = {}
                            student["exercises"] = exercises
                            exercsie_dict["note"] = e.note
                            exercsie_dict["subject"] = e.subject
                            exercises.append(exercsie_dict)

    print json.dumps(data)
开发者ID:bennettbuchanan,项目名称:holbertonschool-higher_level_programming,代码行数:52,代码来源:main.py

示例3: print_all

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import select [as 别名]
def print_all(argv):
    '''Print all data in database, ordered with tab heirarchy.

    Keyword arguments:
    argv -- An array of command line arguments passed to the program.
    '''
    for school in School.select():
        print school
        for batch in Batch.select():
            if batch.school.id == school.id:
                print "\t" + str(batch)
                for student in Student.select():
                    if student.batch.id == batch.id:
                        print "\t\t" + str(student)
                        for exercise in Exercise.select():
                            if exercise.student.id == student.id:
                                print "\t\t\t" + str(exercise)
开发者ID:bennettbuchanan,项目名称:holbertonschool-higher_level_programming,代码行数:19,代码来源:main.py

示例4: len

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import select [as 别名]
	elif sys.argv[1] == 'print':
		if len(sys.argv) >= 3:
			if sys.argv[2] == 'school':
				for school in School.select():	
					print school
			elif sys.argv[2] == 'batch':
				for batch in Batch.select():
					print batch
			elif sys.argv[2] == 'user':
				for user in User.select():
					print user
			elif sys.argv[2] == 'student':
				for student in Student.select():
					print student
			elif sys.argv[2] == 'exercise':
				for exercise in Exercise.select():
					print exercise					
	elif sys.argv[1] == 'insert':
		if sys.argv[2] == 'school':
			school = School.insert(name=sys.argv[3]).execute()
			print "New school: " + str(School.select().where(School.id==school).get())
		elif sys.argv[2] == 'batch':
			batch = Batch.insert(school=sys.argv[3], name=sys.argv[4]).execute()
			print "New batch: "	+ str(Batch.select().where(Batch.id==batch).get())
		elif sys.argv[2] == 'student':
			if len(sys.argv) == 6:
				student = Student.insert(batch=sys.argv[3], age=sys.argv[4], last_name='', first_name=sys.argv[5]).execute()
			else:		
				student = Student.insert(batch=sys.argv[3], age=sys.argv[4], last_name=sys.argv[5], first_name=sys.argv[6]).execute()
			print "New student: " + str(Student.select().where(Student.id==student).get())
		elif sys.argv[2] == 'exercise':
开发者ID:tasneemfarag,项目名称:holbertonschool-higher_level_programming,代码行数:33,代码来源:main.py


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