示例#1
0
 def stats(self, _=None):
     log_api_call('stats')
     results = get_results()
     stats = {
         'db_stats' : db.stats(),
         'api_stats' : get_api_call_stats()
     }
     results['stats'] = stats
     return seal_results(results)
示例#2
0
def make_playlist(artist, title, hours):
    hours = int(hours)

    stats = db.stats(artist, title)
    start = stats['first']

    print stats

    # At first we make a basic assumption that a song is 4 minutes long
    songs_per_hour = 60.0/4

    number_years = 2015 - int(start[:4])

    if number_years > hours:
        actual_hours = number_years
    else:
        actual_hours = hours

    available_slots = actual_hours * songs_per_hour

    print "actual hours %s avail slots %s" % (actual_hours, available_slots)

    # first start with the first year -> end of that year
    allsongs = songs_for_year(start)
    # then go one per year until the last year
    allsongs = []
    lastyear = 2015
    year = int(start[:4])
    while year <= lastyear:
        print "songs for", year
        allsongs.extend(songs_for_year("%s-01-01" % year))
        year += 1

    # We now have too many songs. See how many we need to throw away
    remove_prob = float(available_slots)/len(allsongs)
    print "removing with prob of", remove_prob

    songs = []
    lastsong = None
    for s in allsongs:
        if random.random() < remove_prob and s != lastsong:
            songs.append(s)
            lastsong = s

    return actual_hours, songs
示例#3
0
文件: cli.py 项目: plamere/SixDegrees
 def do_astats(self, line):
     ''' report connectivity stats for artist '''
     aid = self.asearch(line)
     if aid:
         db.stats(aid)