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
a087e668
Commit
a087e668
authored
Jan 16, 2020
by
zhengjinlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统计通话时长
parent
e69ce62e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
8 deletions
+42
-8
cron.py
src/inspect_report/cron.py
+42
-8
No files found.
src/inspect_report/cron.py
View file @
a087e668
...
...
@@ -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
(
'
remain
Time'
)
checks = tn.objects.filter(**session_condition).values('
startTime', 'close
Time')
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.'
)
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