Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
ba2f2cfb
Commit
ba2f2cfb
authored
4 years ago
by
Mario Raciti
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-692
: Fix logic for durations; refactoring
parent
e2cd3490
No related branches found
No related tags found
1 merge request
!410
Resolve TMSS-692
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py
+27
-23
27 additions, 23 deletions
SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py
with
27 additions
and
23 deletions
SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py
+
27
−
23
View file @
ba2f2cfb
...
@@ -8,6 +8,32 @@ import logging
...
@@ -8,6 +8,32 @@ import logging
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
_get_subs_and_durations_from_project
(
project_pk
:
int
)
->
{}:
"""
Help function to retrieve durations and scheduling_units distinguished by success/fail.
"""
# Get SUBs related to the project
scheduling_unit_blueprints
=
models
.
SchedulingUnitBlueprint
.
objects
.
filter
(
draft__scheduling_set__project__pk
=
project_pk
)
# TODO: Split into total, prio A, prio B? See TMSS-592.
total_duration
,
total_succeeded_duration
,
total_not_cancelled
,
total_failed_duration
=
timedelta
(),
timedelta
(),
timedelta
(),
timedelta
()
subs_succeeded
,
subs_failed
=
[],
[]
for
sub
in
scheduling_unit_blueprints
:
# Distinguish between succeeded and failed observations
if
sub
.
status
==
'
finished
'
:
# Succeeded observations
total_succeeded_duration
+=
sub
.
duration
subs_succeeded
.
append
({
'
id
'
:
sub
.
pk
,
'
name
'
:
sub
.
name
,
'
duration
'
:
sub
.
duration
})
elif
sub
.
status
==
'
cancelled
'
:
# Failed observations
total_failed_duration
+=
sub
.
duration
subs_failed
.
append
({
'
id
'
:
sub
.
pk
,
'
name
'
:
sub
.
name
,
'
duration
'
:
sub
.
duration
})
total_duration
+=
sub
.
duration
# Total duration without considering the status of the obs.
total_not_cancelled
=
total_duration
-
total_failed_duration
# Calculate not_cancelled duration
durations
=
{
'
total
'
:
total_duration
,
'
total_succeeded
'
:
total_succeeded_duration
,
'
total_not_cancelled
'
:
total_not_cancelled
,
'
total_failed
'
:
total_failed_duration
,
'
scheduling_unit_blueprints_finished
'
:
subs_succeeded
,
'
scheduling_unit_blueprints_failed
'
:
subs_failed
}
return
durations
def
create_project_report
(
request
:
Request
,
project
:
models
.
Project
)
->
{}:
def
create_project_report
(
request
:
Request
,
project
:
models
.
Project
)
->
{}:
# TODO: Retrieve the information needed, all in one go.
# TODO: Retrieve the information needed, all in one go.
project_pk
=
project
.
pk
project_pk
=
project
.
pk
...
@@ -19,28 +45,6 @@ def create_project_report(request: Request, project: models.Project) -> {}:
...
@@ -19,28 +45,6 @@ def create_project_report(request: Request, project: models.Project) -> {}:
result
[
'
quota
'
]
=
[{
k
:
project_quota_data
[
k
]
for
k
in
(
'
id
'
,
'
resource_type_id
'
,
'
value
'
)},
]
result
[
'
quota
'
]
=
[{
k
:
project_quota_data
[
k
]
for
k
in
(
'
id
'
,
'
resource_type_id
'
,
'
value
'
)},
]
# Add durations to result
# Add durations to result
# TODO: Refactoring, choose better structure for durations result.
result
[
'
durations
'
]
=
_get_subs_and_durations_from_project
(
project_pk
)
# Get SUBs related to this project
scheduling_unit_blueprints
=
models
.
SchedulingUnitBlueprint
.
objects
.
filter
(
draft__scheduling_set__project__pk
=
project_pk
)
subs_succeeded
=
[]
subs_failed
=
[]
total_duration
=
timedelta
()
# TODO: Split into total, prio A, prio B? See TMSS-592.
total_succeeded_duration
=
timedelta
()
total_failed_duration
=
timedelta
()
for
sub
in
scheduling_unit_blueprints
:
# Distinguish between succeeded and failed observations
if
sub
.
status
!=
'
cancelled
'
:
# Observations that have ran or will still run
if
sub
.
status
==
'
finished
'
:
# Succeeded observations
total_succeeded_duration
+=
sub
.
duration
subs_succeeded
.
append
({
'
scheduling_unit_blueprint
'
:
sub
.
name
,
'
duration
'
:
sub
.
duration
})
else
:
total_duration
+=
sub
.
duration
elif
sub
.
status
==
'
cancelled
'
:
# Failed observations
total_failed_duration
+=
sub
.
duration
subs_succeeded
.
append
({
'
scheduling_unit_blueprint
'
:
sub
.
name
,
'
duration
'
:
sub
.
duration
})
# Calculate total duration and build results
total_duration
=
(
total_duration
+
total_succeeded_duration
+
total_failed_duration
)
result
[
'
durations
'
]
=
{
'
total
'
:
total_duration
,
'
total_succeeded
'
:
total_succeeded_duration
,
'
total_failed
'
:
total_failed_duration
,
'
subs_finished
'
:
subs_succeeded
,
'
subs_failed
'
:
subs_failed
}
return
result
return
result
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