def _comments(self, pivot_date): pivot_date_min = datetime.combine(pivot_date, time(0, 0, 0, 0, tzinfo=utc)) pivot_date_max = datetime.combine(pivot_date, time(23, 59, 59, 999999, tzinfo=utc)) num_comments = Comments.objects.filter( creation_date__range=(pivot_date_min, pivot_date_max)).count() # Store data points Metric.insert_metric(Metric.KPI_TOTAL_COMMENTS, pivot_date, num_comments, segment=Metric.SEG_ALL) return num_comments
def handle(self, *args, **options): num_days = int(options.get('days', 7)) if options['custom_date']: end_date = datetime.strptime(options['custom_date'], '%Y-%m-%d') else: end_date = now() - timedelta(days=1) begin_date = end_date - timedelta(days=num_days) begin_date_min = datetime.combine(begin_date, time(0, 0, 0, 0, tzinfo=utc)) end_date_max = datetime.combine(end_date, time(23, 59, 59, 999999, tzinfo=utc)) users = Chefs.objects.values('type')\ .filter(last_signin_date__range=(begin_date_min, end_date_max))\ .annotate(Count('type')) # .exclude(creation_date=F(last_signin_date)) cnt_pro = 0 cnt_foodie = 0 for row in users: if row['type'] == Chefs.TYPE_PRO: cnt_pro += row['type__count'] else: cnt_foodie += row['type__count'] # Store data points if num_days == 7: metric_code = Metric.KPI_SUPERACTIVE_USERS elif num_days == 30: metric_code = Metric.KPI_ACTIVE_USERS elif num_days == 60: metric_code = Metric.KPI_SLEEPING_USERS else: metric_code = Metric.KPI_DEAD_USERS Metric.insert_metric(metric_code, end_date, cnt_foodie, segment=Metric.SEG_FOODIES) Metric.insert_metric(metric_code, end_date, cnt_pro, segment=Metric.SEG_CHEFS) Metric.insert_metric(metric_code, end_date, cnt_pro + cnt_foodie, segment=Metric.SEG_ALL) self.stdout.write("%s user(s) registered" % (cnt_pro + cnt_foodie))
def handle(self, *args, **options): if options['custom_date']: pivot_date = datetime.strptime(options['custom_date'], '%Y-%m-%d') else: pivot_date = now() - timedelta(days=1) pivot_date_min = datetime.combine(pivot_date, time(0, 0, 0, 0, tzinfo=utc)) pivot_date_max = datetime.combine(pivot_date, time(23, 59, 59, 999999, tzinfo=utc)) cnt_foodie = Recipes.objects.filter( draft=0, private=0, creation_date__range=(pivot_date_min, pivot_date_max), chef__type=Chefs.TYPE_FOODIE).count() cnt_pro = Recipes.objects.filter(draft=0, private=0, creation_date__range=(pivot_date_min, pivot_date_max), chef__type=Chefs.TYPE_PRO).count() # Store data points Metric.insert_metric(Metric.KPI_TOTAL_RECIPES, pivot_date, cnt_foodie, segment=Metric.SEG_FOODIES) Metric.insert_metric(Metric.KPI_TOTAL_RECIPES, pivot_date, cnt_pro, segment=Metric.SEG_CHEFS) # Count recipes with more than 3 photos cnt_foodie_plus_3 = Recipes.objects.filter(draft=0, private=0, creation_date__range=(pivot_date_min, pivot_date_max), chef__type=Chefs.TYPE_FOODIE)\ .annotate(photos_count=Count('photos'))\ .filter(photos_count__gt=3).count() cnt_pro_plus_3 = Recipes.objects.filter(draft=0, private=0, creation_date__range=(pivot_date_min, pivot_date_max), chef__type=Chefs.TYPE_PRO)\ .annotate(photos_count=Count('photos'))\ .filter(photos_count__gt=3).count() # Store data points Metric.insert_metric(Metric.KPI_TOTAL_RECIPES_3_PHOTOS, pivot_date, cnt_foodie_plus_3, segment=Metric.SEG_FOODIES) Metric.insert_metric(Metric.KPI_TOTAL_RECIPES_3_PHOTOS, pivot_date, cnt_pro_plus_3, segment=Metric.SEG_CHEFS) # Send data to Dashboard GeckoBoard.push_recipes_created(cnt_foodie_plus_3 + cnt_pro_plus_3, cnt_pro_plus_3, cnt_foodie_plus_3) self.stdout.write("%s Total foodies recipes created" % cnt_foodie) self.stdout.write("%s Total chefs recipes created" % cnt_pro) self.stdout.write("%s foodies recipes with more than 3 photos" % cnt_foodie_plus_3) self.stdout.write("%s chefs recipes with more than 3 photos" % cnt_pro_plus_3)
def handle(self, *args, **options): if options['custom_date']: pivot_date = datetime.strptime(options['custom_date'], '%Y-%m-%d') else: pivot_date = now() - timedelta(days=1) pivot_date_min = datetime.combine(pivot_date, time(0, 0, 0, 0, tzinfo=utc)) pivot_date_max = datetime.combine(pivot_date, time(23, 59, 59, 999999, tzinfo=utc)) registered_users = Chefs.objects.values('type')\ .filter(creation_date__range=(pivot_date_min, pivot_date_max))\ .annotate(Count('type')) cnt_pro = 0 cnt_foodie = 0 for row in registered_users: if row['type'] == Chefs.TYPE_PRO: cnt_pro += row['type__count'] else: cnt_foodie += row['type__count'] # Store data points Metric.insert_metric(Metric.KPI_REGISTERED_USERS, pivot_date, cnt_foodie, segment=Metric.SEG_FOODIES) Metric.insert_metric(Metric.KPI_REGISTERED_USERS, pivot_date, cnt_pro, segment=Metric.SEG_CHEFS) Metric.insert_metric(Metric.KPI_REGISTERED_USERS, pivot_date, cnt_pro + cnt_foodie, segment=Metric.SEG_ALL) # Count total foodies total_foodies = Chefs.objects.filter(is_active=True, active=True, type=Chefs.TYPE_FOODIE).count() Metric.insert_metric(Metric.KPI_TOTAL_USERS, pivot_date, total_foodies, segment=Metric.SEG_FOODIES) total_chefs = Chefs.objects.filter(is_active=True, active=True, type=Chefs.TYPE_PRO).count() Metric.insert_metric(Metric.KPI_TOTAL_USERS, pivot_date, total_chefs, segment=Metric.SEG_CHEFS) # Push to dashboard GeckoBoard.push_weekly_metric(Metric.KPI_REGISTERED_USERS) self.stdout.write("%s user(s) registered" % (cnt_pro + cnt_foodie)) self.stdout.write("Total foodies %s registered" % total_foodies) self.stdout.write("Total chefs %s registered" % total_chefs)