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
cf20d100
Commit
cf20d100
authored
3 years ago
by
Mario Raciti
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-610
: Update get_usage_mode by gathering durations per semester, not per week anymore
parent
d5c2c7b9
No related branches found
No related tags found
3 merge requests
!634
WIP: COBALT commissioning delta
,
!492
Resolve TMSS-610
,
!481
Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py
+22
-41
22 additions, 41 deletions
SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py
with
22 additions
and
41 deletions
SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py
+
22
−
41
View file @
cf20d100
...
...
@@ -198,50 +198,31 @@ def _get_projects_summary(request: Request, cycle: models.Cycle) -> {}:
return
projects_summary
def
_get_usage_mode
(
cycle
:
models
.
Cycle
)
->
[]
:
def
_get_usage_mode
(
cycle
:
models
.
Cycle
)
->
{}
:
"""
Help function to retrieve ILT and local usage mode info.
"""
result
=
[]
# Get all the reservations related to the projects in the cycle
reservations
=
models
.
Reservation
.
objects
.
filter
(
project__cycles
=
cycle
.
pk
)
# # Get all the reservations in stand-alone mode
# reservations_sa_mode = models.Reservation.objects.filter(specifications_doc__activity__type='stand-alone mode')
# Get the first Monday before the cycle.start
start
,
stop
=
cycle
.
start
-
timedelta
(
days
=
cycle
.
start
.
weekday
()),
cycle
.
stop
# Iterate through weeks and sum durations per week
overflow
,
week_duration
=
0
,
0
step
,
d
=
timedelta
(
days
=
7
),
start
while
d
<
stop
:
# Durations entirely contained in the current week
durations_in_week
=
reservations
.
filter
(
start_time__range
=
(
d
,
d
+
step
),
stop_time__lt
=
(
d
+
step
))
\
.
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
# Update week_duration and reset overflow
week_duration
+=
overflow
+
durations_in_week
overflow
=
0
# Reservations with overflow durations between two or more weeks
# TODO: This only covers an overflow of a week (two weeks coverage).
# We need to consider also more weeks (>= 3 weeks coverage). Maybe making the "overflow" var modular.
overflow_reservations
=
reservations
.
filter
(
start_time__range
=
(
d
,
d
+
step
),
stop_time__gte
=
(
d
+
step
))
for
r
in
overflow_reservations
:
# Split the duration and store overflow to be added to the next week
stop_time
=
r
.
stop_time
-
timedelta
(
days
=
r
.
stop_time
.
weekday
())
week_duration
+=
(
stop_time
-
r
.
start_time
).
total_seconds
()
overflow
+=
timedelta
(
days
=
r
.
stop_time
.
weekday
()).
total_seconds
()
# Store the duration for the current week
result
.
append
({
'
week
'
:
d
.
date
().
isoformat
(),
'
duration
'
:
week_duration
if
week_duration
>
0
else
None
})
d
+=
step
# TODO: Filter stand-alone mode not for project, sum for each project, mixed project|no project, ILT mode per week.
# result['total_duration'] += r.duration
# result['local_duration'] += r.duration if r.specifications_doc['activity']['type'] == 'stand-alone mode' else 0
# result['ILT_duration'] = result['total_duration'] - result['local_duration']
result
=
{
'
all modes
'
:
{},
'
stand-alone mode
'
:
{},
'
ILT mode
'
:
{}}
# Get all the reservations in the cycle semester
reservations
=
models
.
Reservation
.
objects
.
filter
(
start_time__gte
=
cycle
.
start
,
stop_time__lte
=
cycle
.
stop
)
result
[
'
all modes
'
][
'
total
'
]
=
reservations
.
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
reservations_projects
=
reservations
.
filter
(
project__project_category
=
'
regular
'
,
project__cycles
=
cycle
.
pk
)
# Production projects
result
[
'
all modes
'
][
'
observing
'
]
=
reservations_projects
.
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
reservations_mixed
=
reservations
.
filter
(
project__cycles
=
cycle
.
pk
).
exclude
(
project__project_category
=
'
regular
'
)
# Non-production projects
result
[
'
all modes
'
][
'
idle/test
'
]
=
reservations_mixed
.
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
# Get all the reservations in stand-alone mode
reservations_sa
=
reservations
.
filter
(
specifications_doc__activity__type
=
'
stand-alone mode
'
)
result
[
'
stand-alone mode
'
][
'
total
'
]
=
reservations_sa
.
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
result
[
'
stand-alone mode
'
][
'
no project
'
]
=
reservations_sa
.
filter
(
project
=
None
).
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
result
[
'
stand-alone mode
'
][
'
project
'
]
=
(
reservations_sa
&
reservations_projects
).
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
result
[
'
stand-alone mode
'
][
'
mixed/no project
'
]
=
(
reservations_sa
&
reservations_mixed
).
aggregate
(
duration
=
Sum
(
F
(
'
stop_time
'
)
-
F
(
'
start_time
'
)))[
'
duration
'
]
or
0
# Get ILT durations
result
[
'
ILT mode
'
][
'
total
'
]
=
result
[
'
all modes
'
][
'
total
'
]
-
result
[
'
stand-alone mode
'
][
'
total
'
]
result
[
'
ILT mode
'
][
'
observing
'
]
=
result
[
'
all modes
'
][
'
observing
'
]
-
result
[
'
stand-alone mode
'
][
'
project
'
]
result
[
'
ILT mode
'
][
'
idle/test
'
]
=
result
[
'
all modes
'
][
'
idle/test
'
]
-
result
[
'
stand-alone mode
'
][
'
mixed/no project
'
]
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