Skip to content

Commit 625bc4f

Browse files
committed
add --starttime flag, add option whether to back-fill unanswered questions to get_all_test_scores()
1 parent 787014d commit 625bc4f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

hackerrank.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ def list_test_candidates(self,test_id, fields=None, filters=None):
272272

273273
def invite_test_candidate(self,test_id,fullname,email,msg="",template=None,send_email=True,tags=None,addtime=0):
274274
arglist=[('email',email),
275-
('send_email',send_email)]
276-
# ('send_email','true' if send_email else 'false')]
275+
('send_email','true' if send_email else 'false')]
276+
# ('send_email',send_email)]
277277
if fullname:
278278
arglist.append(('full_name',fullname))
279279
if msg and msg != '':
@@ -287,7 +287,7 @@ def invite_test_candidate(self,test_id,fullname,email,msg="",template=None,send_
287287
arglist.append(('accommodations','{"additional_time_percent":'+str(addtime)+'}'))
288288
return self.post('tests/{}/candidates'.format(test_id),arglist)
289289

290-
def get_all_test_scores(self,test_id,include_incomplete=False,filters=None):
290+
def get_all_test_scores(self,test_id,all_questions=True,include_incomplete=False,filters=None):
291291
c_info = self.list_test_candidates(test_id,filters=filters)
292292
scores = []
293293
all_qs = set()
@@ -312,9 +312,9 @@ def get_all_test_scores(self,test_id,include_incomplete=False,filters=None):
312312
percent = cand['percentage_score']
313313
questions = cand['questions']
314314
for q in all_qs:
315-
if q not in questions:
315+
if q not in questions and all_questions:
316316
questions[q] = '0'
317-
elif questions[q] == int(questions[q]):
317+
elif q in questions and questions[q] == int(questions[q]):
318318
questions[q] = int(questions[q])
319319
plag = cand['plagiarism'] if cand['plagiarism_status'] == True else None
320320
scores += [{'id': id, 'fullname': fullname, 'email': email, 'andrew': andrew, 'score': score,
@@ -437,7 +437,7 @@ def late_score(score, late_penalty):
437437

438438
def feedback(self, q_info, late_penalty):
439439
if not q_info:
440-
return '\t0\t--total-- (missing or not yet submitted)'
440+
return '\t0\t--total-- (not yet submitted)'
441441
fb = ''
442442
total = 0.0
443443
for q_num in q_info:
@@ -713,6 +713,11 @@ def display_test_candidates(args, t_id):
713713
hr = HackerRank(verbose=args.verbose)
714714
c_list = hr.list_test_candidates(t_id)
715715
for c in c_list:
716+
if args.starttime:
717+
if 'attempt_starttime' in c:
718+
print(c['attempt_starttime'],end='\t')
719+
else:
720+
print('---\t')
716721
fname = c['full_name'] if 'full_name' in c else '{unknown}'
717722
andrew = HackerRank.get_Andrew_ID(c)
718723
plag = '**' if 'plagiarism_status' in c and c['plagiarism_status'] else ''
@@ -744,7 +749,7 @@ def display_score_details(args, t_id, c_id):
744749
for q in questions:
745750
# cache the question names
746751
hr.get_question_name(q)
747-
print('{}{} ({}) @ {}'.format(fname,andrew,c_info['email'],c_info['attempt_endtime']))
752+
print('{}{} ({}) @ {}-{}'.format(fname,andrew,c_info['email'],c_info['attempt_starttime'],c_info['attempt_endtime']))
748753
for q in questions:
749754
print('\t{}\t{}'.format(questions[q],hr.get_question_name(q)))
750755
print('{}%\t{}\tTotal'.format(percent,c_info['score']))
@@ -930,6 +935,7 @@ def parse_arguments(flag_adder = None):
930935
parser.add_argument("-T","--listtests",action="store_true",help="list available tests")
931936
parser.add_argument("-t","--showtest",action="store_true",help="display details of a test")
932937
parser.add_argument("-c","--listcandidates",action="store_true",help="display list of candidates taking test")
938+
parser.add_argument("--starttime",action="store_true",help="add attempt start time to candidate listing")
933939
parser.add_argument("-C","--candidatedetails",action="store_true",help="display detailed results of candidates taking test")
934940
parser.add_argument("-S","--testscore",action="store_true",help="display detailed score on test T by candidate C")
935941
parser.add_argument("-P","--plagiarism",action="store_true",help="analyze plagiarism flags for test")

0 commit comments

Comments
 (0)