Example #1
0
 def post(self, request, *args, **kwargs):
     self.user = self.request.user
     self.end = end_of_day(parse(self.request.POST['end']))
     self.start = start_of_day(parse(self.request.POST['start']))
     self.activity_types = ActivityType.objects.filter(
         id__in=self.request.POST.getlist("activity_type"))
     labels, data = self.get_data()
     return Response({
         'labels': labels,
         'data': data,
     })
Example #2
0
 def get_qs(self, date, year):
     start = start_of_day(date + relativedelta(year=year))
     end = end_of_day(start)
     qs = super().get_initial_queryset()
     qs = qs.filter(date__range=(start, end),
                    activity_type__in=self.activity_types).aggregate(
                        Sum('distance_meters'),
                        Sum('duration_seconds'),
                        Sum('total_elevation_gain'),
                        Count('id'),
                    )
     return qs
Example #3
0
 def get_activities_trimp(self, d):
     trimp = 0
     activities = Activity.objects.filter(user=self.user,
                                          date__range=(start_of_day(d),
                                                       end_of_day(d)))
     trimp_description = 'Trimp {}'.format(self.trimp_type)
     trimp_stream = StreamType.objects.filter(
         description=trimp_description).first()
     for act in activities:
         trimp += act.avg_stream_type(trimp_stream.id)
     if activities.count() > 0:
         trimp = trimp / activities.count()
     return float(trimp)
Example #4
0
 def get_data(self):
     labels = []
     data = {k: [] for k in self.data_points}
     d = self.start
     base_qs = self.get_initial_queryset()
     while d <= self.end:
         day_qs = base_qs.filter(date__range=(start_of_day(d),
                                              end_of_day(d)))
         if 'Duration' in self.data_points:
             data['Duration'].append(
                 day_qs.aggregate(
                     Sum('duration_seconds'))['duration_seconds__sum'])
         if 'Pace' in self.data_points:
             data['Pace'].append(day_qs.aggregate(Sum('pace'))['pace__sum'])
         labels.append(d.strftime("%d/%m/%Y"))
         d += relativedelta(days=1)
     return labels, data
Example #5
0
 def get_initial_queryset(self):
     qs = super().get_initial_queryset()
     qs = qs.filter(date__range=(start_of_day(self.start),
                                 end_of_day(self.end)),
                    activity_type__in=self.activity_types)
     return qs
Example #6
0
 def get_initial_queryset(self):
     qs = super().get_initial_queryset()
     qs = qs.filter(date__range=(start_of_day(self.start_date),
                                 end_of_day(self.end_date)))
     qs = qs.filter(activity_type__description='Run')
     return qs