Commit f917478d authored by zhengjinlei's avatar zhengjinlei

创建定时任务

parent e5041c7c
...@@ -14,6 +14,7 @@ import datetime ...@@ -14,6 +14,7 @@ import datetime
import os import os
import pymysql import pymysql
import raven import raven
from .loggings import LOGGING
from . import config from . import config
......
...@@ -42,8 +42,8 @@ class TasksApi(viewsets.ViewSet): ...@@ -42,8 +42,8 @@ class TasksApi(viewsets.ViewSet):
:return: :return:
""" """
task_id = req.GET.get('task', '') task_id = req.GET.get('task', '')
start_date = req.data.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')) start_date = req.GET.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.GET.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}
......
...@@ -3,11 +3,13 @@ from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, Scor ...@@ -3,11 +3,13 @@ from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, Scor
from config.config import TABLE_PRE from config.config import TABLE_PRE
import json import json
import logging import logging
import kronos
from datetime import datetime, timedelta
"""定时任务 """定时任务
参考:https://github.com/jgorset/django-kronos 参考:https://github.com/jgorset/django-kronos
""" """
logger = logging.getLogger("app_file") logger = logging.getLogger('app_file')
score_item_zero = {'违规则零分': 100, '敏感词': 100} score_item_zero = {'违规则零分': 100, '敏感词': 100}
score_item_service = {'异议处理': 10, '业务促成': 15, '预约及流转': 15, '服务介绍': 5, '6_引导流程_2个场景': 0, '未提供报价': 5, score_item_service = {'异议处理': 10, '业务促成': 15, '预约及流转': 15, '服务介绍': 5, '6_引导流程_2个场景': 0, '未提供报价': 5,
'未做优惠费率介绍': 5} '未做优惠费率介绍': 5}
...@@ -15,11 +17,16 @@ score_item_business = {'结束语': 5, '服务态度': 10, '服务用语': 10, ' ...@@ -15,11 +17,16 @@ score_item_business = {'结束语': 5, '服务态度': 10, '服务用语': 10, '
'开场白': 10} '开场白': 10}
def rule_stat(start_date, end_date): @kronos.register('0 1 * * *')
def rule_stat(start_date=None, end_date=None):
""" """
首页概述-违规项统计 首页概述-违规项统计
:return: :return:
""" """
if not start_date and not end_date:
start_date = (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')
end_date = datetime.now().strftime('%Y-%m-%d')
logger.info('[rule_stat]rule stat start...')
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date} task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date}
tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId') tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId')
stat_count = 0 stat_count = 0
...@@ -47,18 +54,24 @@ def rule_stat(start_date, end_date): ...@@ -47,18 +54,24 @@ def rule_stat(start_date, end_date):
'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
logger.info('统计数量为:%s' % stat_count)
RulesStat.objects.bulk_create(rules_list) RulesStat.objects.bulk_create(rules_list)
logger.info('[rule_stat]rule stat num: [%s]', stat_count)
logger.info('[rule_stat]rule stat end.')
def seat_stat(start_date, end_date): @kronos.register('0 1 * * *')
def seat_stat(start_date=None, end_date=None):
""" """
首页概述-违规统计 首页概述-违规坐席统计
:return: :return:
""" """
if not start_date and not end_date:
start_date = (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')
end_date = datetime.now().strftime('%Y-%m-%d')
logger.info('[seat_stat]violate seat stat start...')
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date} task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date}
tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId') tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId')
stat_count = 0
for t in tasks: for t in tasks:
if SeatStat.objects.filter(taskId=t['id']).exists(): if SeatStat.objects.filter(taskId=t['id']).exists():
continue continue
...@@ -69,6 +82,7 @@ def seat_stat(start_date, end_date): ...@@ -69,6 +82,7 @@ def seat_stat(start_date, end_date):
seat_dict = {} seat_dict = {}
seat_list = [] seat_list = []
for check in checks: for check in checks:
stat_count += 1
if check['agentName'] in seat_dict.keys(): if check['agentName'] in seat_dict.keys():
seat = seat_dict.get(check['agentName']) seat = seat_dict.get(check['agentName'])
seat['total_session'] += 1 seat['total_session'] += 1
...@@ -83,16 +97,23 @@ def seat_stat(start_date, end_date): ...@@ -83,16 +97,23 @@ def seat_stat(start_date, end_date):
seat_obj.update(v) seat_obj.update(v)
seat_list.append(SeatStat(**seat_obj)) seat_list.append(SeatStat(**seat_obj))
SeatStat.objects.bulk_create(seat_list) SeatStat.objects.bulk_create(seat_list)
logger.info('[seat_stat]violate seat count: [%s]', stat_count)
logger.info('[seat_stat]violate seat stat end.')
def score_stat(start_date, end_date): @kronos.register('0 1 * * *')
def score_stat(start_date=None, end_date=None):
""" """
坐席违规统计 坐席得分统计
:return: :return:
""" """
if not start_date and not end_date:
start_date = (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')
end_date = datetime.now().strftime('%Y-%m-%d')
logger.info('[score_stat]seat score stat start...')
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date} task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date}
tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId') tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId')
stat_count = 0
for t in tasks: for t in tasks:
if ScoreStat.objects.filter(taskId=t['id']).exists(): if ScoreStat.objects.filter(taskId=t['id']).exists():
continue continue
...@@ -104,6 +125,7 @@ def score_stat(start_date, end_date): ...@@ -104,6 +125,7 @@ def score_stat(start_date, end_date):
seat_dict = {} seat_dict = {}
seat_list = [] seat_list = []
for check in checks: for check in checks:
stat_count += 1
score_item = json.loads(check['scoreItemRecord']) score_item = json.loads(check['scoreItemRecord'])
service_score = 55 service_score = 55
business_score = 45 business_score = 45
...@@ -141,3 +163,5 @@ def score_stat(start_date, end_date): ...@@ -141,3 +163,5 @@ def score_stat(start_date, end_date):
seat_obj.update(v) seat_obj.update(v)
seat_list.append(ScoreStat(**seat_obj)) seat_list.append(ScoreStat(**seat_obj))
ScoreStat.objects.bulk_create(seat_list) ScoreStat.objects.bulk_create(seat_list)
logger.info('[score_stat]seat count: [%s]', stat_count)
logger.info('[score_stat]seat score 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