Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
eca51fa2
Commit
eca51fa2
authored
8 years ago
by
Megan Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add non-compliant session count to stats
parent
6e0e398a
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/api.py
+1
-1
1 addition, 1 deletion
api/api.py
api/dao/containerstorage.py
+4
-3
4 additions, 3 deletions
api/dao/containerstorage.py
api/dao/containerutil.py
+29
-8
29 additions, 8 deletions
api/dao/containerutil.py
api/handlers/containerhandler.py
+1
-0
1 addition, 0 deletions
api/handlers/containerhandler.py
with
35 additions
and
12 deletions
api/api.py
+
1
−
1
View file @
eca51fa2
...
...
@@ -174,7 +174,7 @@ routes = [
webapp2
.
Route
(
r
'
/api/projects/groups
'
,
containerhandler
.
ContainerHandler
,
handler_method
=
'
get_groups_with_project
'
,
methods
=
[
'
GET
'
]),
webapp2
.
Route
(
r
'
/api/projects/recalc
'
,
containerhandler
.
ContainerHandler
,
handler_method
=
'
calculate_project_compliance
'
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
_format
(
r
'
/api/projects/<cid:{cid_re}>/template
'
),
containerhandler
.
ContainerHandler
,
handler_method
=
'
set_project_template
'
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
_format
(
r
'
/api/projects/<cid:{cid_re}>/
template/
recalc
'
),
containerhandler
.
ContainerHandler
,
handler_method
=
'
calculate_project_compliance
'
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
_format
(
r
'
/api/projects/<cid:{cid_re}>/recalc
'
),
containerhandler
.
ContainerHandler
,
handler_method
=
'
calculate_project_compliance
'
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
_format
(
r
'
/api/<par_cont_name:groups>/<par_id:{group_id_re}>/<cont_name:projects>
'
),
containerhandler
.
ContainerHandler
,
name
=
'
cont_sublist_groups
'
,
handler_method
=
'
get_all
'
,
methods
=
[
'
GET
'
]),
webapp2
.
Route
(
_format
(
r
'
/api/<par_cont_name:{cont_name_re}>/<par_id:{cid_re}>/<cont_name:{cont_name_re}>
'
),
containerhandler
.
ContainerHandler
,
name
=
'
cont_sublist
'
,
handler_method
=
'
get_all
'
,
methods
=
[
'
GET
'
]),
...
...
This diff is collapsed.
Click to expand it.
api/dao/containerstorage.py
+
4
−
3
View file @
eca51fa2
...
...
@@ -194,7 +194,7 @@ class ProjectStorage(ContainerStorage):
# Recalc all projects
projects
=
self
.
get_all_el
({
'
template
'
:
{
'
$exists
'
:
True
}},
None
,
None
)
else
:
project
=
self
.
get_container
(
project_id
,
get_children
=
True
)
project
=
self
.
get_container
(
project_id
)
if
project
:
projects
=
[
project
]
else
:
...
...
@@ -204,10 +204,11 @@ class ProjectStorage(ContainerStorage):
for
project
in
projects
:
template
=
project
.
get
(
'
template
'
,{})
if
not
template
:
return
continue
else
:
session_storage
=
SessionStorage
()
for
s
in
project
.
get
(
'
sessions
'
,
[]):
sessions
=
session_storage
.
get_all_el
({
'
project
'
:
project
[
'
_id
'
]},
None
,
None
)
for
s
in
sessions
:
changed
=
session_storage
.
recalc_session_compliance
(
s
[
'
_id
'
],
session
=
s
,
template
=
template
)
if
changed
:
changed_sessions
.
append
(
s
[
'
_id
'
])
...
...
This diff is collapsed.
Click to expand it.
api/dao/containerutil.py
+
29
−
8
View file @
eca51fa2
...
...
@@ -39,22 +39,46 @@ def add_id_to_subject(subject, pid):
def
get_stats
(
cont
,
cont_type
):
"""
Add a session and attachment count to a project or collection
Add a
session, subject, non-compliant
session and attachment count to a project or collection
"""
if
cont_type
not
in
[
'
projects
'
,
'
collections
'
]:
return
cont
session_ids
=
[]
# Get attachment count from file array length
cont
[
'
attachment_count
'
]
=
len
(
cont
.
get
(
'
files
'
,
[]))
# Get session and non-compliant session count
match_q
=
{}
if
cont_type
==
'
projects
'
:
result
=
list
(
config
.
db
.
sessions
.
find
({
'
project
'
:
cont
[
'
_id
'
]},
{
'
_id
'
:
1
}))
session_ids
=
[
s
[
'
_id
'
]
for
s
in
result
]
match_q
=
{
'
project
'
:
cont
[
'
_id
'
]}
elif
cont_type
==
'
collections
'
:
result
=
config
.
db
.
acquisitions
.
find
({
'
collections
'
:
cont
[
'
_id
'
]},
{
'
session
'
:
1
})
session_ids
=
list
(
set
([
s
[
'
session
'
]
for
s
in
result
]))
match_q
=
{
'
_id
'
:
{
'
$in
'
:
session_ids
}}
pipeline
=
[
{
'
$match
'
:
match_q
},
{
'
$project
'
:
{
'
_id
'
:
1
,
'
non_compliant
'
:
{
'
$cond
'
:
[{
'
$eq
'
:
[
'
$satisfies_template
'
,
False
]},
1
,
0
]}}},
{
'
$group
'
:
{
'
_id
'
:
1
,
'
noncompliant_count
'
:
{
'
$sum
'
:
'
$non_compliant
'
},
'
total
'
:
{
'
$sum
'
:
1
}}}
]
result
=
config
.
db
.
command
(
'
aggregate
'
,
'
sessions
'
,
pipeline
=
pipeline
).
get
(
'
result
'
,
[])
if
len
(
result
)
>
0
:
cont
[
'
session_count
'
]
=
result
[
0
].
get
(
'
total
'
,
0
)
cont
[
'
noncompliant_session_count
'
]
=
result
[
0
].
get
(
'
noncompliant_count
'
,
0
)
else
:
# If there are no sessions, return zero'd out stats
cont
[
'
session_count
'
]
=
0
cont
[
'
noncompliant_session_count
'
]
=
0
cont
[
'
subject_count
'
]
=
0
return
cont
# Get subject count
match_q
[
'
subject._id
'
]
=
{
'
$ne
'
:
None
}
pipeline
=
[
{
'
$match
'
:
{
'
_id
'
:
{
'
$in
'
:
session_ids
},
'
subject._id
'
:
{
'
$ne
'
:
None
}}
},
{
'
$match
'
:
match_q
},
{
'
$group
'
:
{
'
_id
'
:
'
$subject._id
'
}},
{
'
$group
'
:
{
'
_id
'
:
1
,
'
count
'
:
{
'
$sum
'
:
1
}}}
]
...
...
@@ -66,9 +90,6 @@ def get_stats(cont, cont_type):
else
:
cont
[
'
subject_count
'
]
=
0
cont
[
'
attachment_count
'
]
=
len
(
cont
.
get
(
'
files
'
,
[]))
cont
[
'
session_count
'
]
=
len
(
session_ids
)
return
cont
...
...
This diff is collapsed.
Click to expand it.
api/handlers/containerhandler.py
+
1
−
0
View file @
eca51fa2
...
...
@@ -507,6 +507,7 @@ class ContainerHandler(base.RequestHandler):
def
calculate_project_compliance
(
self
,
**
kwargs
):
project_id
=
kwargs
.
pop
(
'
cid
'
,
None
)
log
.
debug
(
"
project_id is {}
"
.
format
(
project_id
))
self
.
config
=
self
.
container_handler_configurations
[
'
projects
'
]
self
.
storage
=
self
.
config
[
'
storage
'
]
return
{
'
sessions_changed
'
:
self
.
storage
.
recalc_sessions_compliance
(
project_id
=
project_id
)}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment