Commit e6482245 authored by Han Dinh's avatar Han Dinh
Browse files

updates

parent 691ec144
'''
Created on Apr 20, 2017
@author: Han
'''
import numpy as np
import os
import matplotlib.pyplot as plt
from dataManager.course import Course
from sequenceManager.sequenceInterface import SequenceInterface
from userStatistic import UserStatistic
from sequenceManager.sequenceSession import SequenceSession
#from nb_conda.handlers import static
class AvgSessionsBeforeQuiz:
'''
class to generate on figure on a specific course and a specific group of users.
'''
NAME_DIRECTORY_FIGURES = 'figures'
def __init__(self, idCourse, title):
'''
@param idCourse: id of the course to generate the data
@param title: title of the figure
'''
self.idCourse = idCourse
self.course = Course(self.idCourse)
self.title = self.course.getCourseName(self.idCourse, summary = True)+" - "+title
self.typeCourse = [Course.CHAPTER]
self.sequenceCourse = self.course.getSequenceId(self.typeCourse)
self.X = range(0, len(self.sequenceCourse))
self.figure = plt.figure()
self.figure.canvas.set_window_title(self.title)
self.figure.suptitle(self.title)
plt.xlabel('User Group')
plt.ylabel('Average # of Sessions Before Quiz Attempt')
self.userStatistic = UserStatistic(idCourse)
def computeY(self, groupSequences):
'''
compute the Y values from the userSequences average number of accesses per session
@param groupSequences: a list of all groups' user sequences
(example: [allFailedSequences, allSucceedSequnces, premiumFailSequences, premiumSucceedSequences, nonpremiumFailSequences, nonPremiumSucceedSequences]
@return: a matrix Ys to display boxplots of each groups' # of users and their average number of accesses per session
'''
dataAllGroups = []
if groupSequences:
for (courseId, oneGroup) in groupSequences:
#print(str(oneGroup))
dataOneGroup=[]
for (userId, sequence) in oneGroup:
self.userStatistic.setUserSequence((userId,sequence))
dataOneGroup.append(self.userStatistic.computeAvgSessionsBeforeQuizAttempt())
#print("dataOneGroup: "+str(dataOneGroup))
dataAllGroups.append(dataOneGroup)
return dataAllGroups
def setData(self, groupSequences):
'''
add a set of userSequences to the figure
@param userSequences: group of sequences to add
@param color: color of the curve
@param line: style of the line
'''
#(sequence1, sequence2, sequence3, sequence4) = userSequences
#(courseId, userSequences) = userSequences
data = self.computeY(groupSequences)
self.plot(data)
def plot(self, data):
'''
plot all the curves on the figure
'''
if data:
plt.boxplot(data)
groupNames = ['Failed All', 'Succeed All', 'Failed Prem.', 'Succeed Prem.',
'Fail Non-Prem.', 'Succeed Non-Prem.']
plt.xticks([1, 2, 3, 4, 5, 6], groupNames, rotation=15, fontsize=8)
#xtickNames = plt.setp(ax, xticklabels=np.repeat(randomDists, 2))
#plt.setp(xtickNames, rotation=45, fontsize=8)
def show(self):
'''
show the current figures
'''
plt.show()
def setLimitYAxe(self, ymin, ymax):
'''
set the y axes of the current figure
'''
axes = self.figure.gca()
axes.set_ylim([ymin,ymax])
def getLimitYaxes(self):
'''
retrieve the boundary of the Y axes
@return: (x, y) where x is the min and y the max
'''
return self.figure.gca().get_ylim()
def saveFigure(self):
'''
save the figure in the directory in jpg format
'''
fileName = os.path.join(AvgSessionsBeforeQuiz.NAME_DIRECTORY_FIGURES, self.title)
fileName = fileName.replace(" ", "")
print("fileName: "+str(fileName))
self.figure.savefig(fileName+'.png')
def closeFigure(self):
plt.close(self.figure)
\ No newline at end of file
'''
Created on Apr 20, 2017
@author: Han
'''
import numpy as np
import os
import matplotlib.pyplot as plt
from dataManager.course import Course
from sequenceManager.sequenceInterface import SequenceInterface
from userStatistic import UserStatistic
from sequenceManager.sequenceSession import SequenceSession
#from nb_conda.handlers import static
class IntervalDailySession:
'''
class to generate on figure on a specific course and a specific group of users.
'''
NAME_DIRECTORY_FIGURES = 'figures'
def __init__(self, idCourse, title):
'''
@param idCourse: id of the course to generate the data
@param title: title of the figure
'''
self.idCourse = idCourse
self.course = Course(self.idCourse)
self.title = self.course.getCourseName(self.idCourse, summary = True)+" - "+title
self.typeCourse = [Course.CHAPTER]
self.sequenceCourse = self.course.getSequenceId(self.typeCourse)
self.X = range(0, len(self.sequenceCourse))
self.figure = plt.figure()
self.figure.canvas.set_window_title(self.title)
self.figure.suptitle(self.title)
plt.xlabel('User Group')
plt.ylabel('Average # of Sessions Daily')
self.userStatistic = UserStatistic(idCourse)
def computeY(self, groupSequences):
'''
compute the Y values from the userSequences average number of accesses per session
@param groupSequences: a list of all groups' user sequences
(example: [allFailedSequences, allSucceedSequnces, premiumFailSequences, premiumSucceedSequences, nonpremiumFailSequences, nonPremiumSucceedSequences]
@return: a matrix Ys to display boxplots of each groups' # of users and their average number of accesses per session
'''
dataAllGroups = []
if groupSequences:
for (courseId, oneGroup) in groupSequences:
#print(str(oneGroup))
dataOneGroup=[]
for (userId, sequence) in oneGroup:
self.userStatistic.setUserSequence((userId,sequence))
dataOneGroup.append(self.userStatistic.computeAvgDailySessions())
#print("dataOneGroup: "+str(dataOneGroup))
dataAllGroups.append(dataOneGroup)
return dataAllGroups
def setData(self, groupSequences):
'''
add a set of userSequences to the figure
@param userSequences: group of sequences to add
@param color: color of the curve
@param line: style of the line
'''
#(sequence1, sequence2, sequence3, sequence4) = userSequences
#(courseId, userSequences) = userSequences
data = self.computeY(groupSequences)
self.plot(data)
def plot(self, data):
'''
plot all the curves on the figure
'''
if data:
plt.boxplot(data)
groupNames = ['Failed All', 'Succeed All', 'Failed Prem.', 'Succeed Prem.',
'Fail Non-Prem.', 'Succeed Non-Prem.']
plt.xticks([1, 2, 3, 4, 5, 6], groupNames, rotation=15, fontsize=8)
#xtickNames = plt.setp(ax, xticklabels=np.repeat(randomDists, 2))
#plt.setp(xtickNames, rotation=45, fontsize=8)
def show(self):
'''
show the current figures
'''
plt.show()
def setLimitYAxe(self, ymin, ymax):
'''
set the y axes of the current figure
'''
axes = self.figure.gca()
axes.set_ylim([ymin,ymax])
def getLimitYaxes(self):
'''
retrieve the boundary of the Y axes
@return: (x, y) where x is the min and y the max
'''
return self.figure.gca().get_ylim()
def saveFigure(self):
'''
save the figure in the directory in jpg format
'''
fileName = os.path.join(IntervalDailySession.NAME_DIRECTORY_FIGURES, self.title)
fileName = fileName.replace(" ", "")
print("fileName: "+str(fileName))
self.figure.savefig(fileName+'.png')
def closeFigure(self):
plt.close(self.figure)
\ No newline at end of file
'''
Created on Apr 6, 2017
@author: Han
'''
import numpy as np
import os
import matplotlib.pyplot as plt
from dataManager.course import Course
from userStatistic import UserStatistic
#from nb_conda.handlers import static
class IntervalDailySessionHistogram:
'''
class to generate a histogram on the users' total duration in all sessions
'''
NAME_DIRECTORY_FIGURES = 'figures'
countFigure = 1
def __init__(self, idCourse, title):
'''
@param idCourse: id of the course to generate the data
@param title: title of the figure
'''
self.idCourse = idCourse
self.course = Course(self.idCourse)
self.title = self.course.getCourseName(self.idCourse, summary = True)+" - "+title
#self.X = self.sequenceCourse
self.userStatistic = UserStatistic(idCourse)
self.figure = plt.figure(IntervalDailySessionHistogram.countFigure)
self.figure.canvas.set_window_title(self.title)
self.figure.suptitle(self.title)
plt.xlabel('Average Number of Sessions Per Day')
plt.ylabel('# of users')
IntervalDailySessionHistogram.countFigure = IntervalDailySessionHistogram.countFigure +1
def computeY(self, userSequences):
'''
compute the Y values from the userSequences (sum of the duration for each part and for each users)
@param userSequences: all the user sequences from which are computed the duration
@return: a matrix Ys where each line is the durations of one user for each part
'''
(_, userSequences) = userSequences
data = []
if userSequences:
for (userId, sequence) in userSequences:
self.userStatistic.setUserSequence((userId,sequence))
data.append(self.userStatistic.computeAvgDailySessions())
return data
def setData(self, userSequences):
'''
add a set of userSequences to the figure
'''
#(_, userSequences) = userSequences
data = self.computeY(userSequences)
self.plot(data)
def plot(self, data):
'''
plot all the curves on the figure
'''
if data:
#plt.hist(data, bins=np.arange(0,int(max(data))+1,1), color='blue', normed=True, align='mid')
plt.hist(data, bins=np.arange(0,int(max(data))+1,0.5), color='red')
def show(self):
'''
show the current figures
'''
plt.show()
def setLimitXAxe(self, xmin, xmax):
'''
set the x axes of the current figure
'''
axes = self.figure.gca()
axes.set_xlim([xmin,xmax])
def getLimitXaxes(self):
'''
retrieve the boundary of the X axes
@return: (x, y) where x is the min and y the max
'''
return self.figure.gca().get_xlim()
def saveFigure(self):
'''
save the figure in the directory in jpg format
'''
fileName = os.path.join(IntervalDailySessionHistogram.NAME_DIRECTORY_FIGURES, self.title)
fileName = fileName.replace(" ", "")
print(fileName)
self.figure.savefig(fileName+'.png')
def closeFigure(self):
plt.close(self.figure)
\ No newline at end of file
'''
Created on Apr 20, 2017
@author: Han
'''
from avgSessionsBeforeQuiz import AvgSessionsBeforeQuiz
from dataManager.course import Course
from sequenceManager.sequenceInterface import SequenceInterface
class ScriptAvgSessionsBeforeQuiz:
'''
class to generate the boxplots on the average number of accesses per session of users on the courses.
Figures are saved in figures directory
'''
def generateAllGroup(self, sequenceSession):
'''
Generate all the figures for the premium group (succeed vs failed) for all courses
'''
for idCourse in Course.ID_COURSES:
for group in SequenceInterface.GROUPS:
userSequence = sequenceSession.getSequences(idCourse, group)
self.generateFigure(idCourse, userSequence, SequenceInterface.getGroupName(group))
def generateListOfGroups(self, idCourse, groupSequences, title, show = True):
'''
compute one graph of multiple boxplots from a list of group sequences
@param groupSequences: a list of all groups' user sequences
'''
avgAccessesSessionBoxPlotListOfGroups = AvgSessionsBeforeQuiz(idCourse, title+'Average Sessions Before Quiz Attempt')
avgAccessesSessionBoxPlotListOfGroups.setData(groupSequences)
avgAccessesSessionBoxPlotListOfGroups.saveFigure()
if show:
avgAccessesSessionBoxPlotListOfGroups.show()
avgAccessesSessionBoxPlotListOfGroups.closeFigure()
def generateFigure(self, idCourse, userSequence, title, show = False):
avgAccessesSessionBoxPlot = AvgSessionsBeforeQuiz(idCourse, title)
avgAccessesSessionBoxPlot.setData(userSequence)
avgAccessesSessionBoxPlot.saveFigure()
if show:
avgAccessesSessionBoxPlot.show()
avgAccessesSessionBoxPlot.closeFigure()
def generatePremium(self, idCourse, sequenceSession, show = True):
userSequencesSucceed = sequenceSession.getSequencesPremiumSucceed(idCourse)
userSequencesFailed = sequenceSession.getSequencesPremiumFailed(idCourse)
self.generateGenericGroup(idCourse, userSequencesSucceed, userSequencesFailed,
SequenceInterface.getGroupName(SequenceInterface.GROUP_PREMIUM), show)
def generateNonPremium(self, idCourse, sequenceSession, show = True):
userSequencesSucceed = sequenceSession.getSequencesNonPremiumSucceed(idCourse)
userSequencesFailed = sequenceSession.getSequencesNonPremiumFailed(idCourse)
self.generateGenericGroup(idCourse, userSequencesSucceed, userSequencesFailed,
SequenceInterface.getGroupName(SequenceInterface.GROUP_NON_PREMIUM), show)
def generateAll(self, idCourse, sequenceSession, show = True):
userSequencesSucceed = sequenceSession.getSequencesAllSucceed(idCourse)
userSequencesFailed = sequenceSession.getSequencesAllFailed(idCourse)
self.generateGenericGroup(idCourse, userSequencesSucceed, userSequencesFailed,
SequenceInterface.getGroupName(SequenceInterface.GROUP_ALL), show)
def generateGenericGroup(self, idCourse, userSequencesSucceed, userSequencesFailed, title, show = True):
avgAccessesSessionBoxPlotSucceed = AvgSessionsBeforeQuiz(idCourse, title+' succeed')
avgAccessesSessionBoxPlotSucceed.setData(userSequencesSucceed)
avgAccessesSessionBoxPlotFailed = AvgSessionsBeforeQuiz(idCourse, title+' failing')
avgAccessesSessionBoxPlotFailed.setData(userSequencesFailed)
#(x, y) = avgAccessesSessionBoxPlotSucceed.getLimitYaxes()
#avgAccessesSessionBoxPlotFailed.setLimitYAxe(x, y)
avgAccessesSessionBoxPlotFailed.saveFigure()
avgAccessesSessionBoxPlotSucceed.saveFigure()
if show:
avgAccessesSessionBoxPlotFailed.show()
avgAccessesSessionBoxPlotFailed.closeFigure()
avgAccessesSessionBoxPlotSucceed.closeFigure()
\ No newline at end of file
'''
Created on Apr 20, 2017
@author: Han
'''
from intervalDailySession import IntervalDailySession
from dataManager.course import Course
from sequenceManager.sequenceInterface import SequenceInterface
class ScriptIntervalDailySession:
'''
class to generate the boxplots on the average number of sessions per day
Figures are saved in figures directory
'''
def generateAllGroup(self, sequenceSession):
'''
Generate all the figures for the premium group (succeed vs failed) for all courses
'''
for idCourse in Course.ID_COURSES:
for group in SequenceInterface.GROUPS:
userSequence = sequenceSession.getSequences(idCourse, group)
self.generateFigure(idCourse, userSequence, SequenceInterface.getGroupName(group))
def generateListOfGroups(self, idCourse, groupSequences, title, show = True):
'''
compute one graph of multiple boxplots from a list of group sequences
@param groupSequences: a list of all groups' user sequences
'''
intervalDailySessionListOfGroups = IntervalDailySession(idCourse, title+' Average Number of Sessions Per Day')
intervalDailySessionListOfGroups.setData(groupSequences)
intervalDailySessionListOfGroups.saveFigure()
if show:
intervalDailySessionListOfGroups.show()
intervalDailySessionListOfGroups.closeFigure()
def generateFigure(self, idCourse, userSequence, title, show = False):
intervalDailySession = IntervalDailySession(idCourse, title)
intervalDailySession.setData(userSequence)
intervalDailySession.saveFigure()
if show:
intervalDailySession.show()
intervalDailySession.closeFigure()
def generatePremium(self, idCourse, sequenceSession, show = True):
userSequencesSucceed = sequenceSession.getSequencesPremiumSucceed(idCourse)
userSequencesFailed = sequenceSession.getSequencesPremiumFailed(idCourse)
self.generateGenericGroup(idCourse, userSequencesSucceed, userSequencesFailed,
SequenceInterface.getGroupName(SequenceInterface.GROUP_PREMIUM), show)
def generateNonPremium(self, idCourse, sequenceSession, show = True):
userSequencesSucceed = sequenceSession.getSequencesNonPremiumSucceed(idCourse)
userSequencesFailed = sequenceSession.getSequencesNonPremiumFailed(idCourse)
self.generateGenericGroup(idCourse, userSequencesSucceed, userSequencesFailed,
SequenceInterface.getGroupName(SequenceInterface.GROUP_NON_PREMIUM), show)
def generateAll(self, idCourse, sequenceSession, show = True):
userSequencesSucceed = sequenceSession.getSequencesAllSucceed(idCourse)
userSequencesFailed = sequenceSession.getSequencesAllFailed(idCourse)
self.generateGenericGroup(idCourse, userSequencesSucceed, userSequencesFailed,
SequenceInterface.getGroupName(SequenceInterface.GROUP_ALL), show)
def generateGenericGroup(self, idCourse, userSequencesSucceed, userSequencesFailed, title, show = True):
intervalDailySessionSucceed = IntervalDailySession(idCourse, title+' succeed')
intervalDailySessionSucceed.setData(userSequencesSucceed)
intervalDailySessionFailed = IntervalDailySession(idCourse, title+' failing')
intervalDailySessionFailed.setData(userSequencesFailed)
#(x, y) = intervalDailySessionSucceed.getLimitYaxes()
#intervalDailySessionFailed.setLimitYAxe(x, y)
intervalDailySessionFailed.saveFigure()
intervalDailySessionSucceed.saveFigure()
if show:
intervalDailySessionFailed.show()
intervalDailySessionFailed.closeFigure()
intervalDailySessionSucceed.closeFigure()
\ No newline at end of file
'''
Created on Apr 6, 2017
@author: Han
'''
from intervalDailySessionHistogram import IntervalDailySessionHistogram
from dataManager.course import Course
from sequenceManager.sequenceInterface import SequenceInterface
class ScriptIntervalDailySessionHistogram:
'''
class to generate the histogram of average number of daily SessionHistograms
Figures are saved in figures directory
'''
def generateAllGroup(self, sequenceSession):
'''
Generate all the figures for the premium group (succeed vs failed) for all courses