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
a88c4932
Commit
a88c4932
authored
Dec 13, 2019
by
zhengjinlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
违规占比
parent
d97fdb44
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
55 deletions
+1
-55
tasksapi.py
src/inspect_report/api/tasksapi.py
+1
-55
No files found.
src/inspect_report/api/tasksapi.py
View file @
a88c4932
...
...
@@ -502,66 +502,12 @@ class TasksApi(viewsets.ViewSet):
for
k
,
v
in
return_data
.
items
():
v
[
'rule'
]
=
k
v
[
'ratio'
]
=
round
(
v
[
'count'
]
/
call_count
,
2
)
if
call_count
else
0
v
[
'ratio'
]
=
'{0}
%
'
.
format
(
int
(
v
[
'ratio'
]
*
100
))
v
[
'call_count'
]
=
call_count
data_sort
.
append
(
v
)
# data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True)
return
Response
({
'code'
:
0
,
'msg'
:
'success'
,
'data'
:
data_sort
})
@
action
([
'post'
],
detail
=
False
)
def
static_rule_bak
(
self
,
req
:
Request
):
"""
首页概述-违规项统计
:param req:
:return:
"""
task_id
=
req
.
data
.
get
(
'task'
,
''
)
agent_name
=
req
.
data
.
get
(
'agentName'
,
''
)
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'
))
task_condition
=
{
'hasCheck'
:
1
,
'createdAt__gte'
:
start_date
,
'createdAt__lt'
:
end_date
+
' 23:59:59'
}
if
task_id
:
task_condition
[
'name__startswith'
]
=
task_id
tasks
=
Tasks
.
objects
.
filter
(
**
task_condition
)
.
values
(
'id'
,
'sessionCollectionId'
)
task_dict
=
{}
for
t
in
tasks
:
if
t
[
'sessionCollectionId'
]
in
task_dict
.
keys
():
task_dict
[
t
[
'sessionCollectionId'
]]
.
append
(
t
[
'id'
])
else
:
task_dict
[
t
[
'sessionCollectionId'
]]
=
[
t
[
'id'
],
]
return_data
=
{}
call_count
=
0
for
k
,
v
in
task_dict
.
items
():
table_name
=
TABLE_PRE
+
k
tn
=
CheckSession
.
set_table
(
table_name
)
session_condition
=
{
'taskId__in'
:
v
}
if
agent_name
:
session_condition
[
'agentName'
]
=
agent_name
# , 'agentName', 'customName', 'remainTime', 'score', 'sessionId', 'taskId'
checks
=
tn
.
objects
.
filter
(
**
session_condition
)
.
values
(
'id'
,
'checkResult'
)
for
check
in
checks
:
call_count
+=
1
result
=
check
[
'checkResult'
]
if
result
:
data
=
json
.
loads
(
result
)
for
d
in
data
:
if
'isViolation'
in
d
.
keys
()
and
d
[
'isViolation'
]
and
'rule'
in
d
.
keys
()
and
'name'
in
d
[
'rule'
]
.
keys
():
name
=
d
[
'rule'
][
'name'
]
if
name
in
return_data
.
keys
():
return_data
[
name
][
'count'
]
+=
1
# return_data[name]['details'].append(detail)
else
:
return_data
[
name
]
=
{
'count'
:
1
,
'details'
:
[],
'tables'
:
[]}
if
k
not
in
return_data
[
name
][
'tables'
]:
return_data
[
name
][
'tables'
]
.
append
(
k
)
data_sort
=
[]
for
k
,
v
in
return_data
.
items
():
v
[
'rule'
]
=
k
v
[
'ratio'
]
=
round
(
v
[
'count'
]
/
call_count
,
2
)
v
[
'call_count'
]
=
call_count
data_sort
.
append
(
v
)
data_sort
=
sorted
(
data_sort
,
key
=
lambda
x
:
x
[
'count'
],
reverse
=
True
)
return
Response
({
'code'
:
0
,
'msg'
:
'success'
,
'data'
:
data_sort
})
@
action
([
'post'
],
detail
=
False
)
def
rule_detail
(
self
,
req
:
Request
):
"""
...
...
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