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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Felix Blanke
AKPlanning
Commits
cf082b61
Commit
cf082b61
authored
3 months ago
by
Felix Blanke
Browse files
Options
Downloads
Patches
Plain Diff
Improve docstring and type hints for optimizer slots
parent
1b1b56fd
No related branches found
No related tags found
1 merge request
!5
Refactor main
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
AKModel/models.py
+19
-8
19 additions, 8 deletions
AKModel/models.py
with
19 additions
and
8 deletions
AKModel/models.py
+
19
−
8
View file @
cf082b61
...
...
@@ -2,7 +2,7 @@ import itertools
import
json
from
dataclasses
import
dataclass
from
datetime
import
datetime
,
timedelta
from
typing
import
Iterable
from
typing
import
Iterable
,
Generator
from
django.db
import
models
from
django.apps
import
apps
...
...
@@ -17,10 +17,15 @@ from timezone_field import TimeZoneField
@dataclass
class
OptimizerTimeslot
:
"""
Class describing a timeslot. Used to interface with an optimizer.
"""
"""
Class describing a
discrete
timeslot. Used to interface with an optimizer.
"""
"""
The availability object corresponding to this timeslot.
"""
avail
:
"
Availability
"
"""
The unique index of this optimizer timeslot.
"""
idx
:
int
"""
The set of time constraints fulfilled by this object.
"""
constraints
:
set
[
str
]
def
merge
(
self
,
other
:
"
OptimizerTimeslot
"
)
->
"
OptimizerTimeslot
"
:
...
...
@@ -33,7 +38,6 @@ class OptimizerTimeslot:
"""
avail
=
self
.
avail
.
merge_with
(
other
.
avail
)
constraints
=
self
.
constraints
.
union
(
other
.
constraints
)
# we simply use the index of result[-1]
return
OptimizerTimeslot
(
avail
=
avail
,
idx
=
self
.
idx
,
constraints
=
constraints
)
...
...
@@ -200,10 +204,10 @@ class Event(models.Model):
slot_duration
:
timedelta
,
slot_index
:
int
=
0
,
constraints
:
set
[
str
]
|
None
=
None
,
)
->
Iterable
[
TimeslotBlock
]:
)
->
Generator
[
TimeslotBlock
,
None
,
int
]:
"""
Discretize a time range into timeslots.
Uses a uniform discretization into
block
s of length `slot_duration`,
Uses a uniform discretization into
discrete slot
s of length `slot_duration`,
starting at `start`. No incomplete timeslots are generated, i.e.
if (`end` - `start`) is not a whole number multiple of `slot_duration`
then the last incomplete timeslot is dropped.
...
...
@@ -214,7 +218,11 @@ class Event(models.Model):
:param slot_index: index of the first timeslot. Defaults to 0.
:yield: Block of optimizer timeslots as the discretization result.
:ytype: list of TimeslotBlock
:ytype: list of OptimizerTimeslot
:return: The first slot index after the yielded blocks, i.e.
`slot_index` + total # generated timeslots
:rtype: int
"""
# local import to prevent cyclic import
# pylint: disable=import-outside-toplevel
...
...
@@ -264,12 +272,15 @@ class Event(models.Model):
return
slot_index
def
uniform_time_slots
(
self
,
*
,
slots_in_an_hour
:
float
=
1.0
)
->
Iterable
[
TimeslotBlock
]:
"""
Uniformly discretize the entire event into a single block of timeslots.
"""
Uniformly discretize the entire event into blocks of timeslots.
Discretizes entire event uniformly. May not necessarily result in a single block
as slots with no room availability are dropped.
: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:
a single list of
Timeslot
Block
:ytype:
list of Optimizer
Timeslot
"""
all_category_constraints
=
AKCategory
.
create_category_constraints
(
AKCategory
.
objects
.
filter
(
event
=
self
).
all
()
...
...
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