Commit a087e668 authored by zhengjinlei's avatar zhengjinlei

统计通话时长

parent e69ce62e
......@@ -37,19 +37,25 @@ def rule_stat(start_date=None, end_date=None):
tn = CheckSession.set_table(table_name)
session_condition = {'taskId': t['id'], 'violationRuleCount__gt': 0}
checks = tn.objects.filter(**session_condition).values('id', 'checkResult', 'agentName', 'customName', 'score',
'remainTime', 'taskId', 'sessionId')
'remainTime', 'startTime', 'closeTime', 'taskId',
'sessionId')
for check in checks:
result = check['checkResult']
if result:
rules_list = []
data = json.loads(result)
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():
name = d['rule']['name']
rule_obj = {'create_date': start_date, 'sessionCollectionId': t['sessionCollectionId'],
'rule': name, 'rule_num': 1, 'task': t['name'].split('_')[0],
'agentName': check['agentName'], 'customName': check['customName'],
'score': check['score'], 'remainTime': check['remainTime'],
'score': check['score'], 'remainTime': remain,
'taskId': check['taskId'], 'sessionId': check['sessionId'],
'session_table_id': check['id']}
rules_list.append(RulesStat(**rule_obj))
......@@ -79,23 +85,28 @@ 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', 'remainTime', 'taskId',
'violationRuleCount')
checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'remainTime', 'startTime',
'closeTime', 'taskId', 'violationRuleCount')
seat_dict = {}
seat_list = []
for check in checks:
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():
seat = seat_dict.get(check['agentName'])
seat['total_session'] += 1
seat['remainTime'] += check['remainTime']
seat['remainTime'] += remain
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']
seat_dict[check['agentName']]['remainTime'] = remain
for k, v in seat_dict.items():
seat_obj = {'agentName': k}
seat_obj.update(v)
......@@ -183,6 +194,23 @@ def seat_time_stat(start_date=None, end_date=None):
logger.info(start_date)
logger.info(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)
stat_count = 0
for t in seats:
......@@ -191,11 +219,17 @@ def seat_time_stat(start_date=None, end_date=None):
table_name = TABLE_PRE + t.sessionCollectionId
tn = CheckSession.set_table(table_name)
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
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.save(update_fields=['remainTime'])
"""
logger.info('[seat_stat]seat time count: [%s]', stat_count)
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