def basicStats(self, path): numRegistered = CourseStats.getNumRegisteredUsers() numContributors = CourseStats.getNumContributingUsers() numQuizSubmitters = CourseStats.getNumQuizSubmitters() with open(path, 'wt') as fid: fid.write('# registered users, ' + str(numRegistered) + '\n') fid.write('# forum contributors, ' + str(numContributors) + '\n') fid.write('# quiz submitters, ' + str(numQuizSubmitters) + '\n')
def runner(self): if not self.checkForDB(): logging.info('Necessary database does not exist, bailing. (' \ + self.getCourseName() + ')') sys.exit() self.loadData() firstResponseTimes = self.timeToFirstResponse().values() finiteFirstResponseTimes = [ t for t in firstResponseTimes if t != float("inf") ] numOpenThreads = CourseStats.getNumThreads() - len( finiteFirstResponseTimes) ratioOpenThreads = float(numOpenThreads) / CourseStats.getNumThreads() betweenTimes = self.timeBetweenPosts() (postBoost, viewBoost, onThreadPostBoost, onThreadViewBoost) = self.avgInstructorBoost() path = os.path.join(self.getMainResultsDir(), 'results.csv') with open(path, 'at') as fid: fid.write(self.getCourseName() + ', ' \ + str(len(self.activesByAnon)) + ', ' \ + str(len(self.lectureActivesByAnon)) + ', ' \ + str(self.contributionByActives()) + ', ' \ + str(self.contributionByLectureActives()) + ', ' \ #+ str(self.viewingByActives()) + ', ' \ + str(self.subscriptionsByActives()) + ', ' \ + str(self.subscriptionsByLectureActives()) + ', ' \ + str(self.numThreadsPerActive()) + ', ' \ + str(self.numThreadsPerLectureActive()) + ', ' \ + str(self.numContributionsPerActive()) + ', ' \ + str(self.numContributionsPerLectureActive()) + ', ' \ + str(self.numViewsPerHourPerActive()) + ', ' \ + str(self.numViewsPerHourPerLectureActive()) + ', ' \ #+ str(self.viewContributionRatio()) + ', ' \ + str(mean(finiteFirstResponseTimes)) + ', ' \ + str(median(firstResponseTimes)) + ', ' \ + str(mean(betweenTimes)) + ', ' \ + str(median(betweenTimes)) + ', ' \ + str(ratioOpenThreads) + ', ' \ + str(self.avgPostLen()) + ', ' \ + str(self.avgContributionsPerThread()) + ', ' \ + str(self.numInstructorPosts()) + ', ' \ + str(self.avgInstructorPostLen()) + ', ' \ + str(postBoost) + ', ' \ + str(viewBoost) + ', ' \ + str(onThreadPostBoost) + ', ' \ + str(onThreadViewBoost) + ', ' \ + str(self.avgReputation()) + '\n')
def runner(self): logging.info('SubscriptionRatio.runner(), ' + self.currCourseName) try: print('Working on: ' + self.currCourseName + ' (' + self.progress() +')') self.anonForumIdMap = ModelHelper.getAnonForumIdMap() self.forumAnonIdMap = ModelHelper.getForumAnonIdMap() for k in range(100): percenters = CourseStats.getKPercenters(k) numPercenters = len(percenters) numSubscriptions = self.countSubscriptions(percenters) ratio = float(numSubscriptions)/ numPercenters path = os.path.join(self.resultsDir,'results' + str(k) + '.csv') with open(path,'at') as fid: fid.write(self.currCourseName + ', ' \ + str(numSubscriptions) + ', ' \ + str(numPercenters) + ', ' \ + str(ratio) + '\n') except CourseDBError: logging.info('\t\t+ ERROR (Connection does not exist), skipping...') pass except NoGradesError: logging.info('\t\t+ ERROR (CourseGrades does not exist), skipping...') pass
def runner(self): if not self.checkForDB(): logging.info('Necessary database does not exist, bailing. (' \ + self.getCourseName() + ')') sys.exit() self.loadData() firstResponseTimes = self.timeToFirstResponse().values() finiteFirstResponseTimes = [t for t in firstResponseTimes if t != float("inf")] numOpenThreads = CourseStats.getNumThreads() - len(finiteFirstResponseTimes) ratioOpenThreads = float(numOpenThreads) / CourseStats.getNumThreads() betweenTimes = self.timeBetweenPosts() (postBoost, viewBoost, onThreadPostBoost, onThreadViewBoost) = self.avgInstructorBoost() path = os.path.join(self.getMainResultsDir(),'results.csv') with open(path,'at') as fid: fid.write(self.getCourseName() + ', ' \ + str(len(self.activesByAnon)) + ', ' \ + str(len(self.lectureActivesByAnon)) + ', ' \ + str(self.contributionByActives()) + ', ' \ + str(self.contributionByLectureActives()) + ', ' \ #+ str(self.viewingByActives()) + ', ' \ + str(self.subscriptionsByActives()) + ', ' \ + str(self.subscriptionsByLectureActives()) + ', ' \ + str(self.numThreadsPerActive()) + ', ' \ + str(self.numThreadsPerLectureActive()) + ', ' \ + str(self.numContributionsPerActive()) + ', ' \ + str(self.numContributionsPerLectureActive()) + ', ' \ + str(self.numViewsPerHourPerActive()) + ', ' \ + str(self.numViewsPerHourPerLectureActive()) + ', ' \ #+ str(self.viewContributionRatio()) + ', ' \ + str(mean(finiteFirstResponseTimes)) + ', ' \ + str(median(firstResponseTimes)) + ', ' \ + str(mean(betweenTimes)) + ', ' \ + str(median(betweenTimes)) + ', ' \ + str(ratioOpenThreads) + ', ' \ + str(self.avgPostLen()) + ', ' \ + str(self.avgContributionsPerThread()) + ', ' \ + str(self.numInstructorPosts()) + ', ' \ + str(self.avgInstructorPostLen()) + ', ' \ + str(postBoost) + ', ' \ + str(viewBoost) + ', ' \ + str(onThreadPostBoost) + ', ' \ + str(onThreadViewBoost) + ', ' \ + str(self.avgReputation()) + '\n')
def loadLectureActives(self): threshold = 5 lectureActiveAnonId = CourseStats.getLectureViewers(threshold) self.lectureActivesByAnon = {} for id in lectureActiveAnonId: try: self.lectureActivesByAnon[id] = self.users.getByAnon(id) except KeyError: pass
def loadActives(self): # return a list of users who got > 5% of max final grade threshold = 5 activeAnonId = CourseStats.getKPercenters(threshold) self.activesByAnon = {} for id in activeAnonId: try: self.activesByAnon[id] = self.users.getByAnon(id) except KeyError: pass
def numViewsPerHourPerLectureActive(self): if not self.viewsExists: return None numHours = 0.0 numViews = 0.0 day = 24*3600.0 for interval in self.viewBounds['bounds']: numHours += (interval[1] + 2*day - interval[0])/3600.0 numViews += CourseStats.getNumForumViewsInInterval([interval[0]-day,interval[1]+day]) return (numViews/numHours) / float(len(self.lectureActivesByAnon))
def avgContributionsPerThread(self): return float(len(self.contributionsByUser)) / float( CourseStats.getNumThreads())
def viewContributionRatio(self): if not self.viewsExists: return None return float(CourseStats.getNumForumViews()) / float( CourseStats.getNumContributions())
def numContributionsPerLectureActive(self): return float(CourseStats.getNumContributions()) / float( len(self.lectureActivesByAnon))
def viewContributionRatio(self): if not self.viewsExists: return None return float(CourseStats.getNumForumViews())/float(CourseStats.getNumContributions())
def subscriptionsByActives(self): return float(CourseStats.getNumSubscriptions() \ - CourseStats.getNumContributingUsers()) / float(len(self.activesByAnon))
def avgContributionsPerThread(self): return float(len(self.contributionsByUser))/float(CourseStats.getNumThreads())
def numContributionsPerLectureActive(self): return float(CourseStats.getNumContributions()) / float(len(self.lectureActivesByAnon))
def numThreadsPerLectureActive(self): return float(CourseStats.getNumThreads()) / float(len(self.lectureActivesByAnon))
def numThreadsPerLectureActive(self): return float(CourseStats.getNumThreads()) / float( len(self.lectureActivesByAnon))