def get_series(user, length=4, limit=15):

    if ":" in user:
        user = user.replace("_", "+")
        
    data, weeks = get_data(user, length)

    if not data and not weeks:
        data, weeks = get_data(user, length)
        if not data and not weeks:
            data, weeks = get_data(user, length)
            if not data and not weeks:
                return None
    
    artists = {}
        
    for week in data:
        for artist, plays in week:
            artists[artist] = []
    
    for week in data:
        week = dict(week)
        for artist in artists:
            plays = week.get(artist, 0)
            if plays < 2:
                plays = 0
            artists[artist].append(plays)
    
    artists = artists.items()
    artists.sort(key=lambda (x,y):max(y))
    artists.reverse()
    
    sh, ss, sv = rgb_to_hsv(*hex_to_rgba("ec2d60")[:3])
    eh, es, ev = rgb_to_hsv(*hex_to_rgba("0c4da2")[:3])
    a = True
    ad = 0.3
    
    th, ts, tv = (eh-sh)/float(limit), (es-ss)/float(limit), (ev-sv)/float(limit)
    
    series_set = SeriesSet()
    for artist, data in artists[:15]:
        series_set.add_series(Series(
            artist,
            dict([(datetime.datetime.fromtimestamp(weeks[i][0]), x) for i, x in enumerate(data)]),
            rgba_to_hex(*(hsv_to_rgb(sh, ss, sv) + (a and 1 or 1-ad,))),
        ))
        sh += th
        ss += ts
        sv += tv
        a = not a
        ad += (0.6/limit)
    
    return series_set
dataset/ETHPy150Open andrewgodwin/lastgraph/lastslice/slice.py/get_series/original