Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
inspect_report
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengjinlei
inspect_report
Commits
0276654d
Commit
0276654d
authored
Dec 18, 2019
by
zhengjinlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页统计
parent
28cbe4ea
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
145 additions
and
9 deletions
+145
-9
tasksapi.py
src/inspect_report/api/tasksapi.py
+43
-4
cron.py
src/inspect_report/cron.py
+64
-3
models.py
src/inspect_report/models.py
+22
-0
urls.py
src/inspect_report/urls.py
+2
-1
views.py
src/inspect_report/views.py
+14
-1
No files found.
src/inspect_report/api/tasksapi.py
View file @
0276654d
...
@@ -5,7 +5,7 @@ from rest_framework import viewsets
...
@@ -5,7 +5,7 @@ from rest_framework import viewsets
from
rest_framework.decorators
import
action
from
rest_framework.decorators
import
action
from
rest_framework.request
import
Request
from
rest_framework.request
import
Request
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
inspect_report.models
import
Tasks
,
CheckSession
,
RulesStat
,
SeatStat
from
inspect_report.models
import
Tasks
,
CheckSession
,
RulesStat
,
SeatStat
,
ScoreStat
import
json
import
json
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
config.config
import
TABLE_PRE
from
config.config
import
TABLE_PRE
...
@@ -414,6 +414,7 @@ class TasksApi(viewsets.ViewSet):
...
@@ -414,6 +414,7 @@ class TasksApi(viewsets.ViewSet):
agent_name
=
req
.
data
.
get
(
'agentName'
,
''
)
agent_name
=
req
.
data
.
get
(
'agentName'
,
''
)
page
=
req
.
data
.
get
(
'page'
,
'1'
)
page
=
req
.
data
.
get
(
'page'
,
'1'
)
page_size
=
req
.
data
.
get
(
'page_size'
,
'10'
)
page_size
=
req
.
data
.
get
(
'page_size'
,
'10'
)
sort
=
req
.
data
.
get
(
'sort'
,
'-avg_score'
)
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
()
...
@@ -423,9 +424,13 @@ class TasksApi(viewsets.ViewSet):
...
@@ -423,9 +424,13 @@ class TasksApi(viewsets.ViewSet):
task_condition
[
'task'
]
=
task_id
task_condition
[
'task'
]
=
task_id
if
agent_name
:
if
agent_name
:
task_condition
[
'agentName'
]
=
agent_name
task_condition
[
'agentName'
]
=
agent_name
# , 'total_session', 'validate_num', 'validate_session', 'validate_zero'
rules
=
RulesStat
.
objects
.
filter
(
**
task_condition
)
.
extra
(
select
=
{
'area'
:
"task"
,
'agentName'
:
'agentName'
})
\
rules
=
ScoreStat
.
objects
.
filter
(
**
task_condition
)
.
extra
(
select
=
{
'area'
:
"task"
,
'agentName'
:
'agentName'
})
\
.
values
(
'area'
,
'agentName'
)
.
annotate
(
avg_score
=
Avg
(
'score'
))
.
order_by
(
'-avg_score'
)
.
values
(
'area'
,
'agentName'
)
.
annotate
(
avg_score_svc
=
Avg
(
'service_score'
),
avg_score_bus
=
Avg
(
'business_score'
),
avg_score
=
Avg
(
'score'
),
total_session
=
Sum
(
'total_session'
),
validate_num
=
Sum
(
'validate_num'
),
validate_zero
=
Sum
(
'validate_zero'
))
\
.
order_by
(
sort
)
paginator
=
Paginator
(
rules
,
page_size
)
paginator
=
Paginator
(
rules
,
page_size
)
total_count
=
paginator
.
count
total_count
=
paginator
.
count
try
:
try
:
...
@@ -526,6 +531,40 @@ class TasksApi(viewsets.ViewSet):
...
@@ -526,6 +531,40 @@ class TasksApi(viewsets.ViewSet):
seats
=
paginator
.
page
(
paginator
.
num_pages
)
seats
=
paginator
.
page
(
paginator
.
num_pages
)
return
Response
({
'code'
:
0
,
'msg'
:
'success'
,
'count'
:
total_count
,
'data'
:
seats
.
object_list
})
return
Response
({
'code'
:
0
,
'msg'
:
'success'
,
'count'
:
total_count
,
'data'
:
seats
.
object_list
})
@
action
([
'post'
],
detail
=
False
)
def
static_score
(
self
,
req
:
Request
):
"""
概览-地市得分统计
:param req:
:return:
"""
task_id
=
req
.
data
.
get
(
'task'
,
''
)
page
=
req
.
data
.
get
(
'page'
,
'1'
)
page_size
=
req
.
data
.
get
(
'page_size'
,
'10'
)
sort
=
req
.
data
.
get
(
'sort'
,
'-avg_score'
)
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'
))
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
()
task_condition
=
{
'create_date__gte'
:
q_start_date
,
'create_date__lt'
:
q_end_date
}
if
task_id
:
task_condition
[
'task'
]
=
task_id
rules
=
ScoreStat
.
objects
.
filter
(
**
task_condition
)
.
extra
(
select
=
{
'area'
:
"task"
})
\
.
values
(
'area'
)
.
annotate
(
avg_score_svc
=
Avg
(
'service_score'
),
avg_score_bus
=
Avg
(
'business_score'
),
avg_score
=
Avg
(
'score'
),
total_session
=
Sum
(
'total_session'
),
validate_num
=
Sum
(
'validate_num'
),
validate_zero
=
Sum
(
'validate_zero'
))
\
.
order_by
(
sort
)
paginator
=
Paginator
(
rules
,
page_size
)
total_count
=
paginator
.
count
try
:
seats
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
seats
=
paginator
.
page
(
1
)
except
EmptyPage
:
seats
=
paginator
.
page
(
paginator
.
num_pages
)
return
Response
({
'code'
:
0
,
'msg'
:
'success'
,
'count'
:
total_count
,
'data'
:
seats
.
object_list
})
@
xframe_options_exempt
@
xframe_options_exempt
def
rule
(
request
):
def
rule
(
request
):
...
...
src/inspect_report/cron.py
View file @
0276654d
# coding: utf-8
# coding: utf-8
from
rest_framework.request
import
Request
from
inspect_report.models
import
Tasks
,
CheckSession
,
RulesStat
,
SeatStat
,
ScoreStat
from
datetime
import
datetime
,
timedelta
from
inspect_report.models
import
Tasks
,
CheckSession
,
RulesStat
,
SeatStat
from
config.config
import
TABLE_PRE
from
config.config
import
TABLE_PRE
import
json
import
json
import
logging
import
logging
...
@@ -10,6 +8,11 @@ import logging
...
@@ -10,6 +8,11 @@ import logging
参考: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_service
=
{
'异议处理'
:
10
,
'业务促成'
:
15
,
'预约及流转'
:
15
,
'服务介绍'
:
5
,
'6_引导流程_2个场景'
:
0
,
'未提供报价'
:
5
,
'未做优惠费率介绍'
:
5
}
score_item_business
=
{
'结束语'
:
5
,
'服务态度'
:
10
,
'服务用语'
:
10
,
'语速识别'
:
5
,
'静音识别'
:
5
,
'6_2_引导流程_投诉安抚'
:
0
,
'开场白'
:
10
}
def
rule_stat
(
start_date
,
end_date
):
def
rule_stat
(
start_date
,
end_date
):
...
@@ -80,3 +83,61 @@ def seat_stat(start_date, end_date):
...
@@ -80,3 +83,61 @@ 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
)
def
score_stat
(
start_date
,
end_date
):
"""
坐席违规统计
:return:
"""
task_condition
=
{
'hasCheck'
:
1
,
'createdAt__gte'
:
start_date
,
'createdAt__lt'
:
end_date
}
tasks
=
Tasks
.
objects
.
filter
(
**
task_condition
)
.
values
(
'id'
,
'name'
,
'sessionCollectionId'
)
for
t
in
tasks
:
if
ScoreStat
.
objects
.
filter
(
taskId
=
t
[
'id'
])
.
exists
():
continue
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'
,
'taskId'
,
'violationRuleCount'
,
'startTime'
,
'score'
,
'scoreItemRecord'
)
seat_dict
=
{}
seat_list
=
[]
for
check
in
checks
:
score_item
=
json
.
loads
(
check
[
'scoreItemRecord'
])
service_score
=
55
business_score
=
45
validate_zero
=
0
for
m
in
score_item
:
if
m
[
'scoreItemName'
]
in
score_item_service
.
keys
():
service_score
-=
m
[
'score'
]
if
m
[
'scoreItemName'
]
in
score_item_business
.
keys
():
business_score
-=
m
[
'score'
]
if
m
[
'scoreItemName'
]
in
score_item_zero
.
keys
():
validate_zero
+=
1
if
validate_zero
>
0
:
score
=
0
else
:
score
=
service_score
+
business_score
if
check
[
'agentName'
]
in
seat_dict
.
keys
():
seat
=
seat_dict
.
get
(
check
[
'agentName'
])
seat
[
'total_session'
]
+=
1
seat
[
'validate_session'
]
+=
1
if
check
[
'violationRuleCount'
]
>
0
else
0
seat
[
'validate_num'
]
+=
len
(
score_item
)
seat
[
'score'
]
=
round
((
seat
[
'score'
]
+
score
)
/
2
,
2
)
seat
[
'service_score'
]
=
round
((
seat
[
'service_score'
]
+
service_score
)
/
2
,
2
)
seat
[
'business_score'
]
=
round
((
seat
[
'business_score'
]
+
business_score
)
/
2
,
2
)
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
,
'score'
:
score
,
'service_score'
:
service_score
,
'business_score'
:
business_score
,
'validate_zero'
:
validate_zero
}
seat_dict
[
check
[
'agentName'
]][
'validate_session'
]
=
1
if
check
[
'violationRuleCount'
]
>
0
else
0
seat_dict
[
check
[
'agentName'
]][
'validate_num'
]
=
len
(
score_item
)
for
k
,
v
in
seat_dict
.
items
():
seat_obj
=
{
'agentName'
:
k
}
seat_obj
.
update
(
v
)
seat_list
.
append
(
ScoreStat
(
**
seat_obj
))
ScoreStat
.
objects
.
bulk_create
(
seat_list
)
src/inspect_report/models.py
View file @
0276654d
...
@@ -61,6 +61,28 @@ class SeatStat(models.Model):
...
@@ -61,6 +61,28 @@ class SeatStat(models.Model):
db_table
=
'seats_datastat'
db_table
=
'seats_datastat'
class
ScoreStat
(
models
.
Model
):
sessionCollectionId
=
models
.
CharField
(
'所在表'
,
null
=
True
,
max_length
=
32
)
validate_session
=
models
.
IntegerField
(
'违规会话数量'
,
default
=
0
)
validate_num
=
models
.
IntegerField
(
'违规次数'
,
default
=
0
)
total_session
=
models
.
IntegerField
(
'会话数量'
,
default
=
0
)
task
=
models
.
CharField
(
'所在地市'
,
null
=
True
,
max_length
=
24
)
create_date
=
models
.
DateField
(
'统计日期'
,
null
=
True
)
start_time
=
models
.
DateTimeField
(
'会话日期'
,
null
=
True
)
agentName
=
models
.
CharField
(
'坐席名称'
,
null
=
True
,
max_length
=
64
)
taskId
=
models
.
IntegerField
(
'质检任务标识'
)
service_score
=
models
.
FloatField
(
'服务类的评分'
,
default
=
0
)
business_score
=
models
.
FloatField
(
'业务类的评分'
,
default
=
0
)
score
=
models
.
FloatField
(
'对当前会话的评分'
,
default
=
0
)
validate_zero
=
models
.
IntegerField
(
'触发0分项次数'
,
default
=
0
)
def
__str__
(
self
):
return
self
.
agentName
class
Meta
:
db_table
=
'scores_datastat'
class
CheckSession
(
models
.
Model
):
class
CheckSession
(
models
.
Model
):
taskId
=
models
.
IntegerField
(
'质检任务标识'
)
taskId
=
models
.
IntegerField
(
'质检任务标识'
)
sessionId
=
models
.
CharField
(
'会话唯一标识'
)
sessionId
=
models
.
CharField
(
'会话唯一标识'
)
...
...
src/inspect_report/urls.py
View file @
0276654d
...
@@ -16,7 +16,7 @@ Including another URLconf
...
@@ -16,7 +16,7 @@ Including another URLconf
from
django.contrib
import
admin
from
django.contrib
import
admin
from
django.urls
import
path
from
django.urls
import
path
from
.api.tasksapi
import
rule
,
seat
,
group
,
score
,
check
from
.api.tasksapi
import
rule
,
seat
,
group
,
score
,
check
from
.views
import
stat_rules_every
,
stat_seats_every
from
.views
import
stat_rules_every
,
stat_seats_every
,
stat_scores_every
urlpatterns
=
[
urlpatterns
=
[
# path('admin/', admin.site.urls),
# path('admin/', admin.site.urls),
...
@@ -27,4 +27,5 @@ urlpatterns = [
...
@@ -27,4 +27,5 @@ urlpatterns = [
path
(
'inspect/check/'
,
check
),
path
(
'inspect/check/'
,
check
),
path
(
'inspect/stat/rule/'
,
stat_rules_every
),
path
(
'inspect/stat/rule/'
,
stat_rules_every
),
path
(
'inspect/stat/seat/'
,
stat_seats_every
),
path
(
'inspect/stat/seat/'
,
stat_seats_every
),
path
(
'inspect/stat/score/'
,
stat_scores_every
),
]
]
src/inspect_report/views.py
View file @
0276654d
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
.cron
import
rule_stat
,
seat_stat
from
.cron
import
rule_stat
,
seat_stat
,
score_stat
from
django.http.response
import
JsonResponse
from
django.http.response
import
JsonResponse
from
dateutil.rrule
import
rrule
,
DAILY
from
dateutil.rrule
import
rrule
,
DAILY
...
@@ -29,3 +29,16 @@ def stat_seats_every(request):
...
@@ -29,3 +29,16 @@ def stat_seats_every(request):
end_date
=
datetime
.
strptime
(
date
.
strftime
(
'
%
Y-
%
m-
%
d'
)
+
' 23:59:59'
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
end_date
=
datetime
.
strptime
(
date
.
strftime
(
'
%
Y-
%
m-
%
d'
)
+
' 23:59:59'
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
seat_stat
(
start_date
,
end_date
)
seat_stat
(
start_date
,
end_date
)
return
JsonResponse
({
'code'
:
0
,
'msg'
:
'stat success'
})
return
JsonResponse
({
'code'
:
0
,
'msg'
:
'stat success'
})
def
stat_scores_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
+
' 23:59:59'
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
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
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'
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment