示例#1
0
	def handle(self, *args, **options):
		teachers = get_all_teachers_classrooms()
		for to in teachers:
			u = to["user"]
			if not TeacherWaitlist.objects.filter(email=u.email).exists():
				
				print 'email doesnt exist, adding to "teacherwaitlist" table: ' + u.email
				newentry = TeacherWaitlist(school="",
					how_hear="organic",
					firstname="",
					lastname="",
					study=False,
					num_students=to["total_students"],
					email=u.email,
					date=timezone.now(),
					convertedToCohort=False,
					cohort="",
					num_emails_sent=0)
				newentry.save()
示例#2
0
文件: cohorts.py 项目: zannorman/mol9
	def handle(self, *args, **options):
		totalConverted = 0
		totalTeachers = 0
		totalLicenses = 0
		totalNotIncohort = 0
		cohortList = {}
		teachers = get_all_teachers_classrooms()
		for item in TeacherWaitlist.objects.all():
			if not item.cohort in cohortList:
				cohortList[item.cohort] = {}
				cohortList[item.cohort]["num_teachers"] = 0
				cohortList[item.cohort]["num_teachers_with_classrooms"] = 0
				cohortList[item.cohort]["num_teachers_with_students"] = 0
				cohortList[item.cohort]["num_teachers_with_licenses"] = 0
				cohortList[item.cohort]["num_total_students"] = 0
				cohortList[item.cohort]["num_total_licenses"] = 0
				cohortList[item.cohort]["num_teachers_no_classrooms"] = 0
				
			else:
				cohortList[item.cohort]["num_teachers"] += 1

			if ClassroomTeacherRel.objects.filter(user__username = item.email).exists():
				if ClassroomTeacherRel.objects.filter(user__username = item.email).first().user.profile.num_licenses > 0:
					cohortList[item.cohort]["num_teachers_with_licenses"] += 1
					cohortList[item.cohort]["num_total_licenses"] += ClassroomTeacherRel.objects.filter(user__username = item.email).first().user.profile.num_licenses 	
				for t in teachers: #hella clumsy and slow
					if t["user"].email == item.email:
						cohortList[item.cohort]["num_total_students"] += t["total_students"]
						if t["total_students"] > 0:
							cohortList[item.cohort]["num_teachers_with_students"] += 1
				cohortList[item.cohort]["num_teachers_with_classrooms"] += 1 
			else:
				cohortList[item.cohort]["num_teachers_no_classrooms"] += 1
		for item in cohortList:
			print str(item)
			print "total teachers in cohort: " + str(cohortList[item]["num_teachers"])
			print "num teachers with classrooms: " + str(cohortList[item]["num_teachers_with_classrooms"])
			print "num teachers with licenses: " + str(cohortList[item]["num_teachers_with_licenses"])
			print "num total licenses: " + str(cohortList[item]["num_total_licenses"])
			print "num total students: " + str(cohortList[item]["num_total_students"])
示例#3
0
	def handle(self, dryrun=False, *args, **options):
		dryrun = "dryrun" == dryrun
		message = ""
		subject = ""
		numEmailedWithSomeLicenses = 0
		numEmailedWithNoLicenses = 0
		teachers = get_all_teachers_classrooms()
		num_skipped = 0
		num_emailed = 0
		for item in teachers:
			# print item["user"].email + " had no licenses but " + str(item["total_students"]) + " students."
			name = ''
			s = ""
			m = ""  
			playtime_per_student = 0
			if not item["total_students"] == 0:
				playtime_per_student = truncate(item["total_playtime"] / item["total_students"], 2)
			if not TeacherWaitlist.objects.filter(email=item["user"].email).exists():
				# print 'SKIP .. email doesnt exist: ' + item["user"].email
				num_skipped += 1
				continue
			if TeacherWaitlist.objects.get(email=item["user"].email).cohort == "":
				# print 'SKIP: .. email not associated with cohort yet: ' + item["user"].email
				num_skipped += 1
				continue
			name = TeacherWaitlist.objects.get(email=item["user"].email).firstname
			if name == "": 
				name = "Hello"
			if item["total_playtime"] == 0:
				s = mbcopy.TEACHER_STARTED_NO_STUDENTS_YET[0]
				m = mbcopy.TEACHER_STARTED_NO_STUDENTS_YET[1].format(name)
			elif item["user"].profile.num_licenses == 0 and item["total_students"] > 0:
				s = mbcopy.TEACHER_STARTED_NOT_PURCHASED_YET[0]
				m = mbcopy.TEACHER_STARTED_NOT_PURCHASED_YET [1].format(name,"https://mathbreakers.com/teacher/purchase")
			elif item["total_students"] > item["user"].profile.num_licenses and item["user"].profile.num_licenses > 0:
				s = mbcopy.TEACHER_TIME_HALF_UP_INSUFFICIENT_LICENSES[0]
				diff = item["total_students"] - item["user"].profile.num_licenses
				m = mbcopy.TEACHER_TIME_HALF_UP_INSUFFICIENT_LICENSES[1].format(
					name,
					item["user"].profile.num_licenses,
					item["total_students"],
					diff,
					diff*3)
				# print item["user"].email + " had "+ str(item["user"].profile.num_licenses) + " wit h " + str(item["total_students"]) + " students. total playtime was : " + str(value["total_playtime"]) + "; total students was : " + str(item["total_students"])
	
			if RobotSentEmail.objects.filter(title=s,email=item["user"].email).exists():
				# print 'SKIP: .. robot already sent email to ' + item["user"].email + ' with subject ' + s + ", skipping"
				num_skipped += 1
				continue
			elif s == "": 
				# print "SKIP: .. not ready for email: " + item["user"].email + " .. totalstudents: " + str(item["total_students"]) + ", playtime per: " + str(playtime_per_student) + ", licenses bought : " + str(item["user"].profile.num_licenses)
				num_skipped += 1
				continue
			else:
				ss = 'emailed: ' + item["user"].email + ": " + s + m[:4] + ".." + " .. totalstudents: " + str(item["total_students"]) + ", playtime per: " + str(playtime_per_student) + ", licenses bought : " + str(item["user"].profile.num_licenses)
				num_emailed += 1
				ss = ss.replace('\n',' ').replace('\t',' ')
				# print ss
				if not dryrun:
					time.sleep(1)
					send_mail_sync(s,m,'*****@*****.**',[item["user"].email])
				else:
					print "dryrun: " + item["user"].email + " message: " + ss
		print "emailed " + str(num_emailed) + ", skipped " + str(num_skipped)
示例#4
0
	def handle(self,  dryrun="", *args, **options):
		sent_emails = 0
		dryrun = dryrun == "dryrun"

		message = ""
		subject = "" 
		num_skipped = 0
		num_emailed = 0

		#emailed = []
		start_lobby_URL = "https://mathbreakers.com/start/N" # M was used week of Mar 20 - 27. N was used week of Mar 28 - Apr 6.
		daily_max = 100
		which_email = "none"
		for item in get_all_teachers_classrooms(): 
			if num_emailed >= daily_max:
				continue
			firstname = ""
			if TeacherWaitlist.objects.filter(email=item["user"].email).exists():
				firstname = TeacherWaitlist.objects.filter(email=item["user"].email)[0].firstname
			if firstname == "":
				firstname = "Hello"

			
			#  batch -- teachers with more students than licenses
			if item["user"].profile.num_licenses > 0 and item["user"].profile.num_licenses < item["total_students"]:
				subject = mbcopy.TEACHER_TIME_HALF_UP_INSUFFICIENT_LICENSES[0]
				message = mbcopy.TEACHER_TIME_HALF_UP_INSUFFICIENT_LICENSES[1].format(firstname,item["total_students"],item["user"].profile.num_licenses,item["total_students"]-item["user"].profile.num_licenses)
				which_email = "A"		
			#  batch -- teachers with all the licenses they need
			elif item["user"].profile.num_licenses > 0 and item["user"].profile.num_licenses >= item["total_students"]:
				subject = mbcopy.TEACHER_WITH_FULL_LICENSES[0]
				message = mbcopy.TEACHER_WITH_FULL_LICENSES[1].format(firstname)
				which_email = "B"
		
			#  batch -- teachers with an account but zero students
			elif item["total_students"] == 0:
				subject = mbcopy.TEACHER_STARTED_NO_STUDENTS_YET_2[0]
				message = mbcopy.TEACHER_STARTED_NO_STUDENTS_YET_2[1].format(firstname)
				which_email = "C"
		
			#  batch -- teachers with students but zero playtime
			elif item["total_playtime"] == 0:
				num_students = item["total_students"]
				subject = mbcopy.TEACHER_WITH_STUDENTS_ZERO_PLAYTIME[0]
				message = mbcopy.TEACHER_WITH_STUDENTS_ZERO_PLAYTIME[1].format(firstname,str(num_students) + " students")
				which_email = "D"
			now = timezone.now() + datetime.timedelta(days=-365) 
			lastTouched = now
			twoWeeksAgo = timezone.now() + datetime.timedelta(days=-14) 	
			twoMonthsAgo = timezone.now() + datetime.timedelta(days=-60) 	
			for ctr in ClassroomTeacherRel.objects.filter(user__email=item["user"].email):
				activities = ClassroomActivityBin.objects.filter(classroom=ctr.classroom)
				for activity in activities:
					# print "activity date for " + str(item["user"].email) + " w/ class:" + str(ctr.classroom) + " : " + str(activity.date)
					if lastTouched < activity.date:
						lastTouched = activity.date
			
			#  batch -- teachers with students with playtime, who have used the product in the past 2 weeks
			if lastTouched > twoWeeksAgo:
				subject = mbcopy.TEACHER_WITH_ACTIVITY_LAST_TWO_WEEKS[0] 
				message = mbcopy.TEACHER_WITH_ACTIVITY_LAST_TWO_WEEKS[1].format(firstname)
				which_email = "E"

			#  batch -- teachers with students with playtime, not for >2 weeks, but in the past 2 months
			elif lastTouched >= twoWeeksAgo and lastTouched < twoMonthsAgo:
				subject = mbcopy.TEACHER_WITH_NO_ACTIVITY_LAST_TWO_WEEKS[0]
				message = mbcopy.TEACHER_WITH_NO_ACTIVITY_LAST_TWO_WEEKS[1]  	
				which_email = "F"

			#  batch -- teachers with no playtime >2 months
			elif lastTouched >= twoMonthsAgo:
				subject = mbcopy.TEACHER_WITH_STUDENTS_NO_ACTIVITY_TWO_MONTHS[0]
				message = mbcopy.TEACHER_WITH_STUDENTS_NO_ACTIVITY_TWO_MONTHS[1].format(firstname,start_lobby_URL)  	
				which_email = "G"
			if RobotSentEmail.objects.filter(title = subject,email = item["user"].email).exists():
				print '[ SKIP ] : robot already sent ' + item["user"].email + " [ " + subject + " . . . ] which email: " + which_email
				num_skipped += 1
			elif not dryrun and not REMOTEDB:
				num_emailed += 1
				time.sleep(1)
				send_mail_sync(subject, message, '*****@*****.**', [item["user"].email])
			else:
				num_emailed += 1
				print "[dryrun/remoteDB] : [ " + which_email + " ] " + item["user"].email + "; " + subject 
		print ""
		print "num skipped: " + str(num_skipped)
		if dryrun or REMOTEDB:
			print "num dry emailed; " + str(num_emailed)
		else:
			print "num  emailed; " + str(num_emailed)