Commit bb1ce837 authored by Bo's avatar Bo
Browse files

Creates the function that get the average duration of the special part

in the course.
parent 36e16051
......@@ -4,3 +4,4 @@
/sequences/
/CSV/
/csv/
/txt/
......@@ -12,23 +12,25 @@ import math
import os
import pickle
from asyncore import read
from lib2to3.pgen2.tokenize import Special
from pattern.metrics import duration
databaseManager = DatabaseManager()
scriptDatabaseManager = ScriptDatabaseManager()
#list = [(1946116, [(1, [(2,2,3,'lin'), (1,0,3,'liu'), (2,6,7,'huang'), (6,8,2,'luo')])])]
# list = [(1946116, [('d&FcEDw/kJSu6', [(2,2,3,'lin'), (1,0,3,'liu'), (2,6,7,'huang'), (6,8,2,'luo')])])]
# list = [(1, [(2,2,3,'lin'), (1,0,3,'liu'), (2,6,7,'huang'), (6,8,2,'luo')])]
# list = [(1946116, [('d&FcEDw/kJSu6', [(2,2,3), (1,0,3), (2,6,7), (6,8,2)])])]
# print list
# #
# #
#
# print str(list[0])
# (course, resultSequence) = list[0]
# print resultSequence
# (user, sequence) = resultSequence[0]
# print sequence
# #
#
# print sequence[0][0]
# print sequence[0][1]
# print sequence[0][2]
#
# sum = 0
# ave = 0
......@@ -37,23 +39,96 @@ scriptDatabaseManager = ScriptDatabaseManager()
# ave = float(sum)/float(len(sequence))
# print ave
# #
# l = scriptDatabaseManager.getSequencesSucceedPremium(DatabaseManager.COURSE_ID_AUDACE_ENTREPRENDRE)
# print l
# print "l"
# (idCourse, firstSequence) = l[0]
#
# print firstSequence
# print "first"
# (idUser, secondSequence) = firstSequence[0]
# print secondSequence
# print "second"
#
# idPart = list()
# idSession = list()
# duration = list()
#
# for index in range(0,len(secondSequence)):
# idPart.append(secondSequence[index][0])
# idSession.append(secondSequence[index][1])
# duration.append(secondSequence[index][2])
#
# print idPart
# print "idpart"
#
# finalSequence = list()
#
# for i in range(0,len(secondSequence)):
# finalSequence.append((idPart[i], idSession[i], duration[i]))
# print finalSequence
# print "final"
#
# sum = 0
# ave = 0
#
l = scriptDatabaseManager.getSequencesSucceedPremium(DatabaseManager.COURSE_ID_AUDACE_ENTREPRENDRE)
print l
(idCourse, firstSequence) = l[0]
print firstSequence
(idUser, finalSequence) = firstSequence[0]
print finalSequence
sum = 0
ave = 0
for index in range(0,len(finalSequence)):
sum = sum + finalSequence[index][2]
ave = float(sum)/float(len(finalSequence))
print ave
#
# def aver(self,list):
# (idCourse, resultSequence) = list[0]
# (idUser, sequence) = list[0]
#
\ No newline at end of file
# for index in range(0,len(finalSequence)):
# if finalSequence[index][0] == 1946116:
# sum = sum + finalSequence[index][2]
# ave = float(sum)/float(len(finalSequence))
# print ave
def averageDuration(idCourse, idPart, kind):
'''
get the average duration of the special part in the special course
'''
scriptDatabaseManager =ScriptDatabaseManager()
list, sum, ave = [], 0 ,0
if kind == 'Succeed':
list = scriptDatabaseManager.getSequencesSucceedPremium(idCourse)
print ("Succeed")
elif kind == 'Failed':
list = scriptDatabaseManager.getSequencesFailedPremium(idCourse)
print ("Failed")
else:
print ("Wrong entrance type")
(idCourse, firstSequence) = list[0]
(idUser, secondSequence) = firstSequence[0]
# partid = list()
# sessionid = list()
# duration = list()
#
# for index in range(0,len(secondSequence)):
# partid.append(secondSequence[index][0])
# sessionid.append(secondSequence[index][1])
# duration.append(secondSequence[index][2])
#
# finalSequence = list()
#
# for i in range(0,len(secondSequence)):
# finalSequence.append((partid[i], sessionid[i], duration[i])
# for index in range(0,len(finalSequence)):
# if finalSequence[index][0] == idPart:
# sum = sum + finalSequence[index][2]
# ave = float(sum)/float(len(finalSequence))
# return ave
for index in range(0,len(secondSequence)):
if secondSequence[index][0] == idPart:
sum = sum + secondSequence[index][2]
ave = float(sum)/float(len(secondSequence))
return ave
scriptDatabaseManager.close()
ave = averageDuration(DatabaseManager.COURSE_ID_AUDACE_ENTREPRENDRE, 1946116, 'Succeed')
print ave
\ No newline at end of file
......@@ -118,7 +118,7 @@ class DatabaseManager:
'''
open the connection to the database
'''
self.connection = sqlite3.connect(os.path.join('..', 'database', 'Z:\\internship\\data\\dataset-hubble-data2.db'))
self.connection = sqlite3.connect(os.path.join('..', 'database', 'dataset-hubble-data2.db'))
def close(self):
'''
......
......@@ -149,7 +149,7 @@ class ScriptDatabaseManager:
'''
databaseManager = DatabaseManager()
with open(os.path.join('..', 'dataraw2', 'Z:\\internship\\data\\0503\\dataraw2\\user_data.csv'), 'rb') as csvfile: # rb for read binary
with open(os.path.join('..', 'dataraw2', 'dataraw2\\user_data.csv'), 'rb') as csvfile: # rb for read binary
spamreader = csv.reader(csvfile, delimiter=";")
firstLine = 0
......@@ -179,7 +179,7 @@ class ScriptDatabaseManager:
'''
databaseManager = DatabaseManager()
with open(os.path.join('..', 'dataraw2', 'Z:\\internship\\data\\0503\\dataraw2\\user_course_exercises_quizz_result.csv'), 'rb') as csvfile: # rb for read binary
with open(os.path.join('..', 'dataraw2', 'dataraw2\\user_course_exercises_quizz_result.csv'), 'rb') as csvfile: # rb for read binary
spamreader = csv.reader(csvfile, delimiter=";")
firstLine = 0
......@@ -212,7 +212,7 @@ class ScriptDatabaseManager:
'''
databaseManager = DatabaseManager()
with open(os.path.join('..', 'dataraw2', 'Z:\\internship\\data\\0503\\dataraw2\\user_data_premium.csv'), 'rb') as csvfile: # rb for read binary
with open(os.path.join('..', 'dataraw2', 'dataraw2\\user_data_premium.csv'), 'rb') as csvfile: # rb for read binary
spamreader = csv.reader(csvfile, delimiter=";")
firstLine = 0
......@@ -236,7 +236,7 @@ class ScriptDatabaseManager:
'''
databaseManager = DatabaseManager()
with open(os.path.join('..', 'dataraw2', 'Z:\\internship\\data\\0503\\dataraw2\\CoursesStructures.csv'), 'rb') as csvfile: # rb for read binary
with open(os.path.join('..', 'dataraw2', 'dataraw2\\CoursesStructures.csv'), 'rb') as csvfile: # rb for read binary
spamreader = csv.reader(csvfile, delimiter=",")
firstLine = 0
......@@ -263,7 +263,7 @@ class ScriptDatabaseManager:
'''
databaseManager = DatabaseManager()
with open(os.path.join('..', 'dataraw2', 'Z:\\internship\\data\\0503\\dataraw2\\Session.csv'), 'rb') as csvfile: # rb for read binary
with open(os.path.join('..', 'dataraw2', 'dataraw2\\Session.csv'), 'rb') as csvfile: # rb for read binary
spamreader = csv.reader(csvfile, delimiter=",")
firstLine = 0
......@@ -292,7 +292,7 @@ class ScriptDatabaseManager:
'''
databaseManager = DatabaseManager()
with open(os.path.join('..', 'dataraw2', 'Z:\\internship\\data\\0503\\dataraw2\\user_course_subscription.csv'), 'rb') as csvfile: # rb for read binary
with open(os.path.join('..', 'dataraw2', 'dataraw2\\user_course_subscription.csv'), 'rb') as csvfile: # rb for read binary
spamreader = csv.reader(csvfile, delimiter=";")
firstLine = 0
......
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