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 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