We've previously looked at A State of Trance's average episode BPM, most-played artists and most-played tracks overall.
Starting with this post we'll do the same - but looking at things from year-to-year. Let's begin with annual average episode BPM.
The first episode of A State of Trance aired in 2001. Since then, the show has seen
len(episodes)
episodes of across its nearly 20-year run. As of writing, according to Spotify, etc ..
As a weekly radio show, I'd expect to see about 52 episodes air each year. Is that correct?
Fortunately Spotify can tell us when an episode aired:
for episode in episodes[:10]:
print(episode['name'], episode['release_date'])
So we can keep a running tally for each year, then print the result:
from collections import defaultdict
episodes_counter = defaultdict(int)
for episode in episodes:
episodes_counter[episode['release_date'][:4]] += 1
print(dict(episodes_counter))
Seems reasonable enough!
Let's crunch some numbers.
What is the annual average episode BPM?
annual_total_bpm = defaultdict(int)
annual_avg_bpm = defaultdict(int)
for episode in episodes:
try:
episode_bpm = 0
tracks_counted = 0
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:
episode_bpm += sp.audio_features(track['uri'])[0]['tempo']
tracks_counted += 1
episodes_counted += 1
avg = episode_bpm/tracks_counted
annual_total_bpm[episode['release_date'][:4]] += avg
except:
pass
for year, avg in annual_total_bpm.items():
annual_avg_bpm[year] = avg / episodes_counter[year]
print(dict(annual_avg_bpm))
Let's see what we've got!
source = pd.DataFrame([(k, v) for k, v in annual_avg_bpm.items()],
columns=['Year', 'Average Episode BPM'])
source['138'] = 138
base = alt.Chart(source).mark_line().encode(
x=alt.X('Year'),
y=alt.Y('Average Episode BPM', scale=alt.Scale(domain=(130, 140))),
).properties(
title="A State of Trance - Annual Average BPM of Episode",
width=600
)
rule = alt.Chart(source).mark_rule(color='red').encode(
y='138'
)
base + rule
Straightforward enough. In the coming posts we'll do something similar, looking at the most-played artists and tracks each year.