Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AKPlanning
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maximilian Marx
AKPlanning
Commits
31a0b542
Verified
Commit
31a0b542
authored
Nov 27, 2022
by
Maximilian Marx
Browse files
Options
Downloads
Patches
Plain Diff
Factor timeslot computation into Event model
parent
4664fcd6
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#117695
passed
Nov 27, 2022
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
AKModel/models.py
+46
-0
46 additions, 0 deletions
AKModel/models.py
AKModel/views.py
+11
-25
11 additions, 25 deletions
AKModel/views.py
with
57 additions
and
25 deletions
AKModel/models.py
+
46
−
0
View file @
31a0b542
...
@@ -116,6 +116,52 @@ class Event(models.Model):
...
@@ -116,6 +116,52 @@ class Event(models.Model):
def
get_aks_without_availabilities
(
self
):
def
get_aks_without_availabilities
(
self
):
return
self
.
ak_set
.
annotate
(
Count
(
'
availabilities
'
,
distinct
=
True
)).
annotate
(
Count
(
'
owners
'
,
distinct
=
True
)).
filter
(
availabilities__count
=
0
,
owners__count__gt
=
0
)
return
self
.
ak_set
.
annotate
(
Count
(
'
availabilities
'
,
distinct
=
True
)).
annotate
(
Count
(
'
owners
'
,
distinct
=
True
)).
filter
(
availabilities__count
=
0
,
owners__count__gt
=
0
)
def
time_slots
(
self
,
*
,
slots_in_an_hour
=
1.0
):
from
AKModel.availability.models
import
Availability
rooms
=
Room
.
objects
.
filter
(
event
=
self
)
slot_duration
=
timedelta
(
hours
=
(
1.0
/
slots_in_an_hour
))
slot_index
=
0
current_slot
=
self
.
start
current_block
=
[]
previous_slot
=
None
room_availabilities
=
list
({
availability
for
room
in
rooms
for
availability
in
room
.
availabilities
.
all
()})
while
current_slot
<
self
.
end
:
slot
=
Availability
(
event
=
self
,
start
=
current_slot
,
end
=
current_slot
+
slot_duration
)
if
any
((
availability
.
contains
(
slot
)
for
availability
in
room_availabilities
)):
if
previous_slot
is
not
None
and
previous_slot
+
slot_duration
<
current_slot
:
yield
current_block
current_block
=
[]
current_block
.
append
(
slot_index
)
previous_slot
=
current_slot
slot_index
+=
1
current_slot
+=
slot_duration
yield
current_block
def
time_slot
(
self
,
*
,
time_slot_index
,
slots_in_an_hour
=
1.0
):
from
AKModel.availability.models
import
Availability
slot_duration
=
timedelta
(
hours
=
(
1.0
/
slots_in_an_hour
))
start
=
self
.
start
+
time_slot_index
*
slot_duration
return
Availability
(
event
=
self
,
start
=
start
,
end
=
start
+
slot_duration
)
class
AKOwner
(
models
.
Model
):
class
AKOwner
(
models
.
Model
):
"""
An AKOwner describes the person organizing/holding an AK.
"""
An AKOwner describes the person organizing/holding an AK.
...
...
This diff is collapsed.
Click to expand it.
AKModel/views.py
+
11
−
25
View file @
31a0b542
...
@@ -229,11 +229,6 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
...
@@ -229,11 +229,6 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
for
slot
in
context
[
"
slots
"
]:
for
slot
in
context
[
"
slots
"
]:
slot
.
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
slot
.
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
slot_duration
=
timedelta
(
hours
=
(
1.0
/
SLOTS_IN_AN_HOUR
))
slot_index
=
1
current_slot
=
self
.
event
.
start
current_block
=
[]
previous_slot
=
None
ak_availabilities
=
{
slot
.
ak
.
pk
:
availability
ak_availabilities
=
{
slot
.
ak
.
pk
:
availability
for
slot
in
context
[
"
slots
"
]
for
slot
in
context
[
"
slots
"
]
for
availability
in
slot
.
ak
.
availabilities
.
all
()}
for
availability
in
slot
.
ak
.
availabilities
.
all
()}
...
@@ -244,20 +239,17 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
...
@@ -244,20 +239,17 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
for
person
in
AKOwner
.
objects
.
filter
(
event
=
self
.
event
)
for
person
in
AKOwner
.
objects
.
filter
(
event
=
self
.
event
)
for
availability
in
person
.
availabilities
.
all
()}
for
availability
in
person
.
availabilities
.
all
()}
while
current_slot
<
self
.
event
.
end
:
slot
=
Availability
(
event
=
self
.
event
,
start
=
current_slot
,
end
=
current_slot
+
slot_duration
)
# also check track availability?
constraints
=
[]
for
(
room
,
availability
)
in
room_availabilities
.
items
():
for
block
in
self
.
event
.
time_slots
(
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
):
if
availability
.
contains
(
slot
):
current_block
=
[]
constraints
.
append
(
f
"
availability-room-
{
room
}
"
)
for
slot_index
in
block
:
slot
=
self
.
event
.
time_slot
(
time_slot_index
=
slot_index
,
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
)
constraints
=
[]
if
constraints
:
if
slot
.
end
<
self
.
event
.
reso_deadline
:
if
current_slot
<
self
.
event
.
reso_deadline
:
constraints
.
append
(
"
resolution
"
)
constraints
.
append
(
"
resolution
"
)
for
(
ak
,
availability
)
in
ak_availabilities
.
items
():
for
(
ak
,
availability
)
in
ak_availabilities
.
items
():
...
@@ -268,9 +260,9 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
...
@@ -268,9 +260,9 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
if
availability
.
contains
(
slot
):
if
availability
.
contains
(
slot
):
constraints
.
append
(
f
"
availability-person-
{
person
}
"
)
constraints
.
append
(
f
"
availability-person-
{
person
}
"
)
if
previous_slot
is
not
None
and
previous_slot
+
slot_duration
<
current_slot
:
for
(
room
,
availability
)
in
room_availabilities
.
items
()
:
timeslots
[
"
blocks
"
].
append
(
current_block
)
if
availability
.
contains
(
slot
):
current_block
=
[]
constraints
.
append
(
f
"
availability-room-
{
room
}
"
)
current_block
.
append
({
current_block
.
append
({
"
id
"
:
slot_index
,
"
id
"
:
slot_index
,
...
@@ -280,12 +272,6 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
...
@@ -280,12 +272,6 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
"
fulfilled_time_constraints
"
:
constraints
,
"
fulfilled_time_constraints
"
:
constraints
,
})
})
previous_slot
=
current_slot
slot_index
+=
1
current_slot
+=
slot_duration
if
current_block
!=
[]:
timeslots
[
"
blocks
"
].
append
(
current_block
)
timeslots
[
"
blocks
"
].
append
(
current_block
)
context
[
"
timeslots
"
]
=
json
.
dumps
(
timeslots
)
context
[
"
timeslots
"
]
=
json
.
dumps
(
timeslots
)
...
...
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