Commit 7ab2f372 authored by zhengjinlei's avatar zhengjinlei

报表提供下载功能

parent 8a1a71fa
......@@ -2,3 +2,4 @@
# from .user import UserApi
from .toolapi import ToolsApi
from .tasksapi import TasksApi
from .dataapi import DataApi
This diff is collapsed.
......@@ -199,11 +199,14 @@ class TasksApi(viewsets.ViewSet):
if agent_name:
task_condition['agentName'] = agent_name
if sort == 'des':
seats = SeatStat.objects.filter(**task_condition).values('agentName', 'validate_session', 'total_session')\
.order_by('-validate_session')
seats = SeatStat.objects.filter(**task_condition).extra(select={'agentName': 'agentName'}) \
.values('agentName').annotate(remainTime=Sum('remainTime'), validate_session=Sum('validate_session'),
total_session=Sum('total_session')).order_by('-validate_session')
else:
seats = SeatStat.objects.filter(**task_condition).values('agentName', 'validate_session', 'total_session') \
.order_by('validate_session')
seats = SeatStat.objects.filter(**task_condition).extra(select={'agentName': 'agentName'}) \
.values('agentName').annotate(remainTime=Sum('remainTime'), validate_session=Sum('validate_session'),
total_session=Sum('total_session')).order_by('validate_session')
paginator = Paginator(seats, page_size)
total_count = paginator.count
try:
......@@ -215,7 +218,8 @@ class TasksApi(viewsets.ViewSet):
return_data = []
for s in seats:
detail = {'agentName': s['agentName'], 'validate_session': s['validate_session'],
'total_session': s['total_session'], 'ratio': round(s['validate_session']/s['total_session'], 2)}
'remainTime': s['remainTime'], 'total_session': s['total_session'],
'ratio': round(s['validate_session']/s['total_session'], 2)}
return_data.append(detail)
if sort == 'asc':
data_sort = sorted(return_data, key=lambda x: x['ratio'])
......
......@@ -78,7 +78,8 @@ def seat_stat(start_date=None, end_date=None):
table_name = TABLE_PRE + t['sessionCollectionId']
tn = CheckSession.set_table(table_name)
session_condition = {'taskId': t['id']}
checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'taskId', 'violationRuleCount')
checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'remainTime', 'taskId',
'violationRuleCount')
seat_dict = {}
seat_list = []
for check in checks:
......@@ -86,12 +87,14 @@ def seat_stat(start_date=None, end_date=None):
if check['agentName'] in seat_dict.keys():
seat = seat_dict.get(check['agentName'])
seat['total_session'] += 1
seat['remainTime'] = check['remainTime']
seat['validate_session'] += 1 if check['violationRuleCount'] > 0 else 0
else:
seat_dict[check['agentName']] = {'create_date': start_date, 'agentName': check['agentName'],
'taskId': check['taskId'], 'task': t['name'].split('_')[0],
'sessionCollectionId': t['sessionCollectionId'], 'total_session': 1}
seat_dict[check['agentName']]['validate_session'] = 1 if check['violationRuleCount'] > 0 else 0
seat_dict[check['agentName']]['remainTime'] = check['remainTime']
for k, v in seat_dict.items():
seat_obj = {'agentName': k}
seat_obj.update(v)
......
......@@ -22,6 +22,7 @@ from . import api
router = routers.DefaultRouter()
router.register(r'tools', api.ToolsApi, base_name='tools')
router.register(r'tasks', api.TasksApi, base_name='tasks')
router.register(r'data', api.DataApi, base_name='data')
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
......
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