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
Felix Blanke
AKPlanning
Commits
eec6035e
Commit
eec6035e
authored
5 months ago
by
Lorenzo Conti
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' into 'feature/ak-conflict-dependency'
# Conflicts: # AKModel/models.py
parents
ba533efa
bb1179c7
Branches
Branches containing commit
No related tags found
1 merge request
!9
Implement export of AK conflicts and dependencies
Pipeline
#269214
passed
5 months ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
AKModel/models.py
+25
-2
25 additions, 2 deletions
AKModel/models.py
AKModel/views/ak.py
+2
-6
2 additions, 6 deletions
AKModel/views/ak.py
with
27 additions
and
8 deletions
AKModel/models.py
+
25
−
2
View file @
eec6035e
import
decimal
import
itertools
import
itertools
import
json
import
json
import
math
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
typing
import
Iterable
,
Generator
from
typing
import
Iterable
,
Generator
...
@@ -382,6 +384,23 @@ class Event(models.Model):
...
@@ -382,6 +384,23 @@ class Event(models.Model):
constraints
=
category_constraints
,
constraints
=
category_constraints
,
)
)
def
discretize_timeslots
(
self
,
*
,
slots_in_an_hour
:
float
=
1.0
)
->
Iterable
[
TimeslotBlock
]:
""""
Choose discretization scheme.
Uses default_time_slots if the event has any DefaultSlot, otherwise uniform_time_slots.
:param slots_in_an_hour: The percentage of an hour covered by a single slot.
Determines the discretization granularity.
:yield: Block of optimizer timeslots as the discretization result.
:ytype: list of TimeslotBlock
"""
if
DefaultSlot
.
objects
.
filter
(
event
=
self
).
exists
():
# discretize default slots if they exists
yield
from
merge_blocks
(
self
.
default_time_slots
(
slots_in_an_hour
=
slots_in_an_hour
))
else
:
yield
from
self
.
uniform_time_slots
(
slots_in_an_hour
=
slots_in_an_hour
)
def
schedule_from_json
(
self
,
schedule
:
str
)
->
None
:
def
schedule_from_json
(
self
,
schedule
:
str
)
->
None
:
"""
Load AK schedule from a json string.
"""
Load AK schedule from a json string.
...
@@ -396,7 +415,7 @@ class Event(models.Model):
...
@@ -396,7 +415,7 @@ class Event(models.Model):
timeslot_dict
=
{
timeslot_dict
=
{
timeslot
.
idx
:
timeslot
timeslot
.
idx
:
timeslot
for
block
in
merge_blocks
(
self
.
default
_time
_
slots
(
slots_in_an_hour
=
slots_in_an_hour
)
)
for
block
in
self
.
discretize
_timeslots
(
slots_in_an_hour
=
slots_in_an_hour
)
for
timeslot
in
block
for
timeslot
in
block
}
}
...
@@ -937,14 +956,17 @@ class AKSlot(models.Model):
...
@@ -937,14 +956,17 @@ class AKSlot(models.Model):
conflict_slots
=
AKSlot
.
objects
.
filter
(
ak__in
=
self
.
ak
.
conflicts
.
all
())
conflict_slots
=
AKSlot
.
objects
.
filter
(
ak__in
=
self
.
ak
.
conflicts
.
all
())
dependency_slots
=
AKSlot
.
objects
.
filter
(
ak__in
=
self
.
ak
.
prerequisites
.
all
())
dependency_slots
=
AKSlot
.
objects
.
filter
(
ak__in
=
self
.
ak
.
prerequisites
.
all
())
ceil_offet_eps
=
decimal
.
Decimal
(
1e-4
)
# self.slots_in_an_hour is set in AKJSONExportView
# self.slots_in_an_hour is set in AKJSONExportView
data
=
{
data
=
{
"
id
"
:
str
(
self
.
pk
),
"
id
"
:
str
(
self
.
pk
),
"
duration
"
:
round
(
self
.
duration
*
self
.
slots_in_an_hour
),
"
duration
"
:
math
.
ceil
(
self
.
duration
*
self
.
slots_in_an_hour
-
ceil_offet_eps
),
"
properties
"
:
{
"
properties
"
:
{
"
conflicts
"
:
[
str
(
conflict
.
pk
)
for
conflict
in
conflict_slots
.
all
()],
"
conflicts
"
:
[
str
(
conflict
.
pk
)
for
conflict
in
conflict_slots
.
all
()],
"
dependencies
"
:
[
str
(
dep
.
pk
)
for
dep
in
dependency_slots
.
all
()],
"
dependencies
"
:
[
str
(
dep
.
pk
)
for
dep
in
dependency_slots
.
all
()],
},
},
"
properties
"
:
{},
"
room_constraints
"
:
[
constraint
.
name
"
room_constraints
"
:
[
constraint
.
name
for
constraint
in
self
.
ak
.
requirements
.
all
()],
for
constraint
in
self
.
ak
.
requirements
.
all
()],
"
time_constraints
"
:
[
"
resolution
"
]
if
self
.
ak
.
reso
else
[],
"
time_constraints
"
:
[
"
resolution
"
]
if
self
.
ak
.
reso
else
[],
...
@@ -954,6 +976,7 @@ class AKSlot(models.Model):
...
@@ -954,6 +976,7 @@ class AKSlot(models.Model):
for
owner
in
self
.
ak
.
owners
.
all
()]),
for
owner
in
self
.
ak
.
owners
.
all
()]),
"
description
"
:
self
.
ak
.
description
,
"
description
"
:
self
.
ak
.
description
,
"
reso
"
:
self
.
ak
.
reso
,
"
reso
"
:
self
.
ak
.
reso
,
"
duration_in_hours
"
:
float
(
self
.
duration
),
},
},
}
}
...
...
This diff is collapsed.
Click to expand it.
AKModel/views/ak.py
+
2
−
6
View file @
eec6035e
...
@@ -9,7 +9,7 @@ from django.views.generic import ListView, DetailView
...
@@ -9,7 +9,7 @@ from django.views.generic import ListView, DetailView
from
AKModel.availability.models
import
Availability
from
AKModel.availability.models
import
Availability
from
AKModel.metaviews.admin
import
AdminViewMixin
,
FilterByEventSlugMixin
,
EventSlugMixin
,
IntermediateAdminView
,
\
from
AKModel.metaviews.admin
import
AdminViewMixin
,
FilterByEventSlugMixin
,
EventSlugMixin
,
IntermediateAdminView
,
\
IntermediateAdminActionView
IntermediateAdminActionView
from
AKModel.models
import
AKRequirement
,
AKSlot
,
DefaultSlot
,
Event
,
AKOrgaMessage
,
AK
,
Room
,
AKOwner
,
merge_blocks
from
AKModel.models
import
AKRequirement
,
AKSlot
,
Event
,
AKOrgaMessage
,
AK
,
Room
,
AKOwner
class
AKRequirementOverview
(
AdminViewMixin
,
FilterByEventSlugMixin
,
ListView
):
class
AKRequirementOverview
(
AdminViewMixin
,
FilterByEventSlugMixin
,
ListView
):
...
@@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
...
@@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
if
(
values
:
=
AKSlot
.
objects
.
select_related
().
filter
(
ak__pk
=
ak_id
,
fixed
=
True
)).
exists
()
if
(
values
:
=
AKSlot
.
objects
.
select_related
().
filter
(
ak__pk
=
ak_id
,
fixed
=
True
)).
exists
()
}
}
if
DefaultSlot
.
objects
.
filter
(
event
=
self
.
event
).
exists
():
blocks
=
self
.
event
.
discretize_timeslots
(
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
)
# discretize default slots if they exists
blocks
=
merge_blocks
(
self
.
event
.
default_time_slots
(
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
))
else
:
blocks
=
self
.
event
.
uniform_time_slots
(
slots_in_an_hour
=
SLOTS_IN_AN_HOUR
)
for
block
in
blocks
:
for
block
in
blocks
:
current_block
=
[]
current_block
=
[]
...
...
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