def get(self): print('start check') username = self.get_secure_cookie('username') if len(userTrack.choose_rec_tracks(username)) == 0: self.write({'status': "Fail"}) print('end check') refresh.check_and_refresh(username) self.write({'status': "OK"})
def store_tracks_info(username): ''' Fetch tracks mp3 url and store them ''' users_tracks = userTrack.choose_all_tracks(username) + \ userTrack.choose_rec_tracks(username) user_tracks = userTrack.choose_tracks_info(users_tracks) info.fetch_tracks_urls(user_tracks) userTrack.store_tracks_info(user_tracks) userTrack.delete_invalid_tracks(username)
def init_emotion(username): ''' start emotion tracks ''' user_tracks = userTrack.choose_all_tracks(username) user_tracks = userTrack.choose_tracks_info(user_tracks) emotion_gevent = geventWorker.Worker(50, 'add_element') emotion_gevent.pack(user_tracks, emotion_contr.calculate_tags) lib_emotion_array = emotion_gevent.return_results() rec_tracks = userTrack.choose_rec_tracks(username) rec_tracks = userTrack.choose_tracks_info(rec_tracks) rec_gevent = geventWorker.Worker(50, 'add_element') rec_gevent.pack(rec_tracks, emotion_contr.calculate_tags) rec_emotion_array = rec_gevent.return_results() # emotion_contr.filter_no_tags(lib_emotion_array, rec_emotion_array) userTrack.add_tracks_emotion(lib_emotion_array + rec_emotion_array)
def choose_tracks(username, lib_ratio, emotion_range): ''' Choose all user tracks from database And pick some tracks ''' lib_list = userTrack.choose_all_tracks(username) lib_list = userTrack.choose_tracks_info(lib_list) rec_list = userTrack.choose_rec_tracks(username) rec_list = userTrack.choose_tracks_info(rec_list) picker = Picker(lib_list, rec_list, username, emotion_range) tracks_list = [ picker.next_mix(track_number, lib_ratio) for track_number in xrange(STORED_TRACKS_NUMBER) ] next_emotion_range = _next_emotion(emotion_range) picker.emotion_range = next_emotion_range next_playlist = picker.next_mix(0, lib_ratio) return tracks_list, next_playlist
def _filter_tracks(self): ''' Get the tracks from the db and make it into the instance of the class NextTrack ''' if self.user_status.last_track: last_title = self.user_status.last_track.title else: last_title = None username = self.user_status.username while 1: emo_range, tag, lib = track_rule.track_rule( "filter", self.user_status) emo_range = emo_range(self.user_status) if emo_range else None tag = tag(self.user_status) if tag else None if lib == "lib": self.lib_tracks = userTrack.choose_all_tracks(username) elif lib == "rec": self.rec_tracks = userTrack.choose_rec_tracks(username) lib_uuids = [track.track_uuid for track in getattr(self, "%s_tracks" % (lib))] if not emo_range and not tag: self.sample_tracks = userTrack.get_source_rec( last_title, username) if not self.sample_tracks: print("No similar rec") self.user_status.track_number.has_source = False else: break else: self.sample_tracks = userTrack.get_user_tracks_detail( emo_range, tag, lib_uuids) if self.sample_tracks: break else: # @todo pass self.chosen_tracks = getattr(self, '%s_tracks' % (lib)) self.lib = lib random.shuffle(self.sample_tracks)