559
def get_problem_status(self, login, exercisename, dry=False):
560
"""Given a login name and exercise name, returns information about the
561
user's performance on that problem.
563
- A boolean, whether they have successfully passed this exercise.
564
- An int, the number of attempts they have made up to and
565
including the first successful attempt (or the total number of
566
attempts, if not yet successful).
568
problemid = self.get_problem_problemid(exercisename)
569
loginid = self.get_user_loginid(login) # May raise a DBException
571
# ASSUME that it is completed, get the total number of attempts up to
572
# and including the first successful attempt.
573
# (Get the date of the first successful attempt. Then count the number
574
# of attempts made <= that date).
575
# Will return an empty table if the problem has never been
576
# successfully completed.
577
query = """SELECT COUNT(*) FROM problem_attempt
578
WHERE loginid = %d AND problemid = %d AND date <=
579
(SELECT date FROM problem_attempt
580
WHERE loginid = %d AND problemid = %d AND complete = TRUE
582
LIMIT 1);""" % (loginid, problemid, loginid, problemid)
584
result = self.db.query(query)
585
count = int(result.getresult()[0][0])
587
# The user has made at least 1 successful attempt.
588
# Return True for success, and the number of attempts up to and
589
# including the successful one.
592
# Returned 0 rows - this indicates that the problem has not been
594
# Return the total number of attempts, and False for success.
595
query = """SELECT COUNT(*) FROM problem_attempt
596
WHERE loginid = %d AND problemid = %d;""" % (loginid, problemid)
597
result = self.db.query(query)
598
count = int(result.getresult()[0][0])
599
return (False, count)
560
602
"""Close the DB connection. Do not call any other functions after
561
603
this. (The behaviour of doing so is undefined).