def printBasicNoteStats(user): notes = Note.objects.filter(owner=user) print "# Notes:", notes.count() noteLen = map(lambda x:len(x.contents), notes) noteLines = map(lambda x:len(x.contents.split('\n')), notes) print "Ave #Chars:", mean(noteLen), ", Ave Var:", variance(noteLen) print "Ave #Lines:", mean(noteLines), ", Ave Var:", variance(noteLines)
def printBasicNoteStats(user): notes = Note.objects.filter(owner=user) print "# Notes:", notes.count() noteLen = map(lambda x: len(x.contents), notes) noteLines = map(lambda x: len(x.contents.split('\n')), notes) print "Ave #Chars:", mean(noteLen), ", Ave Var:", variance(noteLen) print "Ave #Lines:", mean(noteLines), ", Ave Var:", variance(noteLines)
def analyzeUserWalk(user): totalDays, activeDays, aliveAndDeadTotal, aliveAndDeadGained = userWalk(user) aliveGained = map(lambda x:x[0],aliveAndDeadGained) nAddVel = sum(aliveGained)*1.0/activeDays nAddVar = variance(aliveGained) print "Add v:", nAddVel, ", var:", nAddVar deadGained = map(lambda x:x[1],aliveAndDeadGained) nDelVel = sum(deadGained)*1.0/activeDays nDelVar = variance(deadGained)*1.0 print "Del v:", nDelVel, ", var:", nDelVar printBasicNoteStats(user) return nAddVel, nAddVar, nDelVel, nDelVar
def analyzeUserWalk(user): totalDays, activeDays, aliveAndDeadTotal, aliveAndDeadGained = userWalk( user) aliveGained = map(lambda x: x[0], aliveAndDeadGained) nAddVel = sum(aliveGained) * 1.0 / activeDays nAddVar = variance(aliveGained) print "Add v:", nAddVel, ", var:", nAddVar deadGained = map(lambda x: x[1], aliveAndDeadGained) nDelVel = sum(deadGained) * 1.0 / activeDays nDelVar = variance(deadGained) * 1.0 print "Del v:", nDelVel, ", var:", nDelVar printBasicNoteStats(user) return nAddVel, nAddVar, nDelVel, nDelVar
def user_var_change(userid): global _walk_cache if userid not in _walk_cache: _walk_cache[userid] = userWalk(User.objects.filter(id=userid)[0]) totDays,activeDays,adeadtotal,adeadgained = _walk_cache[userid] delta = [(new - dead) for new,dead in adeadgained] return ca.make_feature('var_change', variance(delta))
def creations(users): print "bar" cusave = [wuw.reduceRepeatLogsValues(list(cu.activitylog_set.filter(action__in=['notecapture-focus','note-add']).values())) for cu in users] means = [] varss = [] userstimes = [] for u_i in xrange(len(cusave)): print u_i user = users[u_i] print user uals = cusave[u_i] uals.sort(key=lambda x: long(x["when"])) if len(uals) == 0: continue print len(uals) thisal = uals[0] usertimes = [] for al in uals[1:]: if thisal["action"] == 'notecapture-focus' and al["action"] == 'note-add': elapsed = long(al["when"]) - long(thisal["when"]) usertimes.append(long(al["when"]) - long(thisal["when"])) thisal = al userstimes.append(usertimes) try: means.append(mean(usertimes)) varss.append(variance(usertimes)) except: import sys print sys.exc_info() return reduce(lambda x,y:x+y, userstimes),userstimes,means,varss
def user_var_change(userid): global _walk_cache if userid not in _walk_cache: _walk_cache[userid] = userWalk(User.objects.filter(id=userid)[0]) totDays, activeDays, adeadtotal, adeadgained = _walk_cache[userid] delta = [(new - dead) for new, dead in adeadgained] return ca.make_feature('var_change', variance(delta))
def user_var_day_del(userid): global _walk_cache if userid not in _walk_cache: _walk_cache[userid] = userWalk(User.objects.filter(id=userid)[0]) totDays, activeDays, adeadtotal, adeadgained = _walk_cache[userid] return ca.make_feature('var_del_notes_per_day', variance([dead for alive, dead in adeadgained]))
def user_var_alive_percent(userid): global _walk_cache if userid not in _walk_cache: _walk_cache[userid] = userWalk(User.objects.filter(id=userid)[0]) totDays, activeDays, adeadtotal, adeadgained = _walk_cache[userid] return ca.make_feature( 'variance_alive_notes', variance([(alive / (1.0 * (alive + dead + 0.00001))) for alive, dead in adeadtotal]))
def creations(users): print "bar" cusave = [ wuw.reduceRepeatLogsValues( list( cu.activitylog_set.filter( action__in=['notecapture-focus', 'note-add']).values())) for cu in users ] means = [] varss = [] userstimes = [] for u_i in xrange(len(cusave)): print u_i user = users[u_i] print user uals = cusave[u_i] uals.sort(key=lambda x: long(x["when"])) if len(uals) == 0: continue print len(uals) thisal = uals[0] usertimes = [] for al in uals[1:]: if thisal["action"] == 'notecapture-focus' and al[ "action"] == 'note-add': elapsed = long(al["when"]) - long(thisal["when"]) usertimes.append(long(al["when"]) - long(thisal["when"])) thisal = al userstimes.append(usertimes) try: means.append(mean(usertimes)) varss.append(variance(usertimes)) except: import sys print sys.exc_info() return reduce(lambda x, y: x + y, userstimes), userstimes, means, varss
def user_var_day_del(userid): global _walk_cache if userid not in _walk_cache: _walk_cache[userid] = userWalk(User.objects.filter(id=userid)[0]) totDays,activeDays,adeadtotal,adeadgained = _walk_cache[userid] return ca.make_feature('var_del_notes_per_day',variance([dead for alive,dead in adeadgained ] ))
def user_var_alive_percent(userid): global _walk_cache if userid not in _walk_cache: _walk_cache[userid] = userWalk(User.objects.filter(id=userid)[0]) totDays,activeDays,adeadtotal,adeadgained = _walk_cache[userid] return ca.make_feature('variance_alive_notes',variance( [(alive/(1.0*(alive+dead+0.00001))) for alive,dead in adeadtotal ] ))