Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
logic behind logECG
@classmethod
def get_total_hours(self):
'''Sum of all hours ever added'''
return GhanaECG.objects.all().aggregate(Sum('off_hours'))
@classmethod
def get_today_hours(self):
'''Sum of all hours submitted today'''
end_time = datetime.now()
start_time = datetime(end_time.year,end_time.month,end_time.day)
return GhanaECG.objects.filter(pub_date__range=(start_time, end_time)).aggregate(Sum('off_hours'))
@classmethod
def get_today_locations(self):
'''Location wiht highest number of hours'''
end_time = datetime.now()
start_time = datetime(end_time.year,end_time.month,end_time.day)
return GhanaECG.objects.filter(pub_date__range=(start_time, end_time)).order_by('off_hours').first()
@classmethod
def get_all_time_average(self):
return GhanaECG.objects.all().aggregate(Avg('off_hours'))
# for yesterday
@classmethod
def get_yesterday_hours(sefl):
return GhanaECG.objects.filter(pub_date__day=(timezone.now().day - 1)).aggregate(Sum('off_hours'))
@classmethod
def get_yesterday_locations(self):
return GhanaECG.objects.filter(pub_date__day=timezone.now().day - 1).order_by('off_hours').first()
# for past_week
@classmethod
def get_past_week_hours(self):
start_date = timezone.now().date()
end_date = timezone.now().date() - timedelta(weeks=1)
return GhanaECG.objects.filter(pub_date__range=(end_date, start_date)).aggregate(Sum('off_hours'))
@classmethod
def get_past_week_locations(self):
start_date = timezone.now().date()
end_date = timezone.now().date() - timedelta(weeks=1)
return GhanaECG.objects.filter(pub_date__range=(end_date, start_date)).order_by('off_hours').first()
# for month past
@classmethod
def get_past_month_locations(self):
return GhanaECG.objects.filter(pub_date__month=(datetime.now().month - 1)).order_by('off_hours').first()
@classmethod
def get_past_month_hours(self):
return GhanaECG.objects.filter(pub_date__month=(datetime.today().month - 1)).aggregate(Sum('off_hours'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.