当前位置: 首页>>代码示例>>Python>>正文


Python functions.TruncMonth方法代码示例

本文整理汇总了Python中django.db.models.functions.TruncMonth方法的典型用法代码示例。如果您正苦于以下问题:Python functions.TruncMonth方法的具体用法?Python functions.TruncMonth怎么用?Python functions.TruncMonth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.functions的用法示例。


在下文中一共展示了functions.TruncMonth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: spending_over_time

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import TruncMonth [as 别名]
def spending_over_time(self, request):
        fiscal_year = request.query_params.get("fiscal_year")

        queryset = self.filter_queryset(self.get_queryset())

        if fiscal_year:
            start_date, end_date = get_fiscal_year_range(int(fiscal_year))
            queryset = queryset.filter(
                date_of_grant__gte=start_date, date_of_grant__lte=end_date
            )

        queryset = (
            queryset.without_amendments()
            .annotate(month=TruncMonth("date_of_grant"))
            .values("month")
            .annotate(total=Sum("amount_to_pay"), count=Count("id"))
            .values("month", "total", "count")
            .order_by("month")
        )

        return Response(queryset) 
开发者ID:Code4PuertoRico,项目名称:contratospr-api,代码行数:23,代码来源:viewsets.py

示例2: stats_by_domain

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import TruncMonth [as 别名]
def stats_by_domain(domain):
    searches = (
        Search.objects
        .annotate(month=TruncMonth('created'))
        .values('month')
        .annotate(count=Count('id'))
        .values('month', 'count')
    )
    fetches = {}
    for s in searches:
        year = str(s['month'].year)
        month = str(s['month'].month)
        if year not in fetches:
            fetches[year] = {}
        fetches[year][month] = s['count']

    search = TitleDoc.search()
    search = search.filter('term', domain=domain.name)
    documents = search.execute().hits.total

    return fetches, documents 
开发者ID:peterbe,项目名称:autocompeter,代码行数:23,代码来源:views.py

示例3: stats

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import TruncMonth [as 别名]
def stats(self, last: int) -> OrderedDict:
        qs = self.filter(start_time__gte=now()-timedelta(days=last))
        qs = qs.annotate(
            day=dbfunc.TruncDay('start_time'),
            month=dbfunc.TruncMonth('start_time'),
            year=dbfunc.TruncYear('start_time'),
        )
        result = OrderedDict()
        result['day'] = self._get_history_stats_by(qs, 'day')
        result['month'] = self._get_history_stats_by(qs, 'month')
        result['year'] = self._get_history_stats_by(qs, 'year')
        return result 
开发者ID:vstconsulting,项目名称:polemarch,代码行数:14,代码来源:tasks.py

示例4: get

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import TruncMonth [as 别名]
def get(self, request, *args, **kwargs):
        per_month = json.loads(self.request.GET.get('per_month', 'false'))

        qs = self.get_queryset()

        if per_month:
            qs = qs.order_by('date') \
                .annotate(start=TruncMonth('date')) \
                .values('start') \
                .annotate(count=Sum('count')).order_by()
            data = list(qs)
            visible_interval = 360
        else:
            qs = qs.order_by('date') \
                .values(start=F('date')) \
                .annotate(count=Sum('count'))
            data = list(qs)
            date_list_view = DateUsageListAPIView(request=self.request, format_kwarg={})
            date_data = date_list_view.list(request=self.request).data
            visible_interval = 180

        max_value = qs.aggregate(m=Max('count'))['m']
        min_value = qs.aggregate(m=Min('count'))['m']
        range_value = max_value - min_value

        for item in data:
            item['weight'] = (item['count'] - min_value) / range_value
            if per_month:
                item['url'] = '{}?month_search={}'.format(
                    reverse('extract:date-usage-list'), item['start'].isoformat())
                item['content'] = '{}, {}: {}'.format(item['start'].strftime('%B'),
                                                      item['start'].year, item['count'])
            else:
                item['url'] = '{}?date_search={}'.format(
                    reverse('extract:date-usage-list'), item['start'].isoformat())
                item['content'] = '{}: {}'.format(item['start'].isoformat(), item['count'])
                item['date_data'] = [i for i in date_data if i['date'] == item['start']]

        initial_start_date = datetime.date.today() - datetime.timedelta(days=visible_interval)
        initial_end_date = datetime.date.today() + datetime.timedelta(days=visible_interval)
        ret = {'data': data,
               'per_month': per_month,
               'initial_start_date': initial_start_date,
               'initial_end_date': initial_end_date}
        return JsonResponse(ret) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:47,代码来源:v1.py


注:本文中的django.db.models.functions.TruncMonth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。