Commit 214fd1e1 authored by Antoine PIGEAU's avatar Antoine PIGEAU
Browse files

Add the querie to retrieve the userId of the failed or succeed users.

parent e5021bd9
......@@ -838,11 +838,13 @@ class DatabaseManager:
try:
cursor = self.connection.cursor()
query = ("DELETE FROM "+ DatabaseManager.TABLE_USER_NAME)
query = ("DELETE FROM "+ DatabaseManager.TABLE_SUBSCRIPTION_NAME)
cursor.execute(query)
except:
print "DatabaseManager - removeAllUser error:", sys.exc_info()[0]
print "removeAllSubscription is done"
def getAllSubscriptions(self):
......@@ -1084,6 +1086,45 @@ class DatabaseManager:
except:
print "DatabaseManager - getSequences(idUser, idCourse) error:", sys.exc_info()[0], sys.exc_info()[1]
print "DatabaseManager - getUserSession(...) error:", sys.exc_info()[0], sys.exc_info()[1]
return idUsers
def getPremiumUsers(self, courseId, minScore, maxScore):
'''
retrieve the premium users that take the course courseId and got a mark higher or equal to minScore and strictly lower than maxScore
SELECT p.userid, s.score FROM premium p, subscription s WHERE p.userid = s.userid AND
DATE(p.startedat) <= DATE(s.signedat) AND DATE(p.endedat) >= DATE(s.endedat) AND s.score >= minScore AND s.score < maxScore AND s.courseId = courseId
return a list ((userId, score), ... (userId, score))
'''
idUsers = []
try:
self.connection.text_factory = str
cursor = self.connection.cursor()
query = ("SELECT p."+DatabaseManager.PREMIUM_COLUMN_USER_ID+", s."+DatabaseManager.SUBSCRIPTION_COLUMN_SCORE+" FROM "+ DatabaseManager.TABLE_PREMIUM_NAME+" p, "+
DatabaseManager.TABLE_SUBSCRIPTION_NAME+" s WHERE p."+DatabaseManager.PREMIUM_COLUMN_USER_ID+" = s."+DatabaseManager.SUBSCRIPTION_COLUMN_USER_ID+" AND "+
"DATE(p."+DatabaseManager.PREMIUM_COLUMN_STARTED_AT+") <= DATE(s."+DatabaseManager.SUBSCRIPTION_COLUMN_SIGNED_AT+") AND DATE(p."+
DatabaseManager.PREMIUM_COLUMN_ENDED_AT+") >= DATE(s."+DatabaseManager.SUBSCRIPTION_COLUMN_ENDED_AT+") AND s."+
DatabaseManager.SUBSCRIPTION_COLUMN_SCORE+" >= "+str(minScore)+" AND "+DatabaseManager.SUBSCRIPTION_COLUMN_SCORE+" < "+str(maxScore)+" AND "+
DatabaseManager.SUBSCRIPTION_COLUMN_COURSE_ID+" = "+str(courseId))
print str(query)
cursor.execute(query)
rows = cursor.fetchall()
for row in rows:
idUsers.append((row[0], int(row[1])))
except:
print "DatabaseManager - getPremiumUser(...) error:", sys.exc_info()[0], sys.exc_info()[1]
return idUsers
\ No newline at end of file
......@@ -265,13 +265,18 @@ class ScriptDatabaseManager:
for row in spamreader:
if firstLine != 0:
print str(row)
score = row[6]
if score == '':
score = '0'
databaseManager.addTupleInSubscription(row[0], # idCourse
row[1], # idSubscription
row[2], # signedAt
row[3], # endedAt
row[4], # canceledAt
row[5], # resultCreatedAt
row[6], # score
score, # score
row[7]) # idUser
#break
else:
......@@ -385,4 +390,5 @@ class ScriptDatabaseManager:
databaseManager.close()
return idParts
\ No newline at end of file
......@@ -50,7 +50,14 @@ databaseManager = DatabaseManager()
#databaseManager.createTableQuizz()
#databaseManager.createTablePremium()
scriptDatabaseManager.fillPremiumTable()
#scriptDatabaseManager.fillPremiumTable()
l = databaseManager.getPremiumUsers(DatabaseManager.COURSE_ID_JAVA, 0, 80)
print str(len(l))+": "+str(l)
databaseManager.close()
#scriptDatabaseManager.fillSubscriptionTable()
#sections = scriptDatabaseManager.getSectionsSequence(DatabaseManager.COURSE_ID_JAVA)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment