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
909ec7bf
Commit
909ec7bf
authored
Dec 16, 2019
by
zhengjinlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统计任务
parent
ff7bc26b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
30 deletions
+59
-30
cron.py
src/inspect_report/cron.py
+59
-30
No files found.
src/inspect_report/cron.py
View file @
909ec7bf
...
...
@@ -21,11 +21,14 @@ def rule_stat(start_date, end_date):
tasks
=
Tasks
.
objects
.
filter
(
**
task_condition
)
.
values
(
'id'
,
'name'
,
'sessionCollectionId'
)
stat_count
=
0
for
t
in
tasks
:
if
RulesStat
.
objects
.
filter
(
taskId
=
t
[
'id'
])
.
exists
():
continue
table_name
=
TABLE_PRE
+
t
[
'sessionCollectionId'
]
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'
)
rules_list
=
[]
for
check
in
checks
:
result
=
check
[
'checkResult'
]
if
result
:
...
...
@@ -33,22 +36,30 @@ def rule_stat(start_date, end_date):
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'
]
rd
=
RulesStat
()
rd
.
create_date
=
start_date
rd
.
sessionCollectionId
=
t
[
'sessionCollectionId'
]
rd
.
rule
=
name
rd
.
rule_num
=
1
rd
.
task
=
t
[
'name'
]
.
split
(
'_'
)[
0
]
rd
.
agentName
=
check
[
'agentName'
]
rd
.
customName
=
check
[
'customName'
]
rd
.
score
=
check
[
'score'
]
rd
.
remainTime
=
check
[
'remainTime'
]
rd
.
taskId
=
check
[
'taskId'
]
rd
.
sessionId
=
check
[
'sessionId'
]
rd
.
session_table_id
=
check
[
'id'
]
rd
.
save
()
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'
],
'taskId'
:
check
[
'taskId'
],
'sessionId'
:
check
[
'sessionId'
],
'session_table_id'
:
check
[
'id'
]}
rules_list
.
append
(
RulesStat
(
**
rule_obj
))
# rd = RulesStat()
# rd.create_date = start_date
# rd.sessionCollectionId = t['sessionCollectionId']
# rd.rule = name
# rd.rule_num = 1
# rd.task = t['name'].split('_')[0]
# rd.agentName = check['agentName']
# rd.customName = check['customName']
# rd.score = check['score']
# rd.remainTime = check['remainTime']
# rd.taskId = check['taskId']
# rd.sessionId = check['sessionId']
# rd.session_table_id = check['id']
# rd.save()
stat_count
+=
1
logger
.
info
(
'统计数量为:
%
s'
%
stat_count
)
RulesStat
.
objects
.
bulk_create
(
rules_list
)
def
seat_stat
(
start_date
,
end_date
):
...
...
@@ -60,25 +71,43 @@ def seat_stat(start_date, end_date):
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
SeatStat
.
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'
)
seat_dict
=
{}
seat_list
=
[]
for
check
in
checks
:
seat_condition
=
{
'create_date'
:
start_date
,
'agentName'
:
check
[
'agentName'
]}
seats
=
SeatStat
.
objects
.
filter
(
**
seat_condition
)
if
seats
:
seat
=
seats
[
0
]
seat
.
total_session
+=
1
seat
.
validate_session
+=
1
if
check
[
'violationRuleCount'
]
>
0
else
0
seat
.
save
()
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
else
:
seat
=
SeatStat
()
seat
.
create_date
=
start_date
seat
.
agentName
=
check
[
'agentName'
]
seat
.
taskId
=
check
[
'taskId'
]
seat
.
task
=
t
[
'name'
]
.
split
(
'_'
)[
0
]
seat
.
sessionCollectionId
=
t
[
'sessionCollectionId'
]
seat
.
total_session
=
1
seat
.
validate_session
=
1
if
check
[
'violationRuleCount'
]
>
0
else
0
seat
.
save
()
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
for
k
,
v
in
seat_dict
.
items
():
seat_obj
=
{
'agentName'
:
k
}
seat_obj
.
update
(
v
)
seat_list
.
append
(
SeatStat
(
**
seat_obj
))
# seat_condition = {'create_date': start_date, 'agentName': check['agentName']}
# seats = SeatStat.objects.filter(**seat_condition)
# if seats:
# seat = seats[0]
# seat.total_session += 1
# seat.validate_session += 1 if check['violationRuleCount'] > 0 else 0
# seat.save()
# else:
# seat = SeatStat()
# seat.create_date = start_date
# seat.agentName = check['agentName']
# seat.taskId = check['taskId']
# seat.task = t['name'].split('_')[0]
# seat.sessionCollectionId = t['sessionCollectionId']
# seat.total_session = 1
# seat.validate_session = 1 if check['violationRuleCount'] > 0 else 0
# seat.save()
SeatStat
.
objects
.
bulk_create
(
seat_list
)
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