def create_assignments(db): assignments = [(2, 'debug45678', 'debug45678', True, 3600), (3, 'debug91234', 'debug91234', False, 1600), (4, 'debug56789', 'debug56789', False, 3600)] for a in assignments: assignment = SubjectAssignment(subject_id=a[0], mturk_assignment_id=a[1], mturk_hit_id=a[2], is_complete=a[3], expire_time=a[4]) db.session.add(assignment) db.session.commit()
def create_subject_assignment(subject_id, assignment_phase, assignment_id, hit_id, expire_time, ua_dict): assignment = SubjectAssignment(subject_id=subject_id, assignment_phase=assignment_phase, mturk_hit_id=hit_id, mturk_assignment_id=assignment_id, created_on=datetime.utcnow(), expire_time=expire_time, **ua_dict) db.session.add(assignment) db.session.commit() return assignment
def purge_subject_data(subject_id): subject_assignments = SubjectAssignment.get_all_by_subject_id(subject_id) if subject_assignments: for assignment in subject_assignments: responses = AssignmentResponse.all_by_assignment_id(assignment.id) if responses: responses.delete() db.session.add(responses) db.session.delete(assignment) db.session.add(assignment) db.session.commit() return
def demography(): subject = get_subject_by_user_id(current_user.id) assignment = SubjectAssignment.get(session['current_assignment_id']) form = DemographyForm(request.form) if form.validate_on_submit(): __logs__.info('Subject {0} demography data validated successfully') form.populate_obj(subject) db.session.add(subject) save_session_record(assignment.id, 'Reading') db.session.commit() return redirect(url_for('exp.reading')) return render_template('demography.html', form=form)
def purge_subject_assignment_data(assignment_id): assignment = SubjectAssignment.get(assignment_id) responses = AssignmentResponse.all_by_assignment_id(assignment.id) assessment_session = AssignmentSession.all_by_assignment_id(assignment.id) if responses: for response in responses: db.session.delete(response) db.session.commit() if assessment_session: for s in assessment_session: db.session.delete(s) db.session.commit() db.session.delete(assignment) db.session.commit() return
def get_latest_subject_assignment(subject_id, assignment_phase=None): assignment = SubjectAssignment.get_lastest_by_subject_id( subject_id, assignment_phase) return assignment
def get_assignment(assignment_id): return SubjectAssignment.get(assignment_id)
def all_subject_assignments(subject_id): return SubjectAssignment.get_all_by_subject_id(subject_id)