def mapper(self, _, line):
        """ The mapper loads a track and yields its ramp factor """
        t = track.load_track(line)
        segments = t['segments']
        duration = t['duration']
        xdata = []
        ydata = []
        for i in xrange(len(segments)):
            seg = segments[i]
            sloudness = seg['loudness_max']
            sstart = seg['start'] + seg['loudness_max_time']
            xdata.append( sstart )
            ydata.append( sloudness )

        if duration > 20:
            idata = tools.interpolate(xdata, ydata, int(duration) * 10)
            smooth = tools.smooth(idata, 20)
            samp = tools.sample(smooth, self.SIZE)
            ndata = tools.rnormalize(samp, -60, 0)
            if self.DUMP:
                for i, (x, y) in enumerate(zip(self.MATCH, ndata)):
                    print i, x, y
            if self.VECTOR:
                yield (t['artist_name'], t['title'], t['track_id']), ndata
            else:
                distance = tools.distance(self.MATCH, ndata)
                yield (t['artist_name'], t['title'], t['track_id']), distance
Exemple #2
0
    def mapper(self, _, line):
        """ The mapper loads a track and yields its ramp factor """
        t = track.load_track(line)
        segments = t['segments']
        duration = t['duration']
        xdata = []
        ydata = []
        for i in xrange(len(segments)):
            seg = segments[i]
            sloudness = seg['loudness_max']
            sstart = seg['start'] + seg['loudness_max_time']
            xdata.append(sstart)
            ydata.append(sloudness)

        if duration > 20:
            idata = tools.interpolate(xdata, ydata, int(duration) * 10)
            smooth = tools.smooth(idata, 20)
            samp = tools.sample(smooth, self.SIZE)
            ndata = tools.rnormalize(samp, -60, 0)
            if self.DUMP:
                for i, (x, y) in enumerate(zip(self.MATCH, ndata)):
                    print i, x, y
            if self.VECTOR:
                yield (t['artist_name'], t['title'], t['track_id']), ndata
            else:
                distance = tools.distance(self.MATCH, ndata)
                yield (t['artist_name'], t['title'], t['track_id']), distance
    def mapper(self, _, line):
        """ The mapper loads a track and yields its density """
        t = track.load_track(line)
        fields = ()
        if t:
            for field in t:
                if field in keep:
                    if (field == 'key'):
                        item = key_map[t[field][0]]
                    elif (field == 'mode'):
                        item = mode_map[t[field][0]]
                    elif (field == 'artist_terms'):
                        item = "N/A"
                        for term in t[field]:
                            if term[0] in label_list:
                                item = term[0]
                                break
                    elif (field == 'time_signature'):
                        item = t[field][0]
                    else:
                        item = t[field]

                    fields = fields + (item,)

            yield t['track_id'], fields
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     fields = ()
     if t:
         labels = t['artist_terms']
         for label in labels:
         	yield label[0], 1
Exemple #5
0
    def mapper(self, _, line):
        """ The mapper loads a track and yields its ramp factor """
        t = track.load_track(line)
        if t and t['duration'] > 60 and len(t['segments']) > 20:
            segments = t['segments']
            half_track = t['duration'] / 2
            first_half = 0
            second_half = 0
            first_count = 0
            second_count = 0

            xdata = []
            ydata = []
            for i in xrange(len(segments)):
                seg = segments[i]

                # bail out if we have a really long quiet segment
                # these are usually surprise hidden tracks

                if seg['loudness_max'] < -40 and seg['duration'] > 30:
                    return

                seg_loudness = seg['loudness_max'] * seg['duration']

                if seg['start'] + seg['duration'] <= half_track:
                    seg_loudness = seg['loudness_max'] * seg['duration']
                    first_half += seg_loudness
                    first_count += 1
                elif seg['start'] < half_track and seg['start'] + seg[
                        'duration'] > half_track:
                    # this is the nasty segment that spans the song midpoint.
                    # apportion the loudness appropriately
                    first_seg_loudness = seg['loudness_max'] * (half_track -
                                                                seg['start'])
                    first_half += first_seg_loudness
                    first_count += 1

                    second_seg_loudness = seg['loudness_max'] * (
                        seg['duration'] - (half_track - seg['start']))
                    second_half += second_seg_loudness
                    second_count += 1
                else:
                    seg_loudness = seg['loudness_max'] * seg['duration']
                    second_half += seg_loudness
                    second_count += 1

                xdata.append(seg['start'])
                ydata.append(seg['loudness_max'])

            # only yield data if we've had sufficient segments in the first
            # and second half of the track. (This is to avoid the proverbial
            # hidden tracks that have extreme amounts of leading or tailing
            # silene

            correlation = pearsonr(xdata, ydata)
            ramp_factor = second_half / half_track - first_half / half_track
            score = correlation * ramp_factor
            yield (t['artist_id'], t['artist_name']), (score, t['track_id'])
Exemple #6
0
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     if t:
         if t['tempo'] > 0:
             density = len(t['segments']) / t['duration']
             #only output extreme density
             if YIELD_ALL or density > 8 or density < .5:
                 yield (t['artist_name'], t['title'], t['song_id']), density
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     if t:
         if t['tempo'] > 0:
             density = len(t['segments']) / t['duration']
             #only output extreme density
             if YIELD_ALL or density > 8 or density < .5:
                 yield (t['artist_name'], t['title'], t['song_id']), density
Exemple #8
0
    def mapper(self, _, line):
        """ The mapper loads a track and yields its ramp factor """
        t = track.load_track(line)
        if t and t['duration'] > 60 and len(t['segments']) > 20:
            segments = t['segments']
            half_track = t['duration'] / 2
            first_half = 0
            second_half = 0
            first_count = 0
            second_count = 0

            xdata = []
            ydata = []
            for i in xrange(len(segments)):
                seg = segments[i]

                # bail out if we have a really long quiet segment
                # these are usually surprise hidden tracks

                if seg['loudness_max'] < -40 and seg['duration'] > 30:
                    return

                seg_loudness = seg['loudness_max'] * seg['duration']

                if seg['start'] + seg['duration'] <= half_track:
                    seg_loudness = seg['loudness_max'] * seg['duration']
                    first_half += seg_loudness
                    first_count += 1
                elif seg['start'] < half_track and seg['start'] + seg['duration'] > half_track:
                    # this is the nasty segment that spans the song midpoint.
                    # apportion the loudness appropriately
                    first_seg_loudness = seg['loudness_max'] * (half_track - seg['start'])
                    first_half += first_seg_loudness
                    first_count += 1

                    second_seg_loudness = seg['loudness_max'] * (seg['duration'] - (half_track - seg['start']))
                    second_half += second_seg_loudness
                    second_count += 1
                else:
                    seg_loudness = seg['loudness_max'] * seg['duration']
                    second_half += seg_loudness
                    second_count += 1

                xdata.append( seg['start'] )
                ydata.append( seg['loudness_max'] )

            # only yield data if we've had sufficient segments in the first
            # and second half of the track. (This is to avoid the proverbial
            # hidden tracks that have extreme amounts of leading or tailing
            # silene

            correlation = pearsonr(xdata, ydata)
            if first_count > 10 and second_count > 10:
                ramp_factor = second_half / half_track - first_half / half_track
                #if YIELD_ALL or ramp_factor > 10 or ramp_factor < -10:
                if YIELD_ALL or ramp_factor > 10 and correlation > .5:
                    yield (t['artist_name'], t['title'], t['track_id'], correlation), ramp_factor
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     if t:
         if t['tempo'] > 2:
             #density = 1
             #only output extreme density
             if YIELD_ALL :
                 yield (t['artist_name']), #density
Exemple #10
0
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     if t:
         if t['tempo'] > 2:
             #density = 1
             #only output extreme density
             if YIELD_ALL:
                 yield (t['artist_name']),  #density
Exemple #11
0
def listMSDValues(filepath, value):
    """
        URL getter of a given track for use in the
    """
    f = open(filepath)

    valuestr = str(value)
    for which, line in enumerate(f):
        t = track.load_track(line)
        print t['title']
        print t[valuestr]
Exemple #12
0
def listMSDValues(filepath, value):
    """
        URL getter of a given track for use in the
    """
    f = open(filepath)

    valuestr = str(value)
    for which, line in enumerate(f):
        t = track.load_track(line)
        print t['title']
        print t[valuestr]
Exemple #13
0
def min_distance():
    IMG_PATH = "./tracks/loop.png"
    track = load_track(IMG_PATH)

    # Set to a valid point in trajectory
    starting_position = (150., 200.)
    car = PointCar(*starting_position)
    n_loops = 1
    trellis = path_finding.find_valid_trajectory(car,
                                                 track,
                                                 loops=n_loops,
                                                 states=31)
    split_idx = (len(trellis) // n_loops) + 1 if n_loops > 1 else 0

    c_idx = len(trellis[0]) // 2
    in_idx = 0
    centerline = [t[c_idx] for t in trellis]
    print_stats(centerline)
    inner_contour = [t[in_idx] for t in trellis]
    print_stats(inner_contour)

    path_v = viterbi.additive_viterbi(trellis, alpha=1.0, beta=0.0)
    print_stats(path_v[split_idx:2 * split_idx])
    path_s = optimal.run(trellis, alpha=1.0, beta=0.0)
    print_stats(path_s[split_idx:2 * split_idx])

    xv = [i[0] for i in path_v[split_idx:2 * split_idx]]
    yv = [i[1] for i in path_v[split_idx:2 * split_idx]]
    xs = [i[0] for i in path_s[split_idx:2 * split_idx]]
    ys = [i[1] for i in path_s[split_idx:2 * split_idx]]

    if a.plot:
        fig, ax = plt.subplots()
        ax.imshow(track)
        plt.xlabel("Meters")
        plt.ylabel("Meters")
        ax.fill(xv,
                yv,
                facecolor='none',
                edgecolor='green',
                linestyle="-",
                label="Distance Objective")

        fig, ax = plt.subplots()
        ax.imshow(track)
        plt.xlabel("Meters")
        plt.ylabel("Meters")
        ax.fill(xs,
                ys,
                facecolor='none',
                edgecolor='blue',
                linestyle="-",
                label="Time Objective")
        plt.show()
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     fields = ()
     if t:
         lat, lng = t["artist_latitude"], t["artist_longitude"]
         # print "L/L", lat, lng
         if math.isnan(lat) == False and math.isnan(lng) == False:
             zip = get_fips(lat, lng)
             if zip != None:
                 yield zip, 1
Exemple #15
0
 def downloadtrack(self, track, line, downloadpath):
     t = track.load_track(line)
     print(t['preview'])
     #print t['preview']
     try:
         mp3 = urllib2.urlopen(t['preview'])
         mp3name =  downloadpath + '/' + t['track_id'] + ".mp3"
         with open(mp3name, "wb") as code:
             code.write(mp3.read())
             print(mp3name)              #[DEBUG]
     except urllib2.HTTPError:
         mp3 = get_preview_url.get_preview_from_trackid(t['track_id'])
         print(mp3)
         print "dammit."                 #[DEBUG]
Exemple #16
0
def song(start, number):
	song_file = open("../Data/A.tsv.a")

	for n in xrange(start):
		song = song_file.readline()

	sample_file = open("samplesong.txt", "w")

	for songNumber in xrange(number):
		t = track.load_track(song)



		count = 0
		for field in t:
			count += 1
			sample_file.write("{:d} {:>22} {:s}\n".format(count, str(field), str(t[field])))
		song = song_file.readline()
Exemple #17
0
def state_tradeoff():
    IMG_PATH = "./tracks/loop.png"
    track = load_track(IMG_PATH)

    # Set to a valid point in trajectory
    starting_position = (150., 200.)
    car = PointCar(*starting_position)
    for s in [1, 5, 10, 20, 40, 80]:
        n_loops = 3
        trellis = path_finding.find_valid_trajectory(car,
                                                     track,
                                                     loops=n_loops,
                                                     states=s)
        split_idx = (len(trellis) // n_loops) + 1 if n_loops > 1 else 0
        path_v = viterbi.additive_viterbi(trellis, alpha=1.0,
                                          beta=0.0)[split_idx:2 * split_idx]
        print_stats(path_v)
        path_s = optimal.run(trellis, alpha=1.0,
                             beta=0.0)[split_idx:2 * split_idx]
        print_stats(path_s)
Exemple #18
0
    def mapper(self, _, line):
        """ The mapper loads a track and yields its density """
        t = track.load_track(line)
        fields = ()
        if t:
            #group = genre
            #area = count(key)
            #id = year?
            #genre
            #
            year = t['year']
            key = key_map[t['key'][0]]
            mode = mode_map[t['mode'][0]]
            song_id = t['song_id']
            genre = "N/A"
            hot = t['song_hotttnesss']
            for term in t['artist_terms']:
                if term[0] in label_list:
                    genre = term[0]
                    break

            
            yield  (genre, key), hot
Exemple #19
0
def min_time():
    IMG_PATH = "./tracks/loop.png"
    track = load_track(IMG_PATH)

    # Set to a valid point in trajectory
    starting_position = (150., 200.)
    car = PointCar(*starting_position)
    n_loops = 3
    trellis = path_finding.find_valid_trajectory(car,
                                                 track,
                                                 loops=n_loops,
                                                 states=30)
    split_idx = (len(trellis) // n_loops) + 1 if n_loops > 1 else 0

    path_v = viterbi.additive_viterbi(trellis, alpha=1.0, beta=0.0)
    print_stats(path_v[split_idx:2 * split_idx])
    path_s = optimal.run(trellis, alpha=0.5, beta=0.5)
    print_stats(path_s[split_idx:])

    xv = [i[0] for i in path_v[split_idx:2 * split_idx]]
    yv = [i[1] for i in path_v[split_idx:2 * split_idx]]
    xs = [i[0] for i in path_v[split_idx:2 * split_idx]]
    ys = [i[1] for i in path_v[split_idx:2 * split_idx]]

    if a.plot:
        fig1, ax1 = plt.subplots()
        ax1.imshow(track)
        plt.xlabel("Meters")
        plt.ylabel("Meters")
        ax1.fill(xv, yv, facecolor='none', edgecolor='green', linestyle="-")

        fig2, ax2 = plt.subplots()
        ax2.imshow(track)
        plt.xlabel("Meters")
        plt.ylabel("Meters")
        ax2.fill(xs, ys, facecolor='none', edgecolor='blue', linestyle="-")
        plt.show()
Exemple #20
0
 def mapper(self, _, line):
     """ The mapper loads a track and yields its density """
     t = track.load_track(line)
     if t:
         yield t['year'], t['duration']
Exemple #21
0
    nopass = [x for x in range(mgraph.shape[0]) if x != start]
    dis = mgraph[start]

    while len(nopass):
        idx = nopass[0]
        for i in nopass:
            if dis[i] < dis[idx]: idx = i

        nopass.remove(idx)
        passed.append(idx)

        for i in nopass:
            if dis[idx] + mgraph[idx][i] < dis[i]: dis[i] = dis[idx] + mgraph[idx][i]
    return dis


if __name__ == "__main__":
    IMG_PATH = "./tracks/loop.png"
    track = load_track(IMG_PATH)

    a = datetime.datetime.now()
    # Set to a valid point in trajectory
    car = PointCar(150, 200)
    trellis = find_valid_trajectory(car, track)
    matrix = build_matrix(trellis)
    dijstra_m = dijstra_O2(0, matrix)
    for item in dijstra_m[-10:]:
        print(item)

    b = datetime.datetime.now()
    print(b-a)