<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
show_artist.py

Created by <NAME> on 2009-08-04.
Copyright (c) 2009 The Echo Nest Corporation. All rights reserved.
"""

import sys
import os

from pyechonest import track as track_api
from pyechonest import config
import matplotlib.pyplot as plt

# How to set your ECHO_NEST_API_KEY:
#   1) Set the environment variable 'ECHO_NEST_API_KEY' to be your key, or
#   2) Uncomment the next line and add your key between the quotes
#config.ECHO_NEST_API_KEY="YOUR API KEY HERE" 

usage = "Usage: click_plot.py filename"

def plot_click_track(filename):
    track = track_api.Track(filename)
    tempo = float(track.tempo['value'])
    beats = track.beats
    times = [ dict['start'] for dict in beats ]
    bpms = get_bpms(times)
    plt.ylabel('Beats Per Minute')
    plt.xlabel('Time')
    plt.title('Click Plot for ' + os.path.basename(filename))
    plt.plot(times, get_filtered_bpms(bpms), label='Filtered')
    plt.plot(times, bpms, color=('0.8'), label='raw')
    plt.ylim(tempo * .9, tempo * 1.1)
    plt.axhline(tempo, color=('0.7'), label="Tempo")
    plt.show()

def get_bpms(times):
    bpms = []
    for i in xrange(len(times) - 1):
        delta = times[i + 1] - times[i]
        bpms.append(60. / delta)
    bpms.append(60. / delta)
    return bpms
<commit_msg>Added docs detailing how to get and install matplotlib if the import fails<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
show_artist.py

Created by <NAME> on 2009-08-04.
Copyright (c) 2009 The Echo Nest Corporation. All rights reserved.
"""

import sys
import os

from pyechonest import track as track_api
from pyechonest import config
try:
    import matplotlib.pyplot as plt
except ImportError:
    print """
click_plot.py requires matplotlib. 

You can get it here: 

    http://matplotlib.sourceforge.net/.

Instructions for installing matplotlib are here:

    http://matplotlib.sourceforge.net/users/installing.html

"""
    sys.exit(1)

# How to set your ECHO_NEST_API_KEY:
#   1) Set the environment variable 'ECHO_NEST_API_KEY' to be your key, or
#   2) Uncomment the next line and add your key between the quotes
#config.ECHO_NEST_API_KEY="YOUR API KEY HERE" 

usage = "Usage: click_plot.py filename"

def plot_click_track(filename):
    track = track_api.Track(filename)
    tempo = float(track.tempo['value'])
    beats = track.beats
    times = [ dict['start'] for dict in beats ]
    bpms = get_bpms(times)
    plt.ylabel('Beats Per Minute')
    plt.xlabel('Time')
    plt.title('Click Plot for ' + os.path.basename(filename))
    plt.plot(times, get_filtered_bpms(bpms), label='Filtered')
    plt.plot(times, bpms, color=('0.8'), label='raw')
    plt.ylim(tempo * .9, tempo * 1.1)
    plt.axhline(tempo, color=('0.7'), label="Tempo")
    plt.show()

def get_bpms(times):
    bpms = []
    for i in xrange(len(times) - 1):
        delta = times[i + 1] - times[i]
        bpms.append(60. / delta)
    bpms.append(60. / delta)
    return bpms

{'fraction_non_alphanumeric': 0.12550066755674233, 'fraction_numerical': 0.019025367156208277, 'mean_word_length': 3.534039334341906, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6474001', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1057, 'n_words': 295}