def index(): app.logger.info(session['round']) #app.logger.info(session['session_idd']) # seed = datetime.utcnow().microsecond # app.logger.info(randShots(seed)) if request.method == 'GET': # Just the button return render_template('randomize_get.html') else: # Generate Treatment time = datetime.utcnow() seed = time.microsecond assignment = randShots(seed) # Add Round session['round'] = (session['round'] + 1) # Record Things assign = models.Assignment(session_id=session['session_idd'], user_id=session['user_idd'], time=str(time), seed=seed, outcome=assignment, round_num=session['round']) db.session.add(assign) db.session.commit() return render_template('randomize_post.html', treat=assignment)
def make_fake_assignment(course, creator): return models.Assignment(name='hw1', points=3, display_name="CS 61A", templates="[]", course=course.key, creator=creator.key, max_group_size=4, due_date=datetime.datetime.now())
def handle_add(args): assignment = models.Assignment(title=args[2], desc=args[3], visible=bool(args[4]), date_due=datetime.date( int(args[5]), int(args[6]), int(args[7]))) db.session.add(assignment) db.session.commit() if assignment.visible: emails.send_email_users_new_asgn(assignment) return "Added assignment " + str(assignment) + " successfully."
def test_scores_forassign_w_fs_wo_scores(self): """Tests that fs scores are loaded""" assign = models.Assignment().put() user = models.User(email=['*****@*****.**']).put() backup = models.Backup(submitter=user, assignment=assign).put() subm = models.Submission(backup=backup).put() models.FinalSubmission(submitter=user, assignment=assign, submission=subm).put() user = user.get() self.assertNotEqual(user.get_final_submission(assign), None) self.assertFalse(user.scores_for_assignment(assign.get())[1])
def make_hw_assignment(course, creator): date = (datetime.datetime.now() + datetime.timedelta(days=2)) with open('app/seed/scheme_templates/scheme.py') as sc: templates = {} templates['scheme.py'] = sc.read(), return models.Assignment(name='cal/CS61A/sp15/hw1', points=2, display_name="Homework 1", templates=json.dumps(templates), course=course.key, creator=creator.key, max_group_size=4, due_date=date)
def make_future_assignment(course, creator): date = (datetime.datetime.now() + datetime.timedelta(days=365)) with open('app/seed/hog_template.py') as fp: templates = {} templates['hog.py'] = fp.read() templates['hogq.scm'] = fp.read() return models.Assignment( name='cal/CS61A/sp15/proj1', display_name="Hog", points=20, templates=json.dumps(templates), creator=creator.key, course=course.key, max_group_size=4, due_date=date, lock_date=date, )
def make_past_assignment(course, creator): date = (datetime.datetime.now() - datetime.timedelta(days=365)) with open('app/seed/scheme_templates/scheme.py') as sc, \ open('app/seed/scheme_templates/scheme_reader.py') as sr, \ open('app/seed/scheme_templates/tests.scm') as tests, \ open('app/seed/scheme_templates/questions.scm') as quest: templates = {} templates['scheme.py'] = sc.read(), templates['scheme_reader.py'] = sr.read(), templates['tests.scm'] = tests.read(), templates['questsions.scm'] = quest.read(), return models.Assignment(name='cal/61A/fa14/proj4', points=20, display_name="Scheme", templates=json.dumps(templates), course=course.key, creator=creator.key, max_group_size=4, due_date=date)
def test_assignment_comparator(self): """Tests that assignments can be compared like numbers... by due date""" creator_key = models.User(email=['*****@*****.**']).put() course = make_fake_course(creator_key.get()) assignment1 = make_fake_assignment(course, creator_key.get()) assignment2 = models.Assignment(name='hw1', points=3, display_name="CS 61A", templates="[]", course=course.key, creator=creator_key, max_group_size=4, due_date=datetime.datetime.now() + datetime.timedelta(days=3)) self.assertTrue(assignment2 < assignment1) self.assertFalse(assignment1 < assignment2) lst = [assignment1, assignment2] lst = sorted(lst) self.assertEqual(lst, [assignment2, assignment1])
def test_get_assignment(self): """ Tests the get_assignment will whine on multiple assignments """ models.Assignment(name=self.assignment_name).put() with self.assertRaises(BadValueError): self.API().get_assignment(self.assignment_name)
def populate(): """ Populate database with test data""" po1 = models.Officer(last_name='Tinkle', first_name='Ivana', race='BLACK', gender='F', employment_date=datetime(2000, 4, 4, 1, 1, 1), birth_year=1970, pd_id=1) po2 = models.Officer(last_name='Jass', first_name='Hugh', race='WHITE', gender='M', birth_year=1950, pd_id=1, employment_date=datetime(1996, 4, 4, 1, 1, 1)) po3 = models.Officer(last_name='Butz', first_name='Seymour', race='WHITE', gender='F', birth_year=1950, pd_id=1, employment_date=datetime(1983, 4, 4, 1, 1, 1)) po4 = models.Officer(last_name='Cuddleme', first_name='Haywood', middle_initial='U', race='HISPANIC', gender='F', birth_year=1950, pd_id=1, employment_date=datetime(2014, 4, 4, 1, 1, 1)) test_officers = [po1, po2, po3, po4] db.session.add_all(test_officers) db.session.commit() po1 = models.Officer.query.get(1) po2 = models.Officer.query.get(2) po3 = models.Officer.query.get(3) po4 = models.Officer.query.get(4) star1 = models.Assignment(star_no=1234, rank='COMMANDER', officer=po1) star2 = models.Assignment(star_no=5678, rank='PO', officer=po2) star3 = models.Assignment(star_no=9012, rank='CHIEF', officer=po3) star4 = models.Assignment(star_no=3456, rank='LIEUTENANT', officer=po4) test_assignments = [star1, star2, star3, star4] db.session.add_all(test_assignments) db.session.commit() image1 = models.Image(filepath='static/images/test_cop1.png') image2 = models.Image(filepath='static/images/test_cop2.png') image3 = models.Image(filepath='static/images/test_cop3.png') image4 = models.Image(filepath='static/images/test_cop4.png') test_images = [image1, image2, image3, image4] db.session.add_all(test_images) db.session.commit() face1 = models.Face(officer_id=1, img_id=1) face2 = models.Face(officer_id=2, img_id=2) face3 = models.Face(officer_id=3, img_id=3) face4 = models.Face(officer_id=4, img_id=4) test_faces = [face1, face2, face3, face4] db.session.add_all(test_faces) db.session.commit()
def setUp(self): super(FinalSubmissionTest, self).setUp() self.courses = { "first": models.Course(institution="UC Awesome", display_name="First Course", instructor=[self.accounts['admin'].key]), "second": models.Course(institution="UC Awesome", display_name="Second Course", instructor=[self.accounts['admin'].key]), } for course in self.courses.values(): course.put() for student in ["student0", "student1", "student2"]: models.Participant.add_role(self.accounts[student], self.courses['first'], constants.STUDENT_ROLE) self.assignments = { "first": models.Assignment(name="first", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="first display", templates="{}", max_group_size=3, due_date=NOW + datetime.timedelta(days=1)), } for assign in self.assignments.values(): assign.put() self.assign = self.assignments["first"] self.backups = { "first": models.Backup( submitter=self.accounts["student0"].key, assignment=self.assignments["first"].key, messages=[ models.Message(kind='file_contents', contents={"trends.py": ""}) ], ), "second": models.Backup( submitter=self.accounts["student1"].key, assignment=self.assignments["first"].key, messages=[ models.Message(kind='file_contents', contents={"trends.py": ""}) ], ), "third": models.Backup( submitter=self.accounts["student2"].key, assignment=self.assignments["first"].key, messages=[ models.Message(kind='file_contents', contents={"trends.py": ""}) ], ), } for backup in self.backups.values(): backup.put()
def generate_demo_data(session: Session): """Generates demonstration data from models""" # check that the db is empty if session.query(models.User).first(): log.info("Data already exists, skipping data generation.") return log.info("Generating demo data.") user = models.User( name="Tom Hill", email="*****@*****.**", password_hash=security.get_password_hash("password"), stripe_customer_id=stripe.Customer.create()["id"], ) session.add(user) session.commit() session.refresh(user) discrete_maths = models.Course( name="Introduction to Reinforcement Learning", code="RL479", description="description", status="completing", due="2021-12-12", syllabus=[ { "id": 1, "name": "Introduction to Reinforcement Learning", "completed": False, }, { "id": 2, "name": "Exploration and Control", "completed": False }, { "id": 3, "name": "MDPs and Dynamic Programming", "completed": False }, { "id": 4, "name": "Fundementals of Dynamic Programming Algorithms", "completed": False, }, { "id": 5, "name": "Model-Free Prediction", "completed": False }, { "id": 6, "name": "Model-Free Control", "completed": False }, { "id": 7, "name": "Function Approximation", "completed": False }, { "id": 8, "name": "Planning & Models", "completed": False }, { "id": 9, "name": "Policy-Gradient and Actor-Critic Methods", "completed": False, }, { "id": 10, "name": "Approximate Dynamic Programming", "completed": False }, { "id": 11, "name": "Multi-Step & Off Policy", "completed": False }, { "id": 12, "name": "Deep RL 1", "completed": False }, { "id": 13, "name": "Deep RL 2", "completed": False }, ], cover={"color": "#8bbeb2"}, user_id=user.id, ) maths = models.Topic(name="mathematics") algebra = models.Topic(name="algebra") session.add_all([discrete_maths, maths, algebra]) session.commit() session.refresh(maths) session.refresh(algebra) # could try session.expire_all() instead? linear_algebra = models.Resource( name="Interactive Linear Algebra", url="http://textbooks.math.gatech.edu/ila/index.html", user_id=user.id, topics=[maths, algebra], ) big_exam = models.Assignment( name="Big Exam", description="Examination of:Set theory, Proof, Graph Theory", due="2021-12-12", course_id=discrete_maths.id, status="in_progress", weight=50, ) session.add_all([linear_algebra, big_exam]) session.commit()
def setUp(self): #pylint: disable=invalid-name super(BaseUnitTest, self).setUp() self.accounts = self.get_accounts() for user in self.accounts.values(): user.put() self.courses = { "first": models.Course(institution="UC Awesome a", instructor=[self.accounts['admin'].key]), "second": models.Course(institution="UC Awesome b", instructor=[self.accounts['admin'].key]), } for course in self.courses.values(): course.put() self.enroll("student0", "first", STUDENT_ROLE) self.enroll("student1", "first", STUDENT_ROLE) self.enroll("student2", "second", STUDENT_ROLE) self.enroll("staff", "first", STAFF_ROLE) self.assignments = { "first": models.Assignment(name="first", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="first display", templates="{}", max_group_size=3, due_date=datetime.datetime.now()), "second": models.Assignment(name="second", points=3, creator=self.accounts["admin"].key, course=self.courses['second'].key, display_name="second display", templates="{}", max_group_size=3, due_date=datetime.datetime.now()), "empty": models.Assignment(name="empty", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="second display", templates="{}", max_group_size=4, due_date=datetime.datetime.now()), } for assign in self.assignments.values(): assign.put() self.backups = { "first": models.Backup( submitter=self.accounts["student0"].key, assignment=self.assignments["first"].key, ), "second": models.Backup( submitter=self.accounts["student1"].key, assignment=self.assignments["first"].key, ), "third": models.Backup( submitter=self.accounts["student2"].key, assignment=self.assignments["second"].key, ), } for backup in self.backups.values(): backup.put() self.submissions = { "first": models.Submission(backup=self.backups["first"].key), "second": models.Submission(backup=self.backups["second"].key), "third": models.Submission(backup=self.backups["third"].key), } for submission in self.submissions.values(): submission.put() self.groups = { 'group1': models.Group(member=[ self.accounts['student0'].key, self.accounts['student1'].key ], assignment=self.assignments['first'].key) } self.groups['group1'].put() group_backup = models.Backup( submitter=self.accounts['student0'].key, assignment=self.assignments['first'].key, ) group_backup.put() self.backups['group'] = group_backup group_submission = models.Submission(backup=group_backup.key) group_submission.put() self.submissions['group'] = group_submission self.queues = { "first": models.Queue( assignment=self.assignments["first"].key, assigned_staff=[self.accounts["staff"].key], ), } for queue in self.queues.values(): queue.put() self.diffs = {"first": models.Diff()} for diff in self.diffs.values(): diff.put() self.comments = { "first": models.Comment(author=self.accounts['student0'].key, diff=self.diffs["first"].key, message="First comment"), } for comment in self.comments.values(): comment.put() self.user = None
def test_scores_forassign_wo_fs(self): """Tests that missing fs doesn't crash method""" assign = models.Assignment().put().get() user = models.User(email=['*****@*****.**']).put().get() self.assertEqual(user.scores_for_assignment(assign), ([[user.email[0], 0, None, None, None]], False))