本文整理汇总了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;未经允许,请勿转载。 |
请发表评论