Exemplo n.º 1
0
def handle_maths_game(json):

    if json['status'] == 'finish':
        finalScore = json['final_score']
        pre_record = Record.query.filter_by(
            score_type="math", record_date=datetime.now().date()).first()

        if pre_record is None:
            db.session.add(
                Record(email=session['ind_email'],
                       score_type="math",
                       score=finalScore))
            db.session.commit()
        else:
            pre_record.score = max(pre_record.score, finalScore)
            db.session.commit()

    emit('maths',
         json,
         broadcast=True,
         namespace='/individual/' + session['ind_uuid'])
    print('Maths received json: ' + str(json))
Exemplo n.º 2
0
def handle_body_game(json):
    emit('body',
         json,
         broadcast=True,
         namespace='/individual/' + session['ind_uuid'])
    print('Body received json: ' + str(json))
Exemplo n.º 3
0
def handle_nature_game(json):
    emit('nature',
         json,
         broadcast=True,
         namespace='/individual/' + session['ind_uuid'])
    print('Nature received json: ' + str(json))
Exemplo n.º 4
0
def handle_video_game(json):
    emit('music',
         json,
         broadcast=True,
         namespace='/individual/' + session['ind_uuid'])
    print('Music received json: ' + str(json))
Exemplo n.º 5
0
def game_nature():
    global qna, model, index2word_set, nature
    if request.method == 'GET':

        natureFilesPath = ROOT_DIR + '/static/nature/'
        naturefiles = [
            f for f in listdir(natureFilesPath)
            if isfile(join(natureFilesPath, f))
        ]
        naturefiles = [x for x in naturefiles if x != ".DS_Store"]

        random.shuffle(naturefiles)

        finalNatureFilesNames = naturefiles[0:5]

        finalNatureFilesPath = [('nature/' + x) for x in finalNatureFilesNames]

        onlyNames = []

        for musicName in finalNatureFilesNames:
            a, b = musicName.split(".")
            onlyNames.append(a)

        return render_template('nature-index.html',
                               finalNatureFilesPath=finalNatureFilesPath,
                               onlyNames=onlyNames)

    if request.method == 'POST':

        score = 0
        n_score = 0

        for key, value in request.form.to_dict().items():
            a, b = key.split("~")
            maxScore = 0
            value = value.lower()
            for ea in nature[a]['answers']:
                ea = ea.lower()
                maxScore = max(
                    maxScore,
                    SimilarityModel.predict(model, index2word_set, ea, value))
            if maxScore > 50.0:
                score += 1
            else:
                n_score += 1

        finalScore = (score / (score + n_score)) * 100

        pre_record = Record.query.filter_by(
            score_type="nature", record_date=datetime.now().date()).first()

        if pre_record is None:
            db.session.add(
                Record(email=session['ind_email'],
                       score_type="nature",
                       score=finalScore))
            db.session.commit()
        else:
            pre_record.score = max(pre_record.score, finalScore)
            db.session.commit()

        emit('nature', {
            'final_score': finalScore,
            "status": "finish"
        },
             broadcast=True,
             namespace='/individual/' + session['ind_uuid'])

        return "Your Feedback is submitted! This Window will automatically close shortly!!"
Exemplo n.º 6
0
def game_music():
    global qna, model, index2word_set
    if request.method == 'GET':

        musicFilesPath = ROOT_DIR + '/static/music/'
        musicfiles = [
            f for f in listdir(musicFilesPath)
            if isfile(join(musicFilesPath, f))
        ]
        musicfiles = [x for x in musicfiles if x != ".DS_Store"]

        random.shuffle(musicfiles)

        finalMusicFilesNames = musicfiles[0:5]

        finalMusicFilesPath = [('music/' + x) for x in finalMusicFilesNames]

        onlyNames = []

        for musicName in finalMusicFilesNames:
            a, b = musicName.split("-")
            onlyNames.append(a)

        return render_template('music-index.html',
                               finalMusicFilesPath=finalMusicFilesPath,
                               onlyNames=onlyNames)

    if request.method == 'POST':

        score = 0
        n_score = 0

        for key, value in request.form.to_dict().items():
            a, b, c = key.split("-")
            if c == value:
                score += 1
            else:
                n_score += 1

        finalScore = (score / (score + n_score)) * 100

        pre_record = Record.query.filter_by(
            score_type="musical", record_date=datetime.now().date()).first()

        if pre_record is None:
            db.session.add(
                Record(email=session['ind_email'],
                       score_type="musical",
                       score=finalScore))
            db.session.commit()
        else:
            pre_record.score = max(pre_record.score, finalScore)
            db.session.commit()

        emit('music', {
            'final_score': finalScore,
            "status": "finish"
        },
             broadcast=True,
             namespace='/individual/' + session['ind_uuid'])

        return "Your Feedback is submitted! This Window will automatically close shortly!!"
Exemplo n.º 7
0
def game_video():
    global qna, model, index2word_set
    if request.method == 'GET':

        video_name = 'v1'
        video_path = 'videos/' + video_name + '.mp4'
        listOfQuestions = []

        questions = qna[video_name]

        for key, value in questions.items():
            listOfQuestions.append(value["question"])

        return render_template('video-index.html',
                               listOfQuestions=listOfQuestions,
                               video_name=video_name,
                               video_path=video_path)

    if request.method == 'POST':

        score = 0
        n_score = 0

        for key, value in request.form.to_dict().items():
            a, b = key.split("-")
            exp_answers = qna[a][b]["answers"]
            maxScore = 0.0
            value = value.lower()
            for ea in exp_answers:
                ea = ea.lower()
                maxScore = max(
                    maxScore,
                    SimilarityModel.predict(model, index2word_set, ea, value))
            print(maxScore)

            if maxScore > 50.0:
                score += 1
            else:
                n_score += 1

        finalScore = (score / (score + n_score)) * 100

        pre_record = Record.query.filter_by(
            score_type="visual", record_date=datetime.now().date()).first()

        if pre_record is None:
            db.session.add(
                Record(email=session['ind_email'],
                       score_type="visual",
                       score=finalScore))
            db.session.commit()
        else:
            pre_record.score = max(pre_record.score, finalScore)
            db.session.commit()

        emit('video', {
            'final_score': finalScore,
            "status": "finish"
        },
             broadcast=True,
             namespace='/individual/' + session['ind_uuid'])

        return "Your Feedback is submitted! This Window will automatically close shortly!!"