Bånder

UserListeningHabitsCalculator
in package
implements CalculatorInterface

Table of Contents

Interfaces

CalculatorInterface

Methods

calculate()  : array<string|int, mixed>
Calculate recommendations based on user listening habits
applyFilter()  : void
Apply a filter to the database query
calculateMediaSimilarity()  : float
Calculate similarity between two media items based on user listening patterns
findSimilarStyleSongs()  : array<string|int, mixed>
Find songs with similar style based on genres
getSongArtists()  : array<string|int, mixed>
Get artist IDs for a song
hasReachedArtistRecommendationLimit()  : bool
Check if the artist has reached the maximum number of recommendations for a user in the specified period
hasSameArtist()  : bool
Check if two songs share the same artist
validateConfiguration()  : void
Validate that required configuration parameters are present

Methods

calculate()

Calculate recommendations based on user listening habits

public calculate(mixed $sourceData, array<string|int, mixed> $configuration) : array<string|int, mixed>
Parameters
$sourceData : mixed

Source model(s) to calculate recommendations for

$configuration : array<string|int, mixed>

Configuration parameters for calculation

Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

Array of recommendations [sourceId => [targetId => score]]

applyFilter()

Apply a filter to the database query

private applyFilter(Builder $query, string $field, mixed $filterConfig) : void
Parameters
$query : Builder
$field : string
$filterConfig : mixed

calculateMediaSimilarity()

Calculate similarity between two media items based on user listening patterns

private calculateMediaSimilarity(array<string|int, mixed> $sourceUsers, array<string|int, mixed> $targetUsers, array<string|int, mixed> $userListeningHistory) : float
Parameters
$sourceUsers : array<string|int, mixed>

Users who listened to source media

$targetUsers : array<string|int, mixed>

Users who listened to target media

$userListeningHistory : array<string|int, mixed>

Complete user listening history

Return values
float

Similarity score between 0-1

findSimilarStyleSongs()

Find songs with similar style based on genres

private findSimilarStyleSongs(int|string $songId, array<string|int, mixed> $mediaUsers, int $maxRecommendations) : array<string|int, mixed>
Parameters
$songId : int|string

Source song ID

$mediaUsers : array<string|int, mixed>

All media users data

$maxRecommendations : int

Maximum number of recommendations to return

Return values
array<string|int, mixed>

Array of similar songs with scores [songId => score]

getSongArtists()

Get artist IDs for a song

private getSongArtists(int|string $songId) : array<string|int, mixed>
Parameters
$songId : int|string

Song ID

Return values
array<string|int, mixed>

Array of artist IDs

hasReachedArtistRecommendationLimit()

Check if the artist has reached the maximum number of recommendations for a user in the specified period

private hasReachedArtistRecommendationLimit(int|string $userId, int|string $artistId[, int $maxSongs = 5 ][, int $periodDays = 3 ]) : bool
Parameters
$userId : int|string

User ID

$artistId : int|string

Artist ID

$maxSongs : int = 5

Maximum number of songs allowed from the same artist

$periodDays : int = 3

Period in days to check

Return values
bool

True if the artist has reached the maximum, false otherwise

hasSameArtist()

Check if two songs share the same artist

private hasSameArtist(int|string $songId1, int|string $songId2) : bool
Parameters
$songId1 : int|string
$songId2 : int|string
Return values
bool

validateConfiguration()

Validate that required configuration parameters are present

private validateConfiguration(array<string|int, mixed> $configuration) : void
Parameters
$configuration : array<string|int, mixed>
Tags
throws
InvalidArgumentException

        
On this page

Search results