Commit ac8fa273 authored by zhengjinlei's avatar zhengjinlei

统计违规项

parent 4ea3c1df
...@@ -565,7 +565,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -565,7 +565,7 @@ class TasksApi(viewsets.ViewSet):
start_date = req.data.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')) start_date = req.data.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d'))
end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d')) end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d'))
q_start_date = datetime.strptime(start_date, '%Y-%m-%d').date() q_start_date = datetime.strptime(start_date, '%Y-%m-%d').date()
q_end_date = (datetime.strptime(end_date, '%Y-%m-%d') + + timedelta(days=1)).date() q_end_date = (datetime.strptime(end_date, '%Y-%m-%d') + timedelta(days=1)).date()
session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date} session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date}
if agent_name: if agent_name:
......
...@@ -38,10 +38,10 @@ def rule_stat(start_date=None, end_date=None): ...@@ -38,10 +38,10 @@ def rule_stat(start_date=None, end_date=None):
session_condition = {'taskId': t['id'], 'violationRuleCount__gt': 0} session_condition = {'taskId': t['id'], 'violationRuleCount__gt': 0}
checks = tn.objects.filter(**session_condition).values('id', 'checkResult', 'agentName', 'customName', 'score', checks = tn.objects.filter(**session_condition).values('id', 'checkResult', 'agentName', 'customName', 'score',
'remainTime', 'taskId', 'sessionId') 'remainTime', 'taskId', 'sessionId')
rules_list = []
for check in checks: for check in checks:
result = check['checkResult'] result = check['checkResult']
if result: if result:
rules_list = []
data = json.loads(result) data = json.loads(result)
for d in data: for d in data:
if 'isViolation' in d.keys() and d['isViolation'] and 'rule' in d.keys() and 'name' in d['rule'].keys(): if 'isViolation' in d.keys() and d['isViolation'] and 'rule' in d.keys() and 'name' in d['rule'].keys():
...@@ -54,7 +54,8 @@ def rule_stat(start_date=None, end_date=None): ...@@ -54,7 +54,8 @@ def rule_stat(start_date=None, end_date=None):
'session_table_id': check['id']} 'session_table_id': check['id']}
rules_list.append(RulesStat(**rule_obj)) rules_list.append(RulesStat(**rule_obj))
stat_count += 1 stat_count += 1
RulesStat.objects.bulk_create(rules_list) logger.info('rule stat num: [%s]', stat_count)
RulesStat.objects.bulk_create(rules_list)
logger.info('[rule_stat]rule stat num: [%s]', stat_count) logger.info('[rule_stat]rule stat num: [%s]', stat_count)
logger.info('[rule_stat]rule stat end.') logger.info('[rule_stat]rule stat end.')
......
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