Commit 7abc3100 authored by zhengjinlei's avatar zhengjinlei

违规项统计

parent 04441033
...@@ -93,7 +93,10 @@ class TasksApi(viewsets.ViewSet): ...@@ -93,7 +93,10 @@ class TasksApi(viewsets.ViewSet):
task_condition['task'] = task_id task_condition['task'] = task_id
if agent_name: if agent_name:
task_condition['agentName'] = agent_name task_condition['agentName'] = agent_name
tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num') # tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num')
tasks = RulesStat.objects.all().filter(**task_condition) \
.extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'}) \
.values('rule', 'sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num')
for t in tasks: for t in tasks:
name = t['rule'] name = t['rule']
if name in return_data.keys(): if name in return_data.keys():
...@@ -106,7 +109,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -106,7 +109,7 @@ class TasksApi(viewsets.ViewSet):
for k, v in return_data.items(): for k, v in return_data.items():
v['rule'] = k v['rule'] = k
data_sort.append(v) data_sort.append(v)
data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True) # data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True)
return Response({'code': 0, 'msg': 'success', 'data': data_sort}) return Response({'code': 0, 'msg': 'success', 'data': data_sort})
@action(['post'], detail=False) @action(['post'], detail=False)
...@@ -563,7 +566,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -563,7 +566,7 @@ class TasksApi(viewsets.ViewSet):
# tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num') # tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num')
tasks = RulesStat.objects.all().filter(**task_condition)\ tasks = RulesStat.objects.all().filter(**task_condition)\
.extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'})\ .extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'})\
.values('rule','sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num') .values('rule', 'sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num')
for t in tasks: for t in tasks:
name = t['rule'] name = t['rule']
if name in return_data.keys(): if name in return_data.keys():
...@@ -578,7 +581,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -578,7 +581,7 @@ class TasksApi(viewsets.ViewSet):
v['ratio'] = round(v['count']/call_count, 2) if call_count else 0 v['ratio'] = round(v['count']/call_count, 2) if call_count else 0
v['call_count'] = call_count v['call_count'] = call_count
data_sort.append(v) data_sort.append(v)
data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True) # data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True)
return Response({'code': 0, 'msg': 'success', 'data': data_sort}) return Response({'code': 0, 'msg': 'success', 'data': data_sort})
@action(['post'], detail=False) @action(['post'], detail=False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment