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
7dd3c6c4
Commit
7dd3c6c4
authored
Jan 06, 2020
by
zhengjinlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页统计
parent
7ab2f372
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
31 deletions
+12
-31
tasksapi.py
src/inspect_report/api/tasksapi.py
+12
-31
No files found.
src/inspect_report/api/tasksapi.py
View file @
7dd3c6c4
...
@@ -243,38 +243,19 @@ class TasksApi(viewsets.ViewSet):
...
@@ -243,38 +243,19 @@ class TasksApi(viewsets.ViewSet):
task_id
=
req
.
data
.
get
(
'task'
,
''
)
task_id
=
req
.
data
.
get
(
'task'
,
''
)
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'
))
task_condition
=
{
'hasCheck'
:
1
,
'createdAt__gte'
:
start_date
,
'createdAt__lt'
:
end_date
+
' 23:59:59'
}
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
()
session_condition
=
{
'create_date__gte'
:
q_start_date
,
'create_date__lt'
:
q_end_date
}
if
task_id
:
if
task_id
:
task_condition
[
'name__startswith'
]
=
task_id
session_condition
[
'task'
]
=
task_id
tasks
=
Tasks
.
objects
.
filter
(
**
task_condition
)
.
values
(
'id'
,
'sessionCollectionId'
)
seat_data
=
SeatStat
.
objects
.
filter
(
**
session_condition
)
.
aggregate
(
task_dict
=
{}
validate_session_sum
=
Sum
(
'validate_session'
),
total_session_sum
=
Sum
(
'total_session'
))
for
t
in
tasks
:
avg_score
=
ScoreStat
.
objects
.
filter
(
**
session_condition
)
.
aggregate
(
score_avg
=
Round
(
Avg
(
'score'
),
2
))
if
t
[
'sessionCollectionId'
]
in
task_dict
.
keys
():
return_data
=
{
'validate_session'
:
seat_data
[
'validate_session_sum'
],
task_dict
[
t
[
'sessionCollectionId'
]]
.
append
(
t
[
'id'
])
'total_session'
:
seat_data
[
'total_session_sum'
]}
else
:
if
seat_data
[
'total_session_sum'
]:
task_dict
[
t
[
'sessionCollectionId'
]]
=
[
t
[
'id'
],
]
return_data
[
'ratio'
]
=
round
(
seat_data
[
'validate_session_sum'
]
/
seat_data
[
'total_session_sum'
],
2
)
return_data
=
{
'total_session'
:
0
,
'validate_session'
:
0
}
return_data
[
'avg_score'
]
=
avg_score
[
'score_avg'
]
total_score
=
0
for
k
,
v
in
task_dict
.
items
():
table_name
=
TABLE_PRE
+
k
tn
=
CheckSession
.
set_table
(
table_name
)
session_condition
=
{
'taskId__in'
:
v
}
# checks = tn.objects.filter(**session_condition).values('violationRuleCount', 'score')
# for check in checks:
# total_score += check['score']
# return_data['total_session'] += 1
# if check['violationRuleCount'] > 0:
# return_data['validate_session'] += 1
session_all
=
tn
.
objects
.
filter
(
**
session_condition
)
.
aggregate
(
Count
(
"id"
))
score_all
=
tn
.
objects
.
filter
(
**
session_condition
)
.
aggregate
(
Sum
(
"score"
))
session_condition
[
'violationRuleCount__gt'
]
=
0
validate_all
=
tn
.
objects
.
filter
(
**
session_condition
)
.
aggregate
(
Count
(
"id"
))
return_data
[
'total_session'
]
+=
session_all
[
'id__count'
]
return_data
[
'validate_session'
]
+=
validate_all
[
'id__count'
]
total_score
+=
score_all
[
'score__sum'
]
if
return_data
[
'total_session'
]:
return_data
[
'ratio'
]
=
round
(
return_data
[
'validate_session'
]
/
return_data
[
'total_session'
],
2
)
return_data
[
'avg_score'
]
=
round
(
total_score
/
return_data
[
'total_session'
],
2
)
else
:
else
:
return_data
[
'ratio'
]
=
0.0
return_data
[
'ratio'
]
=
0.0
return_data
[
'avg_score'
]
=
0.0
return_data
[
'avg_score'
]
=
0.0
...
...
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