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))
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!!"
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!!"
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!!"
def parent(): global clf, encoder if request.method == 'POST': email = str(request.form['email']) children = Parents.query.filter_by(parent_email=email).all() graph_scores = { "visual": [], "verbal": [], "math": [], "intrapersonal": [], "logical": [], "body": [], "musical": [], "nature": [] } graph_dates = [] child_email = "" if children is not None: for child in children: child_email = child.child_email N = 30 while (N >= 0): start_date = datetime.now() - timedelta(N) graph_dates.append(start_date.strftime('%d/%m')) N -= 1 for key, value in graph_scores.items(): record = Record.query.filter_by( email=child.child_email, score_type=key, record_date=start_date.date()).first() value.append( record.score ) if record is not None else value.append(0) # maze , math, music, video , natural , body input = [] features = [ "visual", "verbal", "math", "body", "musical", "logical", "intrapersonal", "nature" ] for feature in features: record = Record.query.filter_by(email=child_email, record_date=datetime.now().date(), score_type=feature).first() if record is not None: input.append(record.score) else: input.append(0) predicted = clf.predict([input]) career_name = list(encoder.inverse_transform(predicted)) return render_template('parent.html', graph_dates=graph_dates, graph_scores=graph_scores, child_email=child_email, career_name=career_name[0])