本文整理汇总了Python中qsstats.QuerySetStats.values方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySetStats.values方法的具体用法?Python QuerySetStats.values怎么用?Python QuerySetStats.values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qsstats.QuerySetStats
的用法示例。
在下文中一共展示了QuerySetStats.values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visitclick_data_json
# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import values [as 别名]
def visitclick_data_json(request, *args, **kwargs):
"""
For default this function return a data list of week
"""
google_format = {'rows':[],'cols':[
{'label':_('Time'),'type':'string','pattern':''},
{'label':_('Click'),'type':'number','pattern':''},
]}
if datetime.now().hour == 0:
date_init = datetime.now()-timedelta(hours=4)
else:
date_init = datetime.now().date()
date_end = datetime.now()
strftime='%H:%M'
field='date'
display='hours'
if 'week' in request.GET.values() or 'week' in request.POST.values():
date_end = get_first_dow(datetime.now().year, datetime.now().isocalendar()[1])
date_init = date_end-timedelta(days=6)
strftime='%d/%m'
display='days'
elif 'month' in request.GET.values() or 'month' in request.POST.values():
date_init = date(date_end.year,date_end.month,1)
strftime='%d/%m'
display='days'
elif 'year' in request.GET.values() or 'year' in request.POST.values():
date_init = datetime.now() - timedelta(days=365)
strftime='%m/%Y'
display='months'
elif 'custom' in request.GET.values() or 'custom' in request.POST.values():
date_init = datetime.strptime(request.POST.get('date_init',False) or request.GET.get('date_init'),'%Y-%m-%d')
date_end = datetime.strptime(request.POST.get('date_end',False) or request.GET.get('date_end'),'%Y-%m-%d')
date_diff = date_end-date_init
if (date_diff.days ==1):
strftime='%d/%m'
display='hours'
elif (date_diff.days >2 and date_diff.days <=31):
strftime='%d/%m'
display='days'
elif (date_diff.days > 31):
strftime='%d/%m'
display='months'
elif 'clicks' in request.GET.values() or 'clicks' in request.POST.values():
date_init = datetime.strptime(request.POST.get('date_init',False) or request.GET.get('date_init'),'%Y-%m-%d %H:%M:%S')
date_end = request.POST.get('date_end',False) or request.GET.get('date_end',False)
field='url'
google_format['cols']=[
{'label':_('Url'),'type':'string','pattern':''},
{'label':_('Click'),'type':'number','pattern':''},
]
if date_end:
date_end = datetime.strptime(date_end,'%Y-%m-%d %H:%M:%S')
else:
date_end =date_init+timedelta(hours=1)
elif 'browsers' in request.GET.values() or 'browsers' in request.POST.values():
field='browser'
google_format['cols']=[
{'label':_('Browsers'),'type':'string','pattern':''},
{'label':_('Click'),'type':'number','pattern':''},
]
elif 'operating_system' in request.GET.values() or 'operate_system' in request.POST.values():
field='operating_system'
google_format['cols']=[
{'label':_('Operating System'),'type':'string','pattern':''},
{'label':_('Click'),'type':'number','pattern':''},
]
clicks = Click.objects.filter(
Q(date__gte=date_init),
Q(date__lte=date_end)
)
if not ('clicks' in request.GET.values() or 'clicks' in request.POST.values()) and \
not ('browsers' in request.GET.values() or 'browsers' in request.POST.values()) and \
not ('operating_system' in request.GET.values() or 'operating_system' in request.POST.values()):
clicks = QuerySetStats(clicks, field).time_series(date_init,date_end, display,aggregate=Count(field))
else:
clicks= clicks.values(field).order_by(field).annotate(count=Count(field))
if field == 'date':
google_format['cols']=[
{'label':_('Date'),'type':'string','pattern':''},
{'label':_('Click'),'type':'number','pattern':''},
]
for click in clicks:
if type(click) is tuple:
value_line=click[0]
label_line=click[0]
#.........这里部分代码省略.........