Introduction

How many unique tracks have been played on A State of Trance over the years? What's been played the most?

In this post, we'll examine track plays over time.

Getting Started

First, some baseline analysis. Let's first figure out how many tracks played on A State of Trance are available on Spotify:

tracks_counted = 0

for episode in episodes:
    try:
        for track in sp.album_tracks(episode['uri'])['items']:
            if "a state of trance" in track['name'].lower() or "- interview" in track['name'].lower():
                continue
            else:
                tracks_counted += 1
    except:
        pass

print(tracks_counted)
17369

Wow - 17,000+ total tracks have been played! Remember, as we learned in the "Methodology" post some episodes - especially early ones - are incomplete.

How many unique tracks? Get your regular expressions ready ..

import re

unique_tracks = set()

for episode in episodes:
    try:
        for track in sp.album_tracks(episode['uri'])['items']:
            if "a state of trance" in track['name'].lower() or "- interview" in track['name'].lower():
                continue
            else:
                unique_tracks.add(re.sub("[\(\[].*?[\)\]]", "", track['name'])) # Remove episode numbers from track names (ex. 'Eternity [ASOT 005]')
    except:
        pass

print(len(unique_tracks))
12722

As always, this is a "best guess" - an approximation.

Calculating

Let's crunch some numbers.

Which tracks have the most plays?

from collections import defaultdict

tracks_counter = defaultdict(int)

for episode in episodes:
    try:
        for track in sp.album_tracks(episode['uri'])['items']:
            if "a state of trance" in track['name'].lower() or "- interview" in track['name'].lower():
                continue
            else:
                track_artist = track['artists'][0]['name']
                if len(track['artists']) > 1:
                    for artist in track['artists'][1:]:
                        track_artist += " & " + artist['name']
                tracks_counter[track_artist + ' - ' + re.sub("[\(\[].*?[\)\]]", "", track['name'])] += 1
    except:
        pass

top_tracks = sorted(tracks_counter.items(), key=lambda k_v: k_v[1], reverse=True)

Results

Let's see what we've got!

for track in top_tracks[:25]:
    print(track)
('Rising Star - Clear Blue Moon  - Original Mix', 10)
('Gareth Emery & STANDERWICK & HALIENE - Saving Light ', 10)
('Solid Globe - North Pole  - Original Mix', 9)
('Active Sight - The Search For Freedom  - Original Mix', 9)
('EnMass - CQ  - Original Mix', 9)
('Jonas Steur - Castamara  - Original Mix', 9)
('Marco V - Simulated  - Original Mix', 8)
('Rank 1 - Awakening  - Original Mix', 8)
('Solarstone & Scott Bond - 3rd Earth  - Original Mix', 8)
('Pulser - My Religion  - Original Mix', 8)
('Paul van Dyk & Hemstock & Jennings - Nothing But You  - Original Mix', 8)
("Perry O'Neil - Wave Force  - Original Mix", 8)
('Re:Locate - Rogue  - Original Mix', 8)
('Jose Amnesia & Jennifer Rene - Louder  - Original Mix', 8)
("Armin van Buuren & Ana Criado - I'll Listen  - Original Mix", 8)
('ID - ID ', 8)
('RAM - RAMexico ', 8)
('Cosmic Gate & Forêt - Need To Feel Loved ', 8)
('Solarstone - Seven Cities  - Armin van Buuren Remix', 7)
('Solarstone & Scott Bond - Naked Angel  - Original Mix', 7)
('Roland Klinkenberg - Monday Groove  - Original Mix', 7)
('Solid Globe - Sahara  - Original Mix', 7)
('Adam White & Andy Moor & Whiteroom - The White Room  - Original Mix', 7)
('Robert Gitelman - Children Of The Sun  - Original Mix', 7)
('Interstate - I Found You  - Original Mix', 7)

In a crude graph:

source = pd.DataFrame.from_dict(top_tracks[:25])

bars = alt.Chart(source).mark_bar().encode(
    x=alt.X('1:Q', title='Plays'),
    y=alt.Y('0:N', sort='-x', title='Track', axis=alt.Axis(labels=False)),
).properties(
    title="A State of Trance - Most-played tracks",
    width=500
)

text = alt.Chart(source).mark_text(dx=-350, color='white', align='left').encode(
    x=alt.X('1:Q', title='Plays'),
    y=alt.Y('0:N', sort='-x'),
    text=alt.Text('0:N')
)

bars + text