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
f2f867e9
Commit
f2f867e9
authored
Dec 11, 2019
by
zhengjinlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
概览统计
parent
6e47c439
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
3 deletions
+73
-3
tasksapi.py
src/inspect_report/api/tasksapi.py
+2
-2
cron.py
src/inspect_report/cron.py
+45
-0
models.py
src/inspect_report/models.py
+14
-0
urls.py
src/inspect_report/urls.py
+2
-0
views.py
src/inspect_report/views.py
+10
-1
No files found.
src/inspect_report/api/tasksapi.py
View file @
f2f867e9
...
@@ -520,8 +520,8 @@ class TasksApi(viewsets.ViewSet):
...
@@ -520,8 +520,8 @@ class TasksApi(viewsets.ViewSet):
session_condition
=
{
'taskId__in'
:
v
}
session_condition
=
{
'taskId__in'
:
v
}
if
agent_name
:
if
agent_name
:
session_condition
[
'agentName'
]
=
agent_name
session_condition
[
'agentName'
]
=
agent_name
checks
=
tn
.
objects
.
filter
(
**
session_condition
)
.
values
(
'id'
,
'checkResult'
,
'agentName'
,
'customName'
,
# , 'agentName', 'customName', 'remainTime', 'score', 'sessionId', 'taskId'
'remainTime'
,
'score'
,
'sessionId'
,
'taskId
'
)
checks
=
tn
.
objects
.
filter
(
**
session_condition
)
.
values
(
'id'
,
'checkResult
'
)
for
check
in
checks
:
for
check
in
checks
:
call_count
+=
1
call_count
+=
1
result
=
check
[
'checkResult'
]
result
=
check
[
'checkResult'
]
...
...
src/inspect_report/cron.py
View file @
f2f867e9
# coding: utf-8
# coding: utf-8
from
rest_framework.request
import
Request
from
datetime
import
datetime
,
timedelta
from
inspect_report.models
import
Tasks
,
CheckSession
,
RulesStat
from
config.config
import
TABLE_PRE
import
json
import
logging
"""定时任务
"""定时任务
参考:https://github.com/jgorset/django-kronos
参考:https://github.com/jgorset/django-kronos
"""
"""
logger
=
logging
.
getLogger
(
"app_file"
)
def
rule_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'
)
stat_count
=
0
for
t
in
tasks
:
return_data
=
{}
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'
,
'checkResult'
)
for
check
in
checks
:
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
else
:
return_data
[
name
]
=
{
'count'
:
1
}
for
m
,
n
in
return_data
.
items
():
rd
=
RulesStat
()
rd
.
create_date
=
start_date
rd
.
from_table
=
t
[
'sessionCollectionId'
]
rd
.
rule_name
=
m
rd
.
rule_num
=
n
[
'count'
]
rd
.
area
=
t
[
'name'
]
.
split
(
'_'
)[
0
]
rd
.
save
()
stat_count
+=
1
logger
.
info
(
'统计数量为:
%
s'
%
stat_count
)
src/inspect_report/models.py
View file @
f2f867e9
...
@@ -24,6 +24,20 @@ class Tasks(models.Model):
...
@@ -24,6 +24,20 @@ class Tasks(models.Model):
db_table
=
'check_tasks'
db_table
=
'check_tasks'
class
RulesStat
(
models
.
Model
):
rule_name
=
models
.
CharField
(
'违规名称'
,
null
=
True
,
max_length
=
64
,
db_index
=
True
)
from_table
=
models
.
CharField
(
'所在表'
,
null
=
True
,
max_length
=
32
)
rule_num
=
models
.
IntegerField
(
'违规数量'
,
default
=
0
)
area
=
models
.
CharField
(
'所在地市'
,
null
=
True
,
max_length
=
24
)
create_date
=
models
.
DateField
(
'统计日期'
,
null
=
True
)
def
__str__
(
self
):
return
self
.
rule_name
class
Meta
:
db_table
=
'rules_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 @
f2f867e9
...
@@ -16,6 +16,7 @@ Including another URLconf
...
@@ -16,6 +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
urlpatterns
=
[
urlpatterns
=
[
# path('admin/', admin.site.urls),
# path('admin/', admin.site.urls),
...
@@ -24,4 +25,5 @@ urlpatterns = [
...
@@ -24,4 +25,5 @@ urlpatterns = [
path
(
'inspect/group/'
,
group
),
path
(
'inspect/group/'
,
group
),
path
(
'inspect/score/'
,
score
),
path
(
'inspect/score/'
,
score
),
path
(
'inspect/check/'
,
check
),
path
(
'inspect/check/'
,
check
),
path
(
'inspect/stat/'
,
stat_rules_every
),
]
]
src/inspect_report/views.py
View file @
f2f867e9
from
django.shortcuts
import
render
from
datetime
import
datetime
,
timedelta
from
.cron
import
rule_stat
from
django.http.response
import
JsonResponse
# Create your views here.
# Create your views here.
def
stat_rules_every
(
request
):
date
=
request
.
GET
.
get
(
'date'
)
start_date
=
datetime
.
strptime
(
date
,
'
%
Y-
%
m-
%
d'
)
end_date
=
datetime
.
strptime
(
date
+
' 23:59:59'
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
rule_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