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
4b9b2043
Commit
4b9b2043
authored
May 30, 2024
by
Felix Blanke
Browse files
Options
Downloads
Patches
Plain Diff
Add docstring and fix type hint
parent
471f8a50
No related branches found
No related tags found
1 merge request
!2
Merge AK category slots
Pipeline
#236560
failed
May 30, 2024
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
AKModel/models.py
+27
-1
27 additions, 1 deletion
AKModel/models.py
with
27 additions
and
1 deletion
AKModel/models.py
+
27
−
1
View file @
4b9b2043
...
...
@@ -23,7 +23,14 @@ class OptimizerTimeslot:
idx
:
int
constraints
:
set
[
str
]
def
merge
(
self
,
other
:
"
OptimizerTimeslot
"
)
->
None
:
def
merge
(
self
,
other
:
"
OptimizerTimeslot
"
)
->
"
OptimizerTimeslot
"
:
"""
Merge with other OptimizerTimeslot.
Creates a new OptimizerTimeslot object.
Its availability is constructed by merging the availabilities of self and other,
its constraints by taking the union of both constraint sets.
As an index, the index of self is used.
"""
avail
=
self
.
avail
.
merge_with
(
other
.
avail
)
constraints
=
self
.
constraints
.
union
(
other
.
constraints
)
# we simply use the index of result[-1]
...
...
@@ -304,6 +311,18 @@ class Event(models.Model):
def
merge_blocks
(
self
,
blocks
:
Iterable
[
TimeslotBlock
]
)
->
Iterable
[
TimeslotBlock
]:
"""
Merge iterable of blocks together.
The timeslots of all blocks are grouped into maximal blocks.
Timeslots with the same start and end are identified with each other
and merged (cf `OptimizerTimeslot.merge`).
Throws a ValueError if any timeslots are overlapping but do not
share the same start and end, i.e. partial overlap is not allowed.
:param blocks: iterable of blocks to merge.
:return: iterable of merged blocks.
:rtype: iterable over lists of OptimizerTimeslot objects
"""
if
not
blocks
:
return
[]
...
...
@@ -481,6 +500,13 @@ class AKCategory(models.Model):
@staticmethod
def
create_category_constraints
(
categories
:
Iterable
[
"
AKCategory
"
])
->
set
[
str
]:
"""
Create a set of constraint strings from an AKCategory iterable.
:param categories: The iterable of categories to derive the constraint strings from.
:return: A set of category constraint strings, i.e. strings of the form
'
availability-cat-<cat.name>
'
.
:rtype: set of strings.
"""
return
{
f
"
availability-cat-
{
cat
.
name
}
"
for
cat
in
categories
...
...
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