insights

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package insights implements insight calculation based on data from the Spotify API and the generation of visualizations for insights.

Index

Constants

This section is empty.

Variables

View Source
var OpenURLRegex *regexp.Regexp = regexp.MustCompile(`^https://open\.spotify\.com/(\w+)/(\w+)\??.*$`)

Functions

func BuildSharedURL

func BuildSharedURL(res string, id string) string

BuildSharedURL builds a Spotify track url, given a track id.

func ParseSharedURL

func ParseSharedURL(url string) (string, error)

ParseSharedURL parses a Spotify track url, returning the id of the track

Types

type ChainerFunc

type ChainerFunc[T any, V any] func(<-chan T) <-chan V

type Recommendation

type Recommendation struct {
	Spotify   *sdk.Spotify
	SeedTrack *sdk.Track
	Registry  *sdk.ResourceRegistry
	Settings  *RecommendationSettings
}

Recommendation produces a list of tracks that are similar to its seed track.

func NewRecommendation

func NewRecommendation(spo *sdk.Spotify, s *RecommendationSettings) *Recommendation

NewRecommendation sets up and then returns a new Recommendation.

func (*Recommendation) Populate

func (p *Recommendation) Populate() []SimilarityScore

Populate fetches audio features for tracks that could be similar to the seed track.

type RecommendationSettings

type RecommendationSettings struct {
	SeedTrackId    string
	SeedTrackURL   string
	AlbumFilters   sdk.ArtistAlbumFilters
	IncludeAuthors bool
	MaxWorkers     int
	MaxArtists     int
	MaxAlbums      int
	MinScore       float64
	MinCount       int
	MaxCount       int
}

RecommendationSettings holds settings for the track recommendation feature.

func NewRecommendationSettings

func NewRecommendationSettings() *RecommendationSettings

NewRecommendationSettings creates a RecommendationSettings value with useful defaults.

type SimilarityScore

type SimilarityScore struct {
	TrackId string
	Value   float64
}

A SimilarityScore holds the calculated similarity between its referenced track and the seed track.

func CalculateSimilarityScore

func CalculateSimilarityScore(src *sdk.AudioFeatures, other *sdk.AudioFeatures) SimilarityScore

CalculateSimilarityScore calculates the similarity between the audio features of two tracks using cosine similarity.

type SimilarityScoreHeap

type SimilarityScoreHeap []SimilarityScore

A SimilarityScoreHeap implements the heap.Interface interface in order to provide a max priority queue of similarity scores.

func (SimilarityScoreHeap) Len

func (h SimilarityScoreHeap) Len() int

func (SimilarityScoreHeap) Less

func (h SimilarityScoreHeap) Less(i, j int) bool

func (*SimilarityScoreHeap) Pop

func (h *SimilarityScoreHeap) Pop() any

func (*SimilarityScoreHeap) Push

func (h *SimilarityScoreHeap) Push(x any)

func (SimilarityScoreHeap) Swap

func (h SimilarityScoreHeap) Swap(i, j int)

type TrackDeDuper

type TrackDeDuper struct {
	Recommendation *Recommendation
	RecordedKeys   map[string]bool
	DupesAvoided   int
}

A TrackDeDuper implements de-duplication strategies for tracks in a list.

func NewTrackDeDuper

func NewTrackDeDuper(rec *Recommendation) *TrackDeDuper

NewTrackDeDuper creates a new TrackDeDuper.

func (*TrackDeDuper) BuildKey

func (d *TrackDeDuper) BuildKey(trackId string) string

BuildKey builds a de-duplication key from a track id.

func (*TrackDeDuper) KeyExists

func (d *TrackDeDuper) KeyExists(key string) bool

KeyExists checks if a key has been seen before.

func (*TrackDeDuper) Record

func (d *TrackDeDuper) Record(key string)

Record records a key as having been seen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL