Skip to content

Commit

Permalink
Modify submission and add count all student
Browse files Browse the repository at this point in the history
  • Loading branch information
JaobsenYc committed Apr 13, 2021
1 parent 32719ef commit b70c107
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
43 changes: 37 additions & 6 deletions app/api/v1/quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
:copyright: © 2020 by the Lin team.
:license: MIT, see LICENSE for more details.
"""

from app.model.lin import User as LinUser
from flask import g, request, jsonify
from lin.exception import Success
from lin.jwt import group_required, login_required
from lin.redprint import Redprint

from app.exception.api import QuizNotFound
from app.model.lin.user import User
from app.exception.api import QuizNotFound, StrIndexError
from app.model.v1.quiz import Quiz
from lin.db import db

Expand All @@ -22,9 +22,9 @@ def get_quiz(id):
"""
获取id指定测试的信息
"""
quiz = Quiz.get(id=int(id))
quiz = Quiz.get(id=id)
if quiz:
return quiz
return quiz.expression
raise QuizNotFound


Expand All @@ -42,11 +42,16 @@ def search():

@quiz_api.route("", methods=["POST"])
def create_quiz():
"""
创建测试
"""
all_stu = LinUser.count_all_student()
with db.auto_commit():
book1 = Quiz()
book1.expression = request.json.get("expression")
book1.average_grade = 0
book1.submission = "0/100"
book1.already_submission=0
book1.submission = "0/"+ str(all_stu)
print(book1.expression)
db.session.add(book1)
return Success(12)
Expand All @@ -72,6 +77,32 @@ def update_quiz(id):
raise QuizNotFound


@quiz_api.route("/submission", methods=["GET"])
# @api.validate(
# headers=AuthorizationSchema,
# json=QuizInSchema,
# resp=DocResponse(Success(13)),
# tags=["测试"],
# )
def update_submission():
id = request.args.get("id")
score = float(request.args.get("score"))/100
quiz = Quiz.get(id=id)
al_sub = Quiz.get(id=id).already_submission
av_grade = Quiz.get(id=id).average_grade
all_stu = LinUser.count_all_student()
if quiz:
quiz.update(
id=id,
average_grade=(al_sub * av_grade + score) / (al_sub + 1),
already_submission=al_sub + 1,
submission=str(al_sub + 1) + "/" + str(all_stu),
commit=True,
)
return Success(13)
raise QuizNotFound


@quiz_api.route("/<int:id>", methods=["DELETE"])
def delete_quiz(id):
quiz = Quiz.get(id=id)
Expand Down
6 changes: 3 additions & 3 deletions app/api/v1/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def delete_quiz(id):
"""
传入id删除对应测试
"""
quiz = Submission.get(id=id)
if quiz:
submission = Submission.get(id=id)
if submission:
# 删除测试,软删除
quiz.delete(commit=True)
submission.delete(commit=True)
return Success(14)
raise QuizNotFound
8 changes: 6 additions & 2 deletions app/api/v1/ttg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

ttg_api = Redprint("ttg")


@ttg_api.route("/valid")
def valid():
"""
Expand All @@ -32,8 +33,10 @@ def truthtable_html():
parseTree = getParse(expression)
truthGen = truthTable(parseTree)
res = truthGen.generateTruthHtml()

return res


@ttg_api.route("/truthtable_json")
def truthtable_json():
"""
Expand All @@ -57,6 +60,7 @@ def truthtable_json():
res = truthGen.generateTruthJson()
return res


import json


Expand All @@ -69,7 +73,7 @@ def isCorrect():

expression = request.args.get("expression")
ans = request.args.get("ans")

quizid = request.args.get("quizid")
parseTree = getParse(expression)
truthGen = truthTable(parseTree)

Expand All @@ -86,4 +90,4 @@ def isCorrect():
score = format((len(ans) - diff) / (len(ans)) * 100, '.2f')
response = {'Correct': res == ans, 'Answer': res, 'Score': score}

return jsonify(response)
return jsonify(response)
10 changes: 10 additions & 0 deletions app/model/lin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ class User(LinUser):
def _set_fields(self):
self._exclude = ["delete_time", "create_time", "update_time"]

@classmethod
def count_all_student(cls) -> int:
result = db.session.query(func.count(manager.user_group_model.user_id)).filter(
manager.user_group_model.group_id == 3
)
count = result.scalar()
return count



@classmethod
def count_by_username(cls, username) -> int:
result = db.session.query(func.count(cls.id)).filter(
Expand Down

0 comments on commit b70c107

Please sign in to comment.