calliope.select.constraints
¶
Module Contents¶
Classes¶
Abstract base class. |
|
Abstract base class. |
|
Abstract base class for global (whole playlist) constraints. |
|
Abstract base class. |
|
Abstract base class. |
|
Apply an item constraint to every item in the playlist. |
|
Apply an item set constraint to some items in the playlist. |
|
The sum of 'prop' for all songs should be between 'vmin' and 'vmax'. |
|
Each song should have duration in range [min, max]. |
|
Playlist should be a specified number of seconds in duration. |
|
Playlist items should total a specified number of bytes in size. |
Functions¶
|
Objective function for value and target range [vmin, vmax] |
Attributes¶
- calliope.select.constraints.linear_score(value, vmin, vmax)¶
Objective function for value and target range [vmin, vmax]
Returns 1.0 if vmin <= value <= vmax, decreasing linearly to 0.0 as value tends towards 0.0 and vmax*2.
- class calliope.select.constraints.ItemConstraint(prop)¶
Bases:
Constraint
Abstract base class.
- Parameters:
prop (str) –
- __repr__()¶
Return repr(self).
- abstract score_item(item)¶
Score how well item satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- Parameters:
item (calliope.playlist.Item) –
- Return type:
float
- abstract partition(collection)¶
Divide ‘collection’ into one ‘good’ and one or more ‘bad’ groups.
This is used to define the neighbourhood we search for a solution.
- Return type:
[[calliope.playlist.Item]]
- class calliope.select.constraints.GlobalConstraint¶
Bases:
Constraint
Abstract base class for global (whole playlist) constraints.
- abstract score_playlist(playlist)¶
Score how well playlist satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- class calliope.select.constraints.SetConstraint(prop, values)¶
Bases:
ItemConstraint
Abstract base class.
Simple set constraint, for properties with nominal (string) values.
An item satisfies the constraint if its value matches one member of values.
- Parameters:
prop (str) –
values ([str]) –
- __repr__()¶
Return repr(self).
- score_item(item)¶
Score how well item satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- Parameters:
item (calliope.playlist.Item) –
- Return type:
float
- partition(collection)¶
Divide ‘collection’ into one ‘good’ and one or more ‘bad’ groups.
This is used to define the neighbourhood we search for a solution.
- class calliope.select.constraints.RangeConstraint(prop, vmin, vmax)¶
Bases:
ItemConstraint
Abstract base class.
Simple range constraint, for properties with numeric values.
An item scores 1.0 if vmin <= prop <= vmax. The score decreases linearly towards 0.0 as prop approaches 0 or 2*`vmax`.
t’s common to specify a single value by specifying vmin = vmax.
- Parameters:
prop (str) –
vmin (float) –
vmax (float) –
- __repr__()¶
Return repr(self).
- score_item(item)¶
Score how well item satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- partition(collection)¶
Divide ‘collection’ into one ‘good’ and one or more ‘bad’ groups.
This is used to define the neighbourhood we search for a solution.
- class calliope.select.constraints.EachGlobalConstraint(item_constraint)¶
Bases:
GlobalConstraint
Apply an item constraint to every item in the playlist.
- Parameters:
item_constraint (ItemConstraint) –
- __repr__()¶
Return repr(self).
- score_playlist(playlist)¶
Score how well playlist satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- partition(collection)¶
- class calliope.select.constraints.FractionGlobalConstraint(item_constraint, fmin, fmax)¶
Bases:
GlobalConstraint
Apply an item set constraint to some items in the playlist.
- Parameters:
item_constraint (SetConstraint) –
fmin (float) –
fmax (float) –
- __repr__()¶
Return repr(self).
- score_playlist(playlist)¶
Score how well playlist satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- partition(collection)¶
- class calliope.select.constraints.SumGlobalConstraint(prop, vmin, vmax)¶
Bases:
GlobalConstraint
,RangeConstraint
The sum of ‘prop’ for all songs should be between ‘vmin’ and ‘vmax’.
Simple range constraint, for properties with numeric values.
An item scores 1.0 if vmin <= prop <= vmax. The score decreases linearly towards 0.0 as prop approaches 0 or 2*`vmax`.
t’s common to specify a single value by specifying vmin = vmax.
- __repr__()¶
Return repr(self).
- score_playlist(playlist)¶
Score how well playlist satisfies this constraint.
The score must be between 0.0 (doesn’t satisfy constraint) and 1.0 (satisfies it perfectly).
- partition(collection)¶
Divide ‘collection’ into one ‘good’ and one or more ‘bad’ groups.
This is used to define the neighbourhood we search for a solution.
- class calliope.select.constraints.ItemDurationConstraint(vmin, vmax)¶
Bases:
EachGlobalConstraint
Each song should have duration in range [min, max].
- PROP = 'duration'¶
- class calliope.select.constraints.PlaylistDurationConstraint(vmin, vmax)¶
Bases:
SumGlobalConstraint
Playlist should be a specified number of seconds in duration.
Simple range constraint, for properties with numeric values.
An item scores 1.0 if vmin <= prop <= vmax. The score decreases linearly towards 0.0 as prop approaches 0 or 2*`vmax`.
t’s common to specify a single value by specifying vmin = vmax.
- PROP = 'duration'¶
- class calliope.select.constraints.PlaylistDiskSpaceConstraint(vmin, vmax)¶
Bases:
SumGlobalConstraint
Playlist items should total a specified number of bytes in size.
Simple range constraint, for properties with numeric values.
An item scores 1.0 if vmin <= prop <= vmax. The score decreases linearly towards 0.0 as prop approaches 0 or 2*`vmax`.
t’s common to specify a single value by specifying vmin = vmax.
- PROP = 'album.size_mb'¶
- calliope.select.constraints.CONSTRAINTS_BY_NAME¶