From 257f12aa06503fa581ad30365e1c75b9ba220337 Mon Sep 17 00:00:00 2001 From: Raul9595 Date: Thu, 23 May 2019 19:49:59 +0530 Subject: [PATCH 1/4] User Submission History and User Stats User Submission History and User Stats --- server.py | 42 ++++++++++++++++++++++ views/stats.html | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 views/stats.html diff --git a/server.py b/server.py index 2c20ab1..8af37d8 100644 --- a/server.py +++ b/server.py @@ -81,6 +81,48 @@ def home(): def dashboard(): return bottle.template("dashboard.html", contests=contests) +@app.get("/stats") +@login_required +def statistics(): + with shelve.open(database_path) as submission_record: + sub_history = [ + ( + user, + [ + attempt + for attempt in submissions + ] + ) + for user, submissions in submission_record.items() + ] + sub_stats = [ + ( + user, + len( + [ + attempt.question + for attempt in submissions + if not(attempt.is_correct) + ] + ), + len( + [ + attempt.question + for attempt in submissions + if attempt.is_correct + ] + ), + len( + [ + attempt.question + for attempt in submissions + ] + ) + ) + for user, submissions in submission_record.items() + ] + return bottle.template("stats.html", sub_history=sub_history, sub_stats=sub_stats) + @app.get("/contest//") @login_required diff --git a/views/stats.html b/views/stats.html new file mode 100644 index 0000000..d4e6489 --- /dev/null +++ b/views/stats.html @@ -0,0 +1,92 @@ +% include('base.html', title="User Statistics") + +
+
+

User Statistics

+
+ + + + + + +
Submission History
+ + + + + + + + + + + % for name,attempts in sub_history : + % for records in attempts : + + + + + + + + + % end + % end + +
UsernameQuestion NumberTime submittedCorrect/Not CorrectContest
{{name}}{{records.question}}{{records.time.strftime("%d-%m-%Y %H:%M")}}{{records.is_correct}}{{records.contest}}
+ + + + + + +
Submission Statistics
+ % for name,incorrect,correct,total in sub_stats : + + + + + + + + + + + +
Total Submissions : {{total}}
+ % end + + + + +
+ \ No newline at end of file From 72b27f51f6d7182c73af1396476be31f021945d5 Mon Sep 17 00:00:00 2001 From: Raul9595 Date: Sun, 26 May 2019 09:36:27 +0530 Subject: [PATCH 2/4] Updated to latest code Updated to latest code --- views/stats.html | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/views/stats.html b/views/stats.html index d4e6489..329262b 100644 --- a/views/stats.html +++ b/views/stats.html @@ -4,6 +4,10 @@

User Statistics

+ @@ -14,29 +18,19 @@

User Statistics

- - - - - - + + + + - % for name,attempts in sub_history : - % for records in attempts : + % for sub_history in sub_history : - - - - - - + + + + % end - % end
UsernameQuestion NumberTime submittedCorrect/Not CorrectContestContestQuestion NumberTime submittedCorrect/Not Correct
{{name}}{{records.question}}{{records.time.strftime("%d-%m-%Y %H:%M")}}{{records.is_correct}}{{records.contest}}{{sub_history["code"]}}{{sub_history["question"]}}{{sub_history["time"].strftime("%d-%m-%Y %H:%M")}}{{sub_history["is_correct"]}}
@@ -46,15 +40,15 @@

User Statistics

- % for name,incorrect,correct,total in sub_stats : - + @@ -62,8 +56,6 @@

User Statistics

Total Submissions : {{total}}Total Submissions : {{sub_stats_total}}
- % end - From b43c17b1af731151246166cf5292a0147b324db3 Mon Sep 17 00:00:00 2001 From: Raul9595 Date: Wed, 12 Jun 2019 23:58:28 +0530 Subject: [PATCH 3/4] Removing redundant code Removing redundant code --- server.py | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/server.py b/server.py index b1e56bc..3bf333b 100644 --- a/server.py +++ b/server.py @@ -108,48 +108,6 @@ def dashboard(): contests = Contest.select().order_by(Contest.start_time) return bottle.template("dashboard.html", contests=contests) -@app.get("/stats") -@login_required -def statistics(): - with shelve.open(database_path) as submission_record: - sub_history = [ - ( - user, - [ - attempt - for attempt in submissions - ] - ) - for user, submissions in submission_record.items() - ] - sub_stats = [ - ( - user, - len( - [ - attempt.question - for attempt in submissions - if not(attempt.is_correct) - ] - ), - len( - [ - attempt.question - for attempt in submissions - if attempt.is_correct - ] - ), - len( - [ - attempt.question - for attempt in submissions - ] - ) - ) - for user, submissions in submission_record.items() - ] - return bottle.template("stats.html", sub_history=sub_history, sub_stats=sub_stats) - @app.get("/stats") @login_required From c1937936192a0348118a174f982bea6fc6f52049 Mon Sep 17 00:00:00 2001 From: Raul9595 Date: Thu, 27 Jun 2019 23:50:08 +0530 Subject: [PATCH 4/4] Added table to store Question status for specific user Added table to store Question status for specific user and display it --- server.py | 30 ++++++++++++++++++++++++++---- views/question.html | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 3bf333b..be8f29d 100644 --- a/server.py +++ b/server.py @@ -55,6 +55,15 @@ class Meta: database = db +class QuestionStatus(Model): + question = ForeignKeyField(Question) + user = TextField() + status = TextField() + + class Meta: + database = db + + class ContestProblems(Model): contest = ForeignKeyField(Contest, backref="questions") question = ForeignKeyField(Question) @@ -76,7 +85,7 @@ class Meta: db.connect() -db.create_tables([User, Session, Submission, ContestProblems, Contest, Question]) +db.create_tables([User, Session, Submission, ContestProblems, Contest, Question, QuestionStatus]) def login_required(function): @@ -236,9 +245,16 @@ def question(code, number): .dicts() .get() ) - return bottle.template( - "question.html", question_number=number, contest=code, question=statement - ) + user = Session.get(Session.token == bottle.request.get_cookie("s_id")).user + question_status = QuestionStatus.select().where((QuestionStatus.question == number) & (QuestionStatus.user == user)) + if question_status.count() == 0: + return bottle.template( + "question.html", question_number=number, contest=code, question=statement, question_status='Not Submitted' + ) + else: + return bottle.template( + "question.html", question_number=number, contest=code, question=statement, question_status='Submitted' + ) @app.get("/contest/") @@ -399,6 +415,12 @@ def file_upload(code, number): ) except Exception as e: bottle.abort(500, str(e)) + try: + QuestionStatus.get_or_create( + question=number, user=user, status='Attempted' + ) + except Exception as e: + bottle.abort(500, str(e)) if not ans: return "Wrong Answer!!" else: diff --git a/views/question.html b/views/question.html index de10aaa..4efd073 100644 --- a/views/question.html +++ b/views/question.html @@ -6,6 +6,7 @@

Submission Page

{{question["question_statement"]}}

+

Status : {{question_status}}

Download Test Case