本文整理汇总了Python中course.Course类的典型用法代码示例。如果您正苦于以下问题:Python Course类的具体用法?Python Course怎么用?Python Course使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Course类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCourseIsTakeable
class TestCourseIsTakeable(unittest.TestCase):
def setUp(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
def test_takeable_one_prereq_satisfied(self):
self.c1.taken = True
self.assertTrue(self.c2.is_takeable)
def test_takeable_many_prereqs_satisfied(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
self.c3 = Course('CSC165', [self.c1])
self.c4 = Course('CSC207', [self.c1, self.c2, self.c3])
self.c1.taken = True
self.assertTrue(self.c2.is_takeable())
self.assertTrue(self.c3.is_takeable())
self.c2.taken = True
self.c3.taken = True
self.assertTrue(self.c4.is_takeable())
def test_not_takeable(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
self.assertFalse(self.c2.is_takeable())
def test_takeable_taken(self):
self.c1 = Course('CSC108')
self.c1.taken = True
self.assertTrue(self.c1.is_takeable())
示例2: Editor
class Editor(GameState):
"""Allows the user to edit a course."""
def __init__(self):
super(Editor, self).__init__()
self.next_state = "MAIN_MENU"
def startup(self, persistent):
"""Creates a Course object from the previously selected JSON file."""
self.persist = persistent
name = self.persist["course_name"]
filepath = os.path.join("resources", "courses", "{}.json".format(name))
with open(filepath, "r") as f:
course_info = json.load(f)
self.course = Course(course_info)
self.scroll_speed = .25
self.view_center = list(self.course.view_rect.center)
def save_to_json(self):
"""Saves location of all course objects to be loaded for future use."""
course_info = {
"map_name": self.course.map_name,
"map_size": self.course.map_size,
"obstacles": [[x.name, x.rect.midbottom] for x in self.course.obstacles]
}
filepath = os.path.join("resources", "courses", "{}.json".format(self.course.map_name))
with open(filepath, "w") as f:
json.dump(course_info, f)
def get_event(self, event):
if event.type == pg.QUIT:
self.save_to_json()
self.done = True
elif event.type == pg.KEYUP:
if event.key == pg.K_ESCAPE:
self.save_to_json()
self.done = True
def scroll(self, dt, mouse_pos):
"""Move the view rect when the mouse is at the edge of the screen."""
speed = self.scroll_speed * dt
x, y = mouse_pos
w, h = prepare.SCREEN_SIZE
if x < 20:
self.view_center[0] -= speed
elif x > w - 20:
self.view_center[0] += speed
if y < 20:
self.view_center[1] -= speed
elif y > h - 20:
self.view_center[1] += speed
self.course.view_rect.center = self.view_center
def update(self, dt):
mouse_pos = pg.mouse.get_pos()
self.scroll(dt, mouse_pos)
def draw(self, surface):
surface.fill(pg.Color(242, 255, 255))
self.course.draw(surface)
示例3: parse_course_table
def parse_course_table (p, tree, table):
courses = []
course_type_path = tree.getpath (table) + "/descendant::a[contains(@class, 'title')]/text()"
course_type = tree.xpath(course_type_path)[0]
codes_path = tree.getpath (table) + "/descendant::td[contains(@class, 'code')]/a"
codes = tree.xpath (codes_path)
codes_title_path = tree.getpath (table) + "/descendant::td[contains(@class, 'title')]/a/text()"
codes_title = tree.xpath (codes_title_path)
if len(codes) != len(codes_title):
print ("Error: lengths don't match with codes and codes_title")
return []
for i in range (len (codes)):
c = Course(codes[i].text)
c.type = parse_course_type (course_type)
c.name = codes_title[i]
c.link = codes[i].get ("href")
for e in codes_title[i].getparent().itersiblings():
if e.tag == "span" and e.get ("class") == "comment":
for p in e.iterchildren():
if p.tag == "p":
c.comment = p.text
courses.append (c)
return courses
示例4: TestCourseAddPrereq
class TestCourseAddPrereq(unittest.TestCase):
def setUp(self):
self.c1 = Course('Highschoolcalc')
self.c2 = Course('MAT136')
self.c3 = Course('MAT137', [self.c1])
self.c4 = Course('MAT237', [self.c2, self.c3])
def test_add_prereq_no_prereqs(self):
prereq = Course('MAT223')
self.c1.add_prereq(prereq)
self.assertEqual([prereq], self.c1.prereqs)
def test_add_prereqs_many_prereqs(self):
prereq = Course('MAT136')
self.c1.add_prereq(prereq)
self.assertEqual(prereq.name, self.c1.prereqs[-1].name)
def test_error_in_tree(self):
self.assertRaises(PrerequisiteError, self.c3.add_prereq, self.c1)
self.assertRaises(PrerequisiteError, self.c4.add_prereq, self.c1)
def test_error_in_prereq_tree(self):
self.assertRaises(PrerequisiteError, self.c1.add_prereq, self.c3)
self.assertRaises(PrerequisiteError, self.c1.add_prereq, self.c4)
def test_error_add_self(self):
self.assertRaises(PrerequisiteError, self.c3.add_prereq, self.c3)
示例5: TestCourseTake
class TestCourseTake(unittest.TestCase):
def setUp(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
self.c3 = Course('CSC207', [self.c2])
def test_take_prereq_satisfied(self):
self.c1.taken = True
self.assertFalse(self.c2.taken)
self.c2.take()
self.assertTrue(self.c2.taken)
def test_take_taken(self):
self.c1.taken = True
self.c1.take()
self.assertTrue(self.c1.taken)
def test_take_many_in_a_row(self):
self.c1.take()
self.c2.take()
self.c3.take()
self.assertTrue(self.c3.taken)
def test_take_error(self):
self.c1.taken = False
self.assertRaises(UntakeableError, self.c2.take)
示例6: Boarding
class Boarding(GameState):
def __init__(self):
super(Boarding, self).__init__()
def startup(self, persistent):
self.persist = persistent
name = self.persist["course_name"]
filepath = os.path.join("resources", "courses", "{}.json".format(name))
with open(filepath, "r") as f:
course_info = json.load(f)
self.course = Course(course_info)
x, y = self.course.map_rect.centerx, 50
self.player = Snowboarder((x, y))
pg.mouse.set_visible(False)
pg.mixer.music.load(prepare.MUSIC["wind"])
pg.mixer.music.set_volume(.7)
pg.mixer.music.play(-1)
def get_event(self, event):
if event.type == pg.KEYUP:
if event.key == pg.K_ESCAPE:
self.done = True
self.next_state = "MAIN_MENU"
pg.mouse.set_visible(True)
pg.mixer.music.fadeout(3000)
def update(self, dt):
keys = pg.key.get_pressed()
self.player.update(dt, keys, self.course.map_rect)
self.course.update(dt, self.player)
def draw(self, surface):
surface.fill(pg.Color(242, 255, 255))
self.course.draw(surface, self.player)
示例7: __make_schedule
def __make_schedule(requirements, current_schedule):
if len(requirements) == 0:
return current_schedule
requirement = requirements[0]
requirements = requirements[1:]
for course in requirement.valid_courses:
if len(Course.get_all_by_crn(course)) == 0:
raise Exception("No class in catalog; %s" % course)
for c in Course.get_all_by_crn(course):
# Check to see if this course conflicts with anything
conflicts = False
for c2 in current_schedule:
if c.timeslot.conflicts(c2.timeslot):
conflicts = True
break
if not conflicts:
# Make sure we can take it, then recurse
schedule = []
if not c.can_take(current_schedule, credit_hour_limit=max_credits):
schedule = __make_schedule(requirements, current_schedule)
if schedule == False:
continue
# If we still can't take it, continue
if not c.can_take(schedule, credit_hour_limit=max_credits):
continue
schedule += [c]
else:
schedule = __make_schedule(requirements, current_schedule + [c])
if schedule != False:
return schedule
return False
示例8: get_course_class_list
def get_course_class_list(self):
from algorithm.models import School, Department, Class, Prerequisite, Building, Room, Period, Lecturer, ClassInstance, ClassLab, Person, Role, PersonRole
from course_class import CourseClass
# This section takes values from the database and stores them in course clas list
print "This will print out all of the course classes currently in the database"
self.classes_list = []
all_course_class = ClassInstance.objects.all()
for ClassInstance in all_course_class:
lecturer = ClassInstance.idLecturer
new_prof = Professor()
new_prof.name = lecturer.Name
new_prof.id = lecturer.idLecturer
Class = ClassInstance.idClass
new_course = Course()
new_course.id = Class.idClass
new_course.name = Class.Class
new_course_class = CourseClass()
new_course_class.professor = new_prof
new_course_class.course = new_course
new_course_class.duration = 1
new_course_class.lab = False
new_course_class.id = ClassInstance.idClassInstance
self.classes_list.append(new_course_class)
self.num_classes += 1
for course_class in self.classes_list:
print "(Professer: %s Course: %s Durration: %d Lab: %d)" % (course_class.professor, course_class.course, course_class.duration, course_class.lab)
示例9: TestCourseMissingPrereqs
class TestCourseMissingPrereqs(unittest.TestCase):
def setUp(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
self.c3 = Course('CSC207', [self.c2])
self.c4 = Course('CSC208', [self.c3])
self.c5 = Course('CSC209', [self.c4])
self.c6 = Course('CSC301', [self.c5])
self.c7 = Course('CSC302', [self.c6])
def test_missing_prereqs_one_missing(self):
self.assertEqual(['CSC108'], self.c2.missing_prereqs())
def test_missing_prereqs_many_missing(self):
lst = ['CSC108', 'CSC148', 'CSC207', 'CSC208', 'CSC209', 'CSC301']
self.assertEqual(lst, self.c7.missing_prereqs())
def test_not_missing_prereq(self):
self.c1.taken = True
self.c2.taken = True
self.c3.taken = True
self.c4.taken = True
self.c5.taken = True
self.c6.taken = True
self.assertEqual([], self.c7.missing_prereqs())
示例10: setUp
def setUp(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
self.c3 = Course('CSC207', [self.c2])
self.c4 = Course('CSC208', [self.c3])
self.c5 = Course('CSC209', [self.c4])
self.c6 = Course('CSC301', [self.c5])
self.c7 = Course('CSC302', [self.c6])
示例11: create_program
def create_program ():
p = Program("Dummy Program")
for t, d in data:
c = Course (t)
c.short_desc = d
p.courses.append (c)
return p
示例12: TestCourseAddPrereq
class TestCourseAddPrereq(unittest.TestCase):
def setUp(self):
self.c3 = Course('alone101')
def test_add_prereq_no_prereqs(self):
prereq = Course('MAT223')
self.c3.add_prereq(prereq)
self.assertEqual([prereq], self.c3.prereqs)
示例13: test_takeable_many_prereqs_satisfied
def test_takeable_many_prereqs_satisfied(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
self.c3 = Course('CSC165', [self.c1])
self.c4 = Course('CSC207', [self.c1, self.c2, self.c3])
self.c1.taken = True
self.assertTrue(self.c2.is_takeable())
self.assertTrue(self.c3.is_takeable())
self.c2.taken = True
self.c3.taken = True
self.assertTrue(self.c4.is_takeable())
示例14: TestCourseTake
class TestCourseTake(unittest.TestCase):
def setUp(self):
self.c1 = Course('CSC108')
self.c2 = Course('CSC148', [self.c1])
def test_take_prereq_satisfied(self):
self.c1.taken = True
self.assertFalse(self.c2.taken)
self.c2.take()
self.assertTrue(self.c2.taken)
示例15: create_courses
def create_courses(roster_data, keep_df=None):
"""
Create Course objects by doing one pass of roster file and using info from fields
StudentID, coursename, TeacherID. Based on the 'keeplist', determine whether a course in mandatry
Return data frame with new column that contains list of Course objects
"""
# Track courses (Course objects) that are created; will eventually be added to main roster dataframe
course_list = []
for ix, row in roster_data.iterrows():
# Info for the course
sid = row["StudentID"]
course = row["coursename"]
teachID = row["TeacherID"]
subject = row["subject"]
# Does Course already exist
exists = False
for course_obj in course_list:
course_name = course_obj.course_name
teach_id = course_obj.teacher_id
if course == course_name and teachID == teach_id:
course_obj.add(sid)
course_list.append(course_obj)
exists = True
break
# Continue if course existed
if exists:
continue
else:
# Check if there is a keep list and, if so, check if this course shoudl be listed as mandatory
keep = False
if isinstance(keep_df, pd.DataFrame):
if course in keep_df["coursename"].tolist() or subject in keep_df["subject"].tolist():
keep = True
# Create new course
new_course = Course(course, teachID, subject, keep)
new_course.add(sid)
course_list.append(new_course)
roster_data["Course"] = course_list
return roster_data