Exemplo n.º 1
0
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding users
        user = User(
            email='*****@*****.**',
            encrypted_password=encrypt('password'),
            name='john_doe'
        )
        student = Student(user, 'U1722')
        db.session.add(student)

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(topic_id=1, id=1, name='se', content='test')
        db.session.add(lesson)

        # adding questions
        qn_1 = Question(1, 1,'easy')
        db.session.add(qn_1)

        qn_2 = Question(1, 1,'medium')
        db.session.add(qn_2)
        
        db.session.commit()
def initializeLesson(topic_id, name, content, url_link):
    topic = topicRead(col='id', value=topic_id)
    if (topic):
        lastLessonID = getLastLessonID(topic_id=topic.id)
        return Lesson(topic_id, lastLessonID + 1, name, content, url_link)
    else:
        return False
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(topic_id=1, id=1, name='se', content='test')
        db.session.add(lesson)

        # adding users
        user = User('*****@*****.**', encrypt('password'), 'staff_name')
        staff = Staff(user)
        db.session.add(staff)

        # adding quizzes
        quiz = Quiz(1, 'quiz_name', True, '2020-03-21', '2020-03-22')
        db.session.add(quiz)

        db.session.commit()
Exemplo n.º 4
0
def save_lesson(day, student, html, verbose=True):
    soup = BeautifulSoup(html)
    data = [unicode(info.text) for info in soup.find_all('td')]
    #print data
    existing = student.lessons.filter_by(day=day,
                                         start_min=to_timestamp(
                                             data[0][:5])).first()
    if existing != None:
        return
    if verbose:
        print "Lektion sparad dag {}:".format(day)
        for info in data:
            print info.encode('utf8')
        print ""
    if len(data) < 6:
        data.append('')
    lesson = Lesson(day=day,
                    start_min=to_timestamp(data[0][:5]),
                    end_min=to_timestamp(data[0][-5:]),
                    subject=data[1],
                    info=data[2].strip(),
                    teachers=data[3],
                    _class=data[4],
                    rooms=data[5],
                    student=student)
    db.session.add(lesson)
    db.session.commit()
Exemplo n.º 5
0
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding users
        user_1 = User('*****@*****.**', encrypt('password'), 'student_1')
        student_1 = Student(user_1, 'U00000000A')
        db.session.add(student_1)

        user_2 = User('*****@*****.**', encrypt('password'), 'student_2')
        student_2 = Student(user_2, 'U00000000B')
        db.session.add(student_2)

        user_3 = User('*****@*****.**', encrypt('password'), 'teacher_1')
        staff_1 = Staff(user_3)
        db.session.add(staff_1)

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(1, 1, 'lesson_1', 'content')
        db.session.add(lesson)

        # adding quizzes
        quiz = Quiz(3, 'quiz_1', True, '2020-03-30', '2020-03-31')
        db.session.add(quiz)

        db.session.commit()
Exemplo n.º 6
0
    def test_lessonRead(self):

        # create a new Lesson object and add it to the database
        lesson = Lesson(topic_id=1, id=3, name='se', content='test')
        db.session.add(lesson)
        db.session.commit()

        # check that the record retrieved is correct (using col='name')
        print(
            '--- check that the record retrieved is correct (using col=\'name\')'
        )
        self.assertEqual(
            lessonRead(topic_id=1, col='name', value='se').name, 'se')

        # check that the record retrieved is correct (using col='id')
        print(
            '--- check that the record retrieved is correct (using col=\'id\')'
        )
        self.assertEqual(lessonRead(topic_id=1, col='id', value=3).name, 'se')

        # check that no record is retrieved (when value of col is unacceptable
        print(
            '--- check that no record is retrieved (when value of col is unacceptable'
        )
        self.assertFalse(lessonRead(topic_id=1, col='wrong_value', value=3))
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding users
        user = User(
            email='*****@*****.**',
            encrypted_password=encrypt('password'),
            name='john_doe'
        )
        student = Student(user, 'U1722')
        db.session.add(student)

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)
        
        # add lessons
        lesson = Lesson(topic_id='1', id='3', name='se', content='test')
        db.session.add(lesson)

        # add questions
        qn = Question('1', '3', 'easy')
        db.session.add(qn)

        # add questionChoice
        qc = initializeQuestionChoice(1,'A',False)
        db.session.add(qc)

        db.session.commit()
def handle_add_lesson_form(user_id):
    """Submit New Lesson plan and redirect to user home"""

    user = User.query.get(user_id)

    if "id" not in session or user.id != session['id']:
        flash('Please login to view.')
        return redirect('/login')

    form = AddLessonForm()

    resources = [(resource.title, resource.url) for resource in Resource.query.filter(Resource.user_id == user.id).all()]

    form.resources.choices = resources

    if form.validate_on_submit():
        title = form.title.data
        summary = form.summary.data
        date = form.add_lesson_date.data.strftime('%Y-%m-%d')
        resources = form.resources.data
        
        lesson = Lesson(
            title=title,
            summary=summary,
            date=date,
            user_id=user_id
        )

        db.session.add(lesson)
        db.session.commit()

        return redirect(f"/users/{user_id}/lessons")

    else:
        return render_template("lessons/new.html", user=user, form=form)
Exemplo n.º 9
0
def add_lesson_to_course(courseID):
    """Adds a lesson to a course"""

    form = request.form
    course = Course.query.get(courseID)

    try:
        lesson = Lesson(course_id=courseID,
                        title=form.get("title"),
                        num=form.get("num"),
                        date_due=form.get("date_due"))

        db.session.add(lesson)
        db.session.commit()

        for student in course.students_enrolled:

            assignment = Assignment(student_enrollment_id=student.id,
                                    lesson_id=lesson.id,
                                    complete=False,
                                    turned_in=False)

            db.session.add(assignment)
            db.session.commit()

        flash("Successfully added lesson")

    except:
        flash("Failed to add lesson")

    return redirect("/")
Exemplo n.º 10
0
def create():
    form = LessonForm()

    if form.validate_on_submit():
        print request.form
        #4/0
        lesson = Lesson()
        lesson.title = request.form.get('title')
        lesson.time = request.form.get('time')
        lesson.audience = request.form.get('audience')
        lesson.goals = request.form.get('goals')
        lesson.summary = request.form.get('summary')
        session.add(lesson)
        session.flush()

        for index, step_entry in enumerate(form.steps.entries):
            step = Step()
            step.title = step_entry.title.data
            step.body = step_entry.body.data
            step.order = index
            step.lesson = lesson
            session.add(step)
            session.flush()

        session.commit()
        return redirect(url_for('view', uid=lesson.id))

    return render_template('create.html', form=form)
Exemplo n.º 11
0
    def test_lesson_model(self):
        """Test basic model"""

        l = Lesson(title="Illinois History", date="2021-12-12", user_id=2222)

        db.session.add(l)
        db.session.commit()

        self.assertEqual(len(self.u2.lesson), 1)
def add_lesson():
    type1 = request.json['type1']
    message = request.json['message']

    #initialize lessons with info
    new_lesson = Lesson(type1, message)

    db.session.add(new_lesson)  #open the session
    db.session.commit()

    return lesson_schema.jsonify(new_lesson)
Exemplo n.º 13
0
 def get_lessons(self):
     cursor = self.conn.cursor()
     cursor.execute(
         'select l.id, l.name, u.id, u.email, u.first_name, u.middle_name, u.last_name, u.password, u.birth_date, u.entry_date, u.role from lessons as l, users as u where teacher_id=u.id;'
     )
     rows = cursor.fetchall()
     lessons = []
     for r in rows:
         teacher = User(*r[2:])
         lessons.append(Lesson(*r[:2], teacher))
     return lessons
Exemplo n.º 14
0
 async def post(self, request, current_user):
     try:
         req = request.json
         user = await Users.get_first('email', req['creator'])
         req['creator'] = user.id
         lesson = Lesson(**req)
         await lesson.create()
         return json({'success': True})
     except:
         logging.exception('err lesson.post')
         return json({'msg': 'error creating'}, status=500)
Exemplo n.º 15
0
 def get_marks(self):
     cursor = self.conn.cursor()
     cursor.execute(
         'select year, quarter, mark, t.*, s.*, l.id, l.name from journal as j, users as t, users as s, lessons as l where student_id = s.id and j.teacher_id = t.id and lesson_id = l.id'
     )
     rows = cursor.fetchall()
     marks = []
     for r in rows:
         teacher = User(*r[3:12])
         student = User(*r[12:21])
         lesson = Lesson(*r[21:], teacher)
         mark = Mark(*r[:3], teacher, student, lesson)
         marks.append(mark)
     return marks
Exemplo n.º 16
0
    def put(self):
        # This method will update a tutorial and its associated lessons
        from app import db
        from models import Tutorial, Lesson

        try:
            data = request.json

            tutorial = Tutorial.query.get(data['id'])

            if tutorial is None:
                return jsonify({
                    "succeed": False,
                    "info": "There is no tutorial with that id."
                })

            duplicatedTutorial = Tutorial.query.filter(
                Tutorial.title == data['title']).first()

            if duplicatedTutorial is not None:
                if duplicatedTutorial.id != int(data['id']):
                    return jsonify({
                        "succeed":
                        False,
                        "info":
                        "There is already a tutorial with the same title."
                    })

            tutorial.title = data['title']
            db.session.commit()

            Lesson.query.filter(Lesson.tutorial_id == data['id']).delete()
            db.session.commit()

            for lesson in data['lessons']:
                newLesson = Lesson(data['id'], lesson['title'],
                                   lesson['description'], lesson['link'])

                db.session.add(newLesson)
                db.session.commit()

            return jsonify({"succeed": True})
        except:
            #db.session.close()
            return jsonify({
                "succeed":
                False,
                "info":
                "Unexpected error has occured. Please try again."
            })
Exemplo n.º 17
0
    def test_getLastLessonID(self):

        # check that function returns 0 when no record in the table
        print('--- check that function returns 0 when no record in the table')
        self.assertEqual(getLastLessonID(1), 0)

        # create a new Lesson object and add it to the database
        lesson = Lesson(topic_id=1, id=1, name='se', content='test')
        db.session.add(lesson)
        db.session.commit()

        # check that function returns 1 when no record in the table
        print('--- check that function returns 1 when no record in the table')
        self.assertEqual(getLastLessonID(1), 1)
Exemplo n.º 18
0
    def test_lessonDelete(self):

        # create a new Lesson object and add it to the database
        lesson = Lesson(topic_id=1, id=3, name='se', content='test')
        db.session.add(lesson)
        db.session.commit()

        # check that record has been deleted (number of record in database -1)
        print(
            '--- check that record has been deleted (-1 number of record in database)'
        )
        self.assertEqual(len(Lesson.query.all()), 1)
        lessonDelete(topic_id=1, lesson_id=3)
        self.assertEqual(len(Lesson.query.all()), 0)
Exemplo n.º 19
0
    def post(self):
        _lesson_parser = reqparse.RequestParser()
        _lesson_parser.add_argument("class_name",
                                    type=str,
                                    required=True,
                                    help="This field cannot be blank.")

        data = _lesson_parser.parse_args()
        _class = Lesson(**data)

        try:
            _class.save_to_db()
        except:
            return {'message': 'Error trying to make a class'}, 500

        return {'message': 'You have made a class!'}, 201
Exemplo n.º 20
0
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(topic_id='1', id='3', name='se', content='test')
        db.session.add(lesson)

        db.session.commit()
Exemplo n.º 21
0
    def test_lessonUpdate(self):

        # create a new Lesson object and add it to the database
        lesson = Lesson(topic_id=1, id=3, name='se', content='test')
        db.session.add(lesson)
        db.session.commit()

        # update value of Lesson object
        lesson.name = 'softwareEngi'
        lessonUpdate()

        # fetch updated Lesson object from the database
        lesson = Lesson.query.filter_by(topic_id=1).filter_by(id=3).first()

        # check if value of Lesson object has been updated
        print('--- check if value of Lesson object has been updated')
        self.assertEqual(lesson.name, 'softwareEngi')
Exemplo n.º 22
0
 def get_lesson():
     """
     解析 JSON, 送去评分
     :return:
     """
     lesson_m = _r.rpop(MQ_LESSON_ANALYZE_INPUT)
     if lesson_m:
         logging.debug("Get redis[" + MQ_LESSON_ANALYZE_INPUT + "] message:%s" % (lesson_m,))
         message = json.loads(lesson_m)
         wt = Lesson()
         wt.message = lesson_m
         wt.lesson_id = message.get('lessonId')
         wt.sentences = message.get('sentences')
         wt.wav_path = message.get('audioPath')
         wt.language = message.get('language')
         return wt
     return None
Exemplo n.º 23
0
def test_asr():
    _wt = Lesson()
    _wt.wav_path = '/data/audio/001.wav'
    _wt.sentences = [
        {
            "id": 1001,
            "text": "Last week my four-year-old daughter Sally was invited to a children's party.",
            "asrText": "Last week my four-year-old daughter Sally was invited to a children's party"
        },
        {
            "id": 1002,
            "text": "I decided to take her by train.",
            "asrText": "I decided to take her by train"
        }
    ]

    _asr_result = get_report_by_wt(_wt)
    return _asr_result
Exemplo n.º 24
0
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding users
        user = User(email='*****@*****.**',
                    encrypted_password=encrypt('password'),
                    name='john_doe')
        student = Student(user, 'U1722')
        db.session.add(student)

        user = User(email='*****@*****.**',
                    encrypted_password=encrypt('password'),
                    name='staff')
        staff = Staff(user)
        db.session.add(staff)

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(topic_id='1', id='3', name='se', content='test')
        db.session.add(lesson)

        # adding questions
        qn = Question('1', '3', 'easy')
        db.session.add(qn)

        # adding quizzes
        qz = Quiz(2, 'quiz', True, '2020-03-21', '2020-03-22'
                  )  # staff id is 2 here, as it uses the fk of users table
        db.session.add(qz)

        # adding courses
        course = Course(index='cz3003')
        db.session.add(course)

        db.session.commit()
Exemplo n.º 25
0
def check(request):
    print "Request started. Segmenting..."
    body_unicode = request.body
    body = json.loads(body_unicode)
    data = body['photo']

    currtime = int(time.time())
    filename = 'files/' + str(currtime) + '.png'
    fh = open('files/' + filename, 'wb')
    fh.write(data.decode('base64'))
    fh.close()

    _, _, _, faces_paths, crop_tuples = detect_faces('files/' + filename)
    students = Student.objects.all()
    ids, matched_crop_tuples = recognize(faces_paths, crop_tuples, students)

    present_students = [student.name for student in students if student.pk in ids]
    absent_students = [student.name for student in students if student.pk not in ids]

    image = cv2.imread('files/' + filename)
    for ((xb, yb, xe, ye), _) in matched_crop_tuples:
        cv2.rectangle(image, (xb,yb), (xe, ye), (213, 72, 211), 7)

    for ((xb, yb, xe, _), sid) in matched_crop_tuples:
        xc = (xb + xe) / 2
        text = next(stud.name for stud in students if stud.pk == sid)
        fontSize = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, fontScale=2, thickness=5)
        print fontSize
        print xc
        offset = fontSize[0][0] / 2
        cv2.putText(image, text, (max(0, xc - offset), yb), cv2.FONT_HERSHEY_DUPLEX, 2, (171, 15, 169), 5)

    cv2.imwrite('files/' + filename, image)
    lesson = Lesson()
    lesson.name = "Mathematics"
    lesson.img = filename
    lesson.save()
    for student in students:
        if student.pk in ids:
            lesson.students.add(student)
    lesson.save()

    return JsonResponse({'present': present_students, 'absent': absent_students})
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # addingusers
        user = User(email='*****@*****.**',
                    encrypted_password=encrypt('password'),
                    name='john_doe')
        staff = Staff(user)
        db.session.add(staff)

        # adding courses
        course = Course(index='cz3003')
        db.session.add(course)

        # adding quizzes
        quiz = Quiz(
            staff_id=1,
            name="Quiz Test",
            is_fast=True,
            date_start='2020-03-01',
            date_end='2020-03-31',
        )
        db.session.add(quiz)

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(topic_id='1', id='3', name='se', content='test')
        db.session.add(lesson)

        # adding questions
        qn = Question('1', '3', 'easy')
        db.session.add(qn)

        db.session.commit()
Exemplo n.º 27
0
    def test_lessonListRead(self):

        # check that function returns the right result (when number of record = 0)
        print(
            '--- check that function returns the right result (when number of record = 0)'
        )
        self.assertEqual(len(lessonListRead()), 0)
        self.assertEqual(lessonListRead(), [])

        # create a new Lesson object and add it to the database
        lesson = Lesson(topic_id=1, id=1, name='lesson_1', content='content')
        db.session.add(lesson)
        db.session.commit()

        # check that function returns the right result (when number of record = 1)
        print(
            '--- check that function returns the right result (when number of record = 1)'
        )
        self.assertEqual(len(lessonListRead()), 1)
        self.assertEqual(lessonListRead()[0].name, 'lesson_1')
    def setUp(self):
        print('\r')
        # drop all tables in the database
        db.session.remove()
        db.drop_all()
        # crete all tables in the database
        db.create_all()

        # adding courses
        course = Course(index='cz3003')
        db.session.add(course)

        # adding users
        user = User(email='*****@*****.**',
                    encrypted_password=encrypt('password'),
                    name='staff')
        staff = Staff(user)
        db.session.add(staff)

        # adding quizzes
        qz = Quiz(1, 'quiz', True, '2020-03-21', '2020-03-22')
        db.session.add(qz)

        # adding topics
        topic = Topic(name='seng')
        db.session.add(topic)

        # adding lessons
        lesson = Lesson(topic_id=1, id=1, name='se', content='test')
        db.session.add(lesson)

        # adding questions
        qn = Question(1, 1, 'easy')
        db.session.add(qn)

        # adding RsQuizQuestionContain
        rs = initializeRsQuizQuestionContain(1, 1)
        db.session.add(rs)

        db.session.commit()
Exemplo n.º 29
0
    def test_lessonCreate(self):

        # create a new Lesson object
        lesson = Lesson(topic_id=1, id=3, name='se', content='test')

        # add Lesson object to the database
        lessonCreate(lesson)

        # retrieve all records from the table 'lessons'
        lesson_list = Lesson.query.all()

        # check that the number of record added is correct
        print('--- check that the number of record added is correct')
        self.assertEqual(1, len(lesson_list))

        # check that the value(s) of the Lesson object added is correct
        print(
            '--- check that the value(s) of the Lesson object added is correct'
        )
        self.assertEqual(lesson_list[0].topic_id, 1)
        self.assertEqual(lesson_list[0].id, 3)
        self.assertEqual(lesson_list[0].name, 'se')
        self.assertEqual(lesson_list[0].content, 'test')
Exemplo n.º 30
0
def addLesson(request):
    user = request.user
    if user.is_authenticated():
        lessonForm = LessonForm(request.POST)
        if request.method == 'POST':
            print(lessonForm)
            lesson = Lesson()
            if lessonForm.is_valid():
                print(lessonForm)
                lesson.group = lessonForm.cleaned_data['group']
                lesson.discipline = lessonForm.cleaned_data['discipline']
                lesson.dateAndTtime = lessonForm.cleaned_data['dateAndTtime']
                lesson.room = lessonForm.cleaned_data['room']
                lesson.lessonID = lessonForm.cleaned_data['lessonID']
                lesson.status = lessonForm.cleaned_data['status']
                lesson.user = lessonForm.cleaned_data['user']
                lesson.save()
                return HttpResponseRedirect('/admin')
        return render_to_response('dokladedit.html', {'form': lessonForm},
                                  context_instance=RequestContext(request))
    #text = """<html><body><h1>Hello world</h1><p>asdfgvbasdbg</p></body></html>"""
    #text2 = "hello again"
    #return HttpResponse(text)
    return render(request, 'vote/create.html', {})