Elements

troi.filters

Elements that are used as filter to remove some parts of the data passed into it:

class troi.filters.ArtistCreditFilterElement(artist_credit_ids, include=False)

Remove recordings if they do or do not belong to a given list of artists.

Parameters:
  • artist_credit_ids – A list of artist_credit_ids to remove/keep

  • include – If true, include all tracks with the given artist_credit_id, otherwise remove them.

class troi.filters.ArtistCreditLimiterElement(count=2, exclude_lower_ranked=True)

This element examines there passed in recordings and if the count of recordings by any one artists exceeds the given limit, excessive recordigns are removed. If the flag exclude_lower_ranked is True, and each recording has a “ranked” key in the musicbrainz dict, then the lowest ranked recordings are removed, otherwise the highest ranked recordings are removed. Throws PipelineError is not all recordings have artist_credit_ids set.

Parameters:
  • count – The number of duplicate aritst_credits to allow in the output

  • exclude_lower_ranked – Remove the lower ranked duplicates, if rankings are present.

class troi.filters.DuplicateRecordingMBIDFilterElement(patch=None)

This Element takes a list of recordings and removes any duplicate recordings based on the recording’s MBID, preserving the input order.

class troi.filters.DuplicateRecordingArtistCreditFilterElement(patch=None)

This Element takes a list of recordings and removes any duplicate recordings based on the recording’s name and artist_credit name, preserving the input order.

class troi.filters.ConsecutiveRecordingFilterElement(patch=None)

This Element takes a list of recordings and removes consecutive duplicate recordings based on the recording’s MBID

For example, a sequence A, A, A, B, B, A, C will be reduced to A, B, A, C

class troi.filters.EmptyRecordingFilterElement(patch=None)

This Element takes a list of recordings and removes ones that have an empty name or artist.

class troi.filters.YearRangeFilterElement(start_year, end_year=None, inverse=False)

Filter a list of Recordings based on their year – the year must be between start_year and end_year, otherwise the recording will be filtered out. If no end_year is given, keep (or reject in case of inverse) tracks greater or equal to start_year. If inverse=True, then keep all Recordings that do no fit into the given year range.

Parameters:
  • start_year – The full start year to filter (inclusive).

  • end_year – The full end year to filter (inclusive).

  • inverse – If inverse is True, exclude everything in the year range.

class troi.filters.GenreFilterElement(genre_list)

Keep recorindgs that have at least one genre in commong from the list passed in when this class is created.

Parameters:

genre_list – A list of genre trags to filter out.

class troi.filters.LatestListenedAtFilterElement(min_number_of_days=14)

Filter the recordings according to latest_listened_at field in the lb metadata. If that field is None, treat it as if the user hasn’t listened to this track recently or at all and keep the track in the list.

Parameters:

min_number_of_days – The number of tracks that must have passed for a track to be kept.

class troi.filters.HatedRecordingsFilterElement(patch=None)

Remove recordings that have been hated by the user

troi.loops

Elements useful for runnning Troi for many users:

class troi.loops.ForLoopElement(patch_slugs, patch_args)

An element that receives items from a pipeline and for each item in the pipeline it instantiates a new patch and executes that patch. A normal use case might include taking a list of users and running the specified patch for each user.

As of right now, only User objects can be processed with this element.

Parameters:
  • patch_slug – the slug of the patch to run inside the for loop

  • pipeline_args – the arguments passed to top-level pipeline, so that they apply to dynamically created pipelines inside the for loop

troi.operations

Elements that perform operations on the data pipeline, such as union, difference, intersection and uniqing.

class troi.operations.UniqueElement(key='mbid')

Make this passed list of entities unique base on the passed key (must be one of name or mbid) and return the unique list. recordings also allow msid as key and artists allow artist_credit_id as key. Currently the order of the list is not preserved. This should be improved on…

Parameters:

key – Which key to use for making the list unique. Defaults to “mbid”.

class troi.operations.UnionElement

Combine both entities lists into one

class troi.operations.IntersectionElement(key='mbid')

Return the list of entities that exist in both entities lists.

class troi.operations.DifferenceElement(key='mbid')

Return the list of recordings in entities_0 minus those in entities_1

class troi.operations.ZipperElement

Given two or more inputs, pick recordings from each alternatingly

troi.sorts

Elements that sort the data in a pipeline:

class troi.sorts.YearSortElement(reverse=False)

Sort recordings by year ascending – recordings that have the same year will be returned in an undefined order. Recordings that have no year set will be returned at the end of the list. If reverse=True, sort descending and return tracks with no year first.

Parameters:

reverse – Reverse the sort order.