Python django.db.models.aggregates 模块,Min() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用django.db.models.aggregates.Min()

项目:dsmr-reader    作者:dennissiemensma    | 项目源码 | 文件源码
def range_statistics(start, end):
    """ Returns the statistics (totals) for a target date. Its month will be used. """
    return DayStatistics.objects.filter(day__gte=start, day__lt=end).aggregate(
        total_cost=Sum('total_cost'),
        electricity1=Sum('electricity1'),
        electricity1_cost=Sum('electricity1_cost'),
        electricity1_returned=Sum('electricity1_returned'),
        electricity2=Sum('electricity2'),
        electricity2_cost=Sum('electricity2_cost'),
        electricity2_returned=Sum('electricity2_returned'),
        electricity_merged=Sum(models.F('electricity1') + models.F('electricity2')),
        electricity_cost_merged=Sum(models.F('electricity1_cost') + models.F('electricity2_cost')),
        electricity_returned_merged=Sum(models.F('electricity1_returned') + models.F('electricity2_returned')),
        gas=Sum('gas'),
        gas_cost=Sum('gas_cost'),
        temperature_min=Min('lowest_temperature'),
        temperature_max=Max('highest_temperature'),
        temperature_avg=Avg('average_temperature'),
    )
项目:wifi-attendance    作者:elvinzeng    | 项目源码 | 文件源码
def get(self, request):
        if request.user.is_authenticated():
            histories = OnlineHistory.objects.filter(mac=request.user.username)\
                .values('date').annotate(min_time=Min('time'), max_time=Max('time')).order_by("-date")
            return render(request, "index.html", locals())
        else:
            verification_token = str(uuid.uuid4())
            request.session["verification_token"] = verification_token
            return render(request, "authentication.html", locals())
项目:wifi-attendance    作者:elvinzeng    | 项目源码 | 文件源码
def get(self, request):
        if request.user.has_perm("mobile_scanner.view_staffonlinehistory"):
            histories = OnlineHistory.objects.filter()\
                .values('date', 'user__last_name', 'user__first_name').annotate(min_time=Min('time'), max_time=Max('time')).order_by("-date")
            return render(request, "staff.html", locals())
        else:
            msg = "?????"
            return render(request, "msg.html", locals())
项目:autostew    作者:Autostew    | 项目源码 | 文件源码
def get_fastest_laps_by_vehicle(self, vehicle):
        return Lap.objects.filter(
            session__setup_actual__track=self,
            participant__vehicle=vehicle,
            count_this_lap=True,
            participant__is_player=True,
        ).values(
            'participant',
            'participant__member__steam_user__display_name',
            'participant__vehicle__name'
        ).annotate(fastest_lap_time=Min('lap_time')).order_by('fastest_lap_time')
项目:autostew    作者:Autostew    | 项目源码 | 文件源码
def get_fastest_laps_by_vehicle_class(self, vehicle_class):
        return Lap.objects.filter(
            session__setup_actual__track=self,
            participant__vehicle__vehicle_class=vehicle_class,
            count_this_lap=True,
            participant__is_player=True,
        ).values(
            'participant__name',
            'participant__vehicle__name'
        ).annotate(fastest_lap_time=Min('lap_time')).order_by('fastest_lap_time')
项目:autostew    作者:Autostew    | 项目源码 | 文件源码
def _best_in_stage_evaluation(self, field_name):
        return getattr(self, field_name) <= self.participant.lap_set.filter(
            **{
                '{}__gt'.format(field_name): 0,
                'session_stage': self.session_stage
            }
        ).aggregate(Min(field_name))['{}__min'.format(field_name)]
项目:ODM2WebSDL    作者:ODM2    | 项目源码 | 文件源码
def deployment_date(self):
        min_datetime = self.sensors.aggregate(first_light=Min('activation_date'))
        return min_datetime['first_light']
项目:ODM2WebSDL    作者:ODM2    | 项目源码 | 文件源码
def deployment_date(self):
        sampling_feature = self.sampling_feature
        min_datetime = sampling_feature.feature_actions.aggregate(first_light=Min('results__valid_datetime'))
        return min_datetime['first_light']
项目:tunga-api    作者:tunga-io    | 项目源码 | 文件源码
def started_at(self):
        return self.subtask_participants_inclusive_filter.filter(status=STATUS_ACCEPTED).aggregate(
            start_date=Min('activated_at'))['start_date']