diff --git a/server.py b/server.py index f1f874d..e261920 100644 --- a/server.py +++ b/server.py @@ -73,7 +73,6 @@ class Meta: db.connect() db.create_tables([User, Session, Submission, ContestProblems, Contest, Question]) - # dummy contest data practiceContest = Contest.get_or_create( code="PRACTICE", @@ -123,6 +122,8 @@ def login_required(function): def login_redirect(*args, **kwargs): if not logggedIn(): return bottle.template("home.html", message="Login required.") + me = Session.get(Session.token == bottle.request.get_cookie("s_id")) + bottle.request.session = me return function(*args, **kwargs) return login_redirect @@ -147,6 +148,33 @@ def dashboard(): return bottle.template("dashboard.html", contests=contests) +@app.get("/stats") +@login_required +def statistics(): + sub_history = ( + Submission.select( + Contest.code, + ContestProblems.question, + Submission.time, + Submission.is_correct, + ) + .where(Submission.user == bottle.request.session.user) + .join(ContestProblems, on=(Submission.contestProblem == ContestProblems.id)) + .switch() + .join(Contest, on=(ContestProblems.contest == Contest.id)) + .order_by(Submission.time.desc()) + .dicts() + ) + sub_stats_total = len(sub_history) + sub_stats_correct = len([sub_history for sub in sub_history if sub["is_correct"]]) + return bottle.template( + "stats.html", + sub_history=sub_history, + sub_stats_correct=sub_stats_correct, + sub_stats_total=sub_stats_total, + ) + + @app.get("/contest//") @login_required def question(code, number): @@ -232,6 +260,7 @@ def rankings(): ] return bottle.template("rankings.html", people=order) + def logggedIn(): if not bottle.request.get_cookie("s_id"): return False diff --git a/views/dashboard.html b/views/dashboard.html index 91974be..95e17ee 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -24,6 +24,7 @@

Contests

diff --git a/views/stats.html b/views/stats.html new file mode 100644 index 0000000..329262b --- /dev/null +++ b/views/stats.html @@ -0,0 +1,84 @@ +% include('base.html', title="User Statistics") + +
+
+

User Statistics

+
+ + + + + + + +
Submission History
+ + + + + + + + + % for sub_history in sub_history : + + + + + + + % end + +
ContestQuestion NumberTime submittedCorrect/Not Correct
{{sub_history["code"]}}{{sub_history["question"]}}{{sub_history["time"].strftime("%d-%m-%Y %H:%M")}}{{sub_history["is_correct"]}}
+ + + + + + +
Submission Statistics
+ + + + + + + + + + + +
Total Submissions : {{sub_stats_total}}
+ + + +
+ \ No newline at end of file