Commit a087e668 authored by zhengjinlei's avatar zhengjinlei

统计通话时长

parent e69ce62e
...@@ -37,19 +37,25 @@ def rule_stat(start_date=None, end_date=None): ...@@ -37,19 +37,25 @@ def rule_stat(start_date=None, end_date=None):
tn = CheckSession.set_table(table_name) tn = CheckSession.set_table(table_name)
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', 'startTime', 'closeTime', 'taskId',
'sessionId')
for check in checks: for check in checks:
result = check['checkResult'] result = check['checkResult']
if result: if result:
rules_list = [] rules_list = []
data = json.loads(result) data = json.loads(result)
for d in data: for d in data:
remain = 0
if check['startTime'] and check['closeTime']:
start = datetime.strptime(check['startTime'], '%Y-%m-%d %H:%M:%S').timestamp()
close = datetime.strptime(check['closeTime'], '%Y-%m-%d %H:%M:%S').timestamp()
remain = int(close - start)
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():
name = d['rule']['name'] name = d['rule']['name']
rule_obj = {'create_date': start_date, 'sessionCollectionId': t['sessionCollectionId'], rule_obj = {'create_date': start_date, 'sessionCollectionId': t['sessionCollectionId'],
'rule': name, 'rule_num': 1, 'task': t['name'].split('_')[0], 'rule': name, 'rule_num': 1, 'task': t['name'].split('_')[0],
'agentName': check['agentName'], 'customName': check['customName'], 'agentName': check['agentName'], 'customName': check['customName'],
'score': check['score'], 'remainTime': check['remainTime'], 'score': check['score'], 'remainTime': remain,
'taskId': check['taskId'], 'sessionId': check['sessionId'], 'taskId': check['taskId'], 'sessionId': check['sessionId'],
'session_table_id': check['id']} 'session_table_id': check['id']}
rules_list.append(RulesStat(**rule_obj)) rules_list.append(RulesStat(**rule_obj))
...@@ -79,23 +85,28 @@ def seat_stat(start_date=None, end_date=None): ...@@ -79,23 +85,28 @@ def seat_stat(start_date=None, end_date=None):
table_name = TABLE_PRE + t['sessionCollectionId'] table_name = TABLE_PRE + t['sessionCollectionId']
tn = CheckSession.set_table(table_name) tn = CheckSession.set_table(table_name)
session_condition = {'taskId': t['id']} session_condition = {'taskId': t['id']}
checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'remainTime', 'taskId', checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'remainTime', 'startTime',
'violationRuleCount') 'closeTime', 'taskId', 'violationRuleCount')
seat_dict = {} seat_dict = {}
seat_list = [] seat_list = []
for check in checks: for check in checks:
stat_count += 1 stat_count += 1
remain = 0
if check['startTime'] and check['closeTime']:
start = datetime.strptime(check['startTime'], '%Y-%m-%d %H:%M:%S').timestamp()
close = datetime.strptime(check['closeTime'], '%Y-%m-%d %H:%M:%S').timestamp()
remain = int(close - start)
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
seat['remainTime'] += check['remainTime'] seat['remainTime'] += remain
seat['validate_session'] += 1 if check['violationRuleCount'] > 0 else 0 seat['validate_session'] += 1 if check['violationRuleCount'] > 0 else 0
else: else:
seat_dict[check['agentName']] = {'create_date': start_date, 'agentName': check['agentName'], seat_dict[check['agentName']] = {'create_date': start_date, 'agentName': check['agentName'],
'taskId': check['taskId'], 'task': t['name'].split('_')[0], 'taskId': check['taskId'], 'task': t['name'].split('_')[0],
'sessionCollectionId': t['sessionCollectionId'], 'total_session': 1} 'sessionCollectionId': t['sessionCollectionId'], 'total_session': 1}
seat_dict[check['agentName']]['validate_session'] = 1 if check['violationRuleCount'] > 0 else 0 seat_dict[check['agentName']]['validate_session'] = 1 if check['violationRuleCount'] > 0 else 0
seat_dict[check['agentName']]['remainTime'] = check['remainTime'] seat_dict[check['agentName']]['remainTime'] = remain
for k, v in seat_dict.items(): for k, v in seat_dict.items():
seat_obj = {'agentName': k} seat_obj = {'agentName': k}
seat_obj.update(v) seat_obj.update(v)
...@@ -183,6 +194,23 @@ def seat_time_stat(start_date=None, end_date=None): ...@@ -183,6 +194,23 @@ def seat_time_stat(start_date=None, end_date=None):
logger.info(start_date) logger.info(start_date)
logger.info(end_date) logger.info(end_date)
task_condition = {'create_date__gte': start_date, 'create_date__lt': end_date} task_condition = {'create_date__gte': start_date, 'create_date__lt': end_date}
rules = RulesStat.objects.filter(**task_condition)
stat_count = 0
for t in rules:
if not t.remainTime:
stat_count += 1
table_name = TABLE_PRE + t.sessionCollectionId
tn = CheckSession.set_table(table_name)
check = tn.objects.get(pk=t.session_table_id)
remain = 0
if check and check.startTime and check.closeTime:
start = datetime.strptime(check.startTime, '%Y-%m-%d %H:%M:%S').timestamp()
close = datetime.strptime(check.closeTime, '%Y-%m-%d %H:%M:%S').timestamp()
remain = int(close - start)
t.remainTime = remain
t.save(update_fields=['remainTime'])
"""
坐席统计
seats = SeatStat.objects.filter(**task_condition) seats = SeatStat.objects.filter(**task_condition)
stat_count = 0 stat_count = 0
for t in seats: for t in seats:
...@@ -191,11 +219,17 @@ def seat_time_stat(start_date=None, end_date=None): ...@@ -191,11 +219,17 @@ def seat_time_stat(start_date=None, end_date=None):
table_name = TABLE_PRE + t.sessionCollectionId table_name = TABLE_PRE + t.sessionCollectionId
tn = CheckSession.set_table(table_name) tn = CheckSession.set_table(table_name)
session_condition = {'taskId': t.taskId, 'agentName': t.agentName} session_condition = {'taskId': t.taskId, 'agentName': t.agentName}
checks = tn.objects.filter(**session_condition).values('remainTime') checks = tn.objects.filter(**session_condition).values('startTime', 'closeTime')
total_time = 0 total_time = 0
for check in checks: for check in checks:
total_time += check['remainTime'] if check['startTime'] and check['closeTime']:
start = datetime.strptime(check['startTime'], '%Y-%m-%d %H:%M:%S').timestamp()
close = datetime.strptime(check['closeTime'], '%Y-%m-%d %H:%M:%S').timestamp()
remain = int(close - start)
total_time += remain
t.remainTime = total_time t.remainTime = total_time
t.save(update_fields=['remainTime']) t.save(update_fields=['remainTime'])
"""
logger.info('[seat_stat]seat time count: [%s]', stat_count) logger.info('[seat_stat]seat time count: [%s]', stat_count)
logger.info('[seat_stat]seat time stat end.') logger.info('[seat_stat]seat time 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