• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.has_charts函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.utils.db.has_charts函数的典型用法代码示例。如果您正苦于以下问题:Python has_charts函数的具体用法?Python has_charts怎么用?Python has_charts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_chart_data

    def get_chart_data(self, instance, max_days=90):
        if hasattr(instance, '_state'):
            db = instance._state.db or 'default'
        else:
            db = 'default'

        if not has_charts(db):
            return []

        hours = max_days * 24
        today = datetime.datetime.now().replace(microsecond=0, second=0, minute=0)
        min_date = today - datetime.timedelta(hours=hours)

        method = get_sql_date_trunc('date', db)

        chart_qs = list(instance.messagecountbyminute_set\
                          .filter(date__gte=min_date)\
                          .extra(select={'grouper': method}).values('grouper')\
                          .annotate(num=Sum('times_seen')).values_list('grouper', 'num')\
                          .order_by('grouper'))

        if not chart_qs:
            return []

        rows = dict(chart_qs)

        #just skip zeroes
        first_seen = hours
        while not rows.get(today - datetime.timedelta(hours=first_seen)) and first_seen > 24:
            first_seen -= 1

        return [rows.get(today - datetime.timedelta(hours=d), 0) for d in xrange(first_seen, -1, -1)]
开发者ID:bgyss,项目名称:sentry,代码行数:32,代码来源:manager.py


示例2: has_charts

def has_charts(group):
    from sentry.utils.db import has_charts
    if hasattr(group, '_state'):
        db = group._state.db or 'default'
    else:
        db = 'default'
    return has_charts(db)
开发者ID:AnguelSC,项目名称:sentry,代码行数:7,代码来源:sentry_helpers.py


示例3: get_chart_data_for_group

    def get_chart_data_for_group(self, instances, max_days=90):
        if not instances:
            return []

        if hasattr(instances[0], '_state'):
            db = instances[0]._state.db or 'default'
        else:
            db = 'default'

        if not has_charts(db):
            return []

        hours = max_days * 24
        today = datetime.datetime.now().replace(microsecond=0, second=0, minute=0)
        min_date = today - datetime.timedelta(hours=hours)

        method = get_sql_date_trunc('date', db)

        field = self.model.messagecountbyminute_set.related
        column = field.field.name
        chart_qs = list(field.model.objects.filter(**{
            '%s__in' % column: instances,
            'date__gte': min_date,
        }).extra(
            select={
                'grouper': method,
            }
        ).values('grouper').annotate(
            num=Sum('times_seen'),
        ).values_list('grouper', 'num'))

        rows = dict(chart_qs)

        return [rows.get(today - datetime.timedelta(hours=d), 0) for d in xrange(hours, -1, -1)]
开发者ID:NewAgeDev,项目名称:sentry,代码行数:34,代码来源:manager.py


示例4: _get_chart_data

    def _get_chart_data(self, queryset, max_days=90, db='default'):
        if not has_charts(db):
            return []

        today = timezone.now().replace(microsecond=0, second=0, minute=0)
        min_date = today - datetime.timedelta(days=max_days)

        if max_days > 30:
            g_type = 'hour'
            d_type = 'hours'
            points = max_days * 24
            modifier = 1
        else:
            g_type = 'minute'
            d_type = 'minutes'
            points = max_days * 24 * 15
            modifier = 5

        method = get_sql_date_trunc('date', db, grouper=g_type)

        chart_qs = list(queryset.filter(date__gte=min_date)
                        .extra(select={'grouper': method}).values('grouper')
                        .annotate(num=Sum('times_seen')).values_list('grouper', 'num')
                        .order_by('grouper'))

        rows = dict(chart_qs)

        results = []
        for point in xrange(points, -1, -1):
            dt = today - datetime.timedelta(**{d_type: point * modifier})
            results.append((int((dt).strftime('%s')) * 1000, rows.get(dt, 0)))
        return results
开发者ID:Crowdbooster,项目名称:sentry,代码行数:32,代码来源:manager.py


示例5: _get_chart_data

    def _get_chart_data(self, queryset, max_days=90, db="default", key=None):
        if not has_charts(db):
            if key is None:
                return []
            return {}

        today = timezone.now().replace(microsecond=0, second=0)

        # the last interval is not accurate, so we exclude it
        # TODO: it'd be ideal to normalize the last datapoint so that we can include it
        # and not have ~inaccurate data for up to MINUTE_NORMALIZATION
        today -= datetime.timedelta(minutes=settings.MINUTE_NORMALIZATION)

        if max_days >= 30:
            g_type = "date"
            d_type = "days"
            points = max_days
            modifier = 1
            today = today.replace(hour=0)
        elif max_days >= 1:
            g_type = "hour"
            d_type = "hours"
            points = max_days * 24
            modifier = 1
            today = today.replace(minute=0)
        else:
            g_type = "minute"
            d_type = "minutes"
            modifier = settings.MINUTE_NORMALIZATION
            points = max_days * 24 * (60 / modifier)

        min_date = today - datetime.timedelta(days=max_days)

        method = get_sql_date_trunc("date", db, grouper=g_type)

        chart_qs = queryset.filter(date__gte=min_date).extra(select={"grouper": method})
        if key:
            chart_qs = chart_qs.values("grouper", key)
        else:
            chart_qs = chart_qs.values("grouper")

        chart_qs = chart_qs.annotate(num=Sum("times_seen"))
        if key:
            chart_qs = chart_qs.values_list(key, "grouper", "num").order_by(key, "grouper")
        else:
            chart_qs = chart_qs.values_list("grouper", "num").order_by("grouper")

        if key is None:
            rows = {None: dict(chart_qs)}
        else:
            rows = {}
            for item, grouper, num in chart_qs:
                if item not in rows:
                    rows[item] = {}
                rows[item][grouper] = num

        results = {}
        for item, tsdata in rows.iteritems():
            results[item] = []
            for point in xrange(points, -1, -1):
                dt = today - datetime.timedelta(**{d_type: point * modifier})
                results[item].append((int((dt).strftime("%s")) * 1000, tsdata.get(dt, 0)))

        if key is None:
            return results[None]
        return results
开发者ID:turleyhari,项目名称:sentry,代码行数:66,代码来源:manager.py


示例6: _get_chart_data

    def _get_chart_data(self, queryset, max_days=90, db='default', key=None):
        if not has_charts(db):
            if key is None:
                return []
            return {}

        today = timezone.now().replace(microsecond=0, second=0)

        # the last interval is not accurate, so we exclude it
        # TODO: it'd be ideal to normalize the last datapoint so that we can include it
        # and not have ~inaccurate data for up to MINUTE_NORMALIZATION
        today -= datetime.timedelta(minutes=MINUTE_NORMALIZATION)

        if max_days >= 30:
            g_type = 'date'
            d_type = 'days'
            points = max_days
            modifier = 1
            today = today.replace(hour=0)
        elif max_days >= 1:
            g_type = 'hour'
            d_type = 'hours'
            points = max_days * 24
            modifier = 1
            today = today.replace(minute=0)
        else:
            g_type = 'minute'
            d_type = 'minutes'
            modifier = MINUTE_NORMALIZATION
            points = max_days * 24 * (60 / modifier)

        min_date = today - datetime.timedelta(days=max_days)

        method = get_sql_date_trunc('date', db, grouper=g_type)

        chart_qs = queryset.filter(
            date__gte=min_date,
        ).extra(
            select={'grouper': method},
        )
        if key:
            chart_qs = chart_qs.values('grouper', key)
        else:
            chart_qs = chart_qs.values('grouper')

        chart_qs = chart_qs.annotate(
            num=Sum('times_seen'),
        )
        if key:
            chart_qs = chart_qs.values_list(key, 'grouper', 'num').order_by(key, 'grouper')
        else:
            chart_qs = chart_qs.values_list('grouper', 'num').order_by('grouper')

        if key is None:
            rows = {None: dict(chart_qs)}
        else:
            rows = {}
            for item, grouper, num in chart_qs:
                if item not in rows:
                    rows[item] = {}
                rows[item][grouper] = num

        results = {}
        for item, tsdata in rows.iteritems():
            results[item] = []
            for point in xrange(points, -1, -1):
                dt = today - datetime.timedelta(**{d_type: point * modifier})
                results[item].append((int(time.mktime((dt).timetuple())) * 1000, tsdata.get(dt, 0)))

        if key is None:
            return results[None]
        return results
开发者ID:Tug,项目名称:sentry,代码行数:72,代码来源:manager.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python db.has_trending函数代码示例发布时间:2022-05-27
下一篇:
Python db.get_db_engine函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap