Commit 8a1a71fa authored by zhengjinlei's avatar zhengjinlei

统计时长

parent 13dd2df8
......@@ -165,3 +165,33 @@ def score_stat(start_date=None, end_date=None):
ScoreStat.objects.bulk_create(seat_list)
logger.info('[score_stat]seat count: [%s]', stat_count)
logger.info('[score_stat]seat score stat end.')
def seat_time_stat(start_date=None, end_date=None):
"""
首页概述-违规坐席统计
: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]seat time stat start...')
logger.info(start_date)
logger.info(end_date)
task_condition = {'create_date__gte': start_date, 'create_date__lt': end_date}
seats = SeatStat.objects.filter(**task_condition)
stat_count = 0
for t in seats:
if not t.remainTime:
stat_count += 1
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')
total_time = 0
for check in checks:
total_time += check['remainTime']
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.')
......@@ -56,6 +56,7 @@ class SeatStat(models.Model):
create_date = models.DateField('统计日期', null=True)
agentName = models.CharField('坐席名称', null=True, max_length=64)
taskId = models.IntegerField('质检任务标识')
remainTime = models.IntegerField('通话时长')
def __str__(self):
return self.agentName
......
......@@ -16,7 +16,7 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from .api.tasksapi import rule, seat, group, score, check
from .views import stat_rules_every, stat_seats_every, stat_scores_every
from .views import stat_rules_every, stat_seats_every, stat_scores_every, stat_time_every
urlpatterns = [
# path('admin/', admin.site.urls),
......@@ -28,4 +28,5 @@ urlpatterns = [
path('inspect/stat/rule/', stat_rules_every),
path('inspect/stat/seat/', stat_seats_every),
path('inspect/stat/score/', stat_scores_every),
path('inspect/stat/time/', stat_time_every),
]
from datetime import datetime, timedelta
from .cron import rule_stat, seat_stat, score_stat
from .cron import rule_stat, seat_stat, score_stat, seat_time_stat
from django.http.response import JsonResponse
from dateutil.rrule import rrule, DAILY
......@@ -42,3 +42,16 @@ def stat_scores_every(request):
end_date = datetime.strptime(date.strftime('%Y-%m-%d') + ' 23:59:59', '%Y-%m-%d %H:%M:%S')
score_stat(start_date, end_date)
return JsonResponse({'code': 0, 'msg': 'stat success'})
def stat_time_every(request):
start_date = request.GET.get('start_date')
end_date = request.GET.get('end_date')
s_date = datetime.strptime(start_date, '%Y-%m-%d')
e_date = datetime.strptime(end_date, '%Y-%m-%d')
seed_dt = list(rrule(DAILY, byweekday=[0, 1, 2, 3, 4, 5, 6], dtstart=s_date, until=e_date))
for date in seed_dt:
start_date = date.date()
end_date = (datetime.strptime(date.strftime('%Y-%m-%d'), '%Y-%m-%d') + timedelta(days=1)).date()
seat_time_stat(start_date, end_date)
return JsonResponse({'code': 0, 'msg': 'stat success'})
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