本文整理汇总了Python中fjord.feedback.models.ResponseMappingType.reshape方法的典型用法代码示例。如果您正苦于以下问题:Python ResponseMappingType.reshape方法的具体用法?Python ResponseMappingType.reshape怎么用?Python ResponseMappingType.reshape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fjord.feedback.models.ResponseMappingType
的用法示例。
在下文中一共展示了ResponseMappingType.reshape方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: response_view
# 需要导入模块: from fjord.feedback.models import ResponseMappingType [as 别名]
# 或者: from fjord.feedback.models.ResponseMappingType import reshape [as 别名]
def response_view(request, responseid, template):
response = get_object_or_404(Response, id=responseid)
try:
prod = Product.objects.get(db_name=response.product)
if (not prod.on_dashboard
and (not request.user.is_authenticated()
or not request.user.has_perm(
'analytics.can_view_dashboard'))):
# If this is a response for a hidden product and the user
# isn't in the analytics group, then they can't see it.
return HttpResponseForbidden()
except Product.DoesNotExist:
pass
mlt = None
records = None
errors = []
if (request.user.is_authenticated()
and request.user.has_perm('analytics.can_view_dashboard')):
try:
# Convert it to a list to force it to execute right now.
mlt = ResponseMappingType.reshape(
ResponseMappingType.morelikethis(response))
except ElasticsearchException as exc:
errors.append('Failed to do morelikethis: %s' % exc)
records = [
(u'Response records', Record.objects.records(response)),
]
jobs = GengoJob.objects.filter(
object_id=response.id,
content_type=ContentType.objects.get_for_model(response)
)
for job in jobs:
records.append(
(u'Gengo job record {0}'.format(job.id), job.records)
)
# We don't pass the response directly to the template and instead
# do some data tweaks here to make it more palatable for viewing.
return render(request, template, {
'errors': errors,
'response': response,
'mlt': mlt,
'records': records,
})
示例2: analytics_duplicates
# 需要导入模块: from fjord.feedback.models import ResponseMappingType [as 别名]
# 或者: from fjord.feedback.models.ResponseMappingType import reshape [as 别名]
def analytics_duplicates(request):
"""Shows all duplicate descriptions over the last n days"""
template = 'analytics/analyzer/duplicates.html'
n = 14
responses = (ResponseMappingType.search()
.filter(created__gte=datetime.now() - timedelta(days=n))
.values_dict('description', 'happy', 'created', 'locale',
'user_agent', 'id')
.order_by('created').everything())
responses = ResponseMappingType.reshape(responses)
total_count = len(responses)
response_dupes = {}
for resp in responses:
response_dupes.setdefault(resp['description'], []).append(resp)
response_dupes = [
(key, val) for key, val in response_dupes.items()
if len(val) > 1
]
# convert the dict into a list of tuples sorted by the number of
# responses per tuple largest number first
response_dupes = sorted(response_dupes, key=lambda item: len(item[1]) * -1)
# duplicate_count -> count
# i.e. "how many responses had 2 duplicates?"
summary_counts = defaultdict(int)
for desc, responses in response_dupes:
summary_counts[len(responses)] = summary_counts[len(responses)] + 1
summary_counts = sorted(summary_counts.items(), key=lambda item: item[0])
return render(request, template, {
'n': 14,
'response_dupes': response_dupes,
'render_time': datetime.now(),
'summary_counts': summary_counts,
'total_count': total_count,
})
示例3: response_view
# 需要导入模块: from fjord.feedback.models import ResponseMappingType [as 别名]
# 或者: from fjord.feedback.models.ResponseMappingType import reshape [as 别名]
def response_view(request, responseid, template):
response = get_object_or_404(Response, id=responseid)
mlt = None
records = None
errors = []
if (request.user.is_authenticated()
and request.user.has_perm('analytics.can_view_dashboard')):
try:
# Convert it to a list to force it to execute right now.
mlt = ResponseMappingType.reshape(
ResponseMappingType.morelikethis(response))
except ElasticsearchException as exc:
errors.append('Failed to do morelikethis: %s' % exc)
records = [
(u'Response records', Record.objects.records(response)),
]
jobs = GengoJob.objects.filter(
object_id=response.id,
content_type=ContentType.objects.get_for_model(response)
)
for job in jobs:
records.append(
(u'Gengo job record {0}'.format(job.id), job.records)
)
# We don't pass the response directly to the template and instead
# do some data tweaks here to make it more palatable for viewing.
return render(request, template, {
'errors': errors,
'response': response,
'mlt': mlt,
'records': records,
})