def increase_own_value(cls, sound_id): current = DBSession.query(cls).filter_by( left_sound_id=sound_id, right_sound_id=sound_id).first() rate = int((100 - current.weight) - (100 - current.weight) / 1.618) DBSession.query(cls).\ filter_by(left_sound_id=sound_id, right_sound_id=sound_id).\ update({"weight": cls.weight + rate}, synchronize_session='fetch')
def reduce_own_value(cls, sound_id): current = DBSession.query(cls).filter_by( left_sound_id=sound_id, right_sound_id=sound_id).first() rate = int(current.weight - current.weight / 1.618) DBSession.query(cls).\ filter_by(left_sound_id=sound_id, right_sound_id=sound_id).\ update({"weight": cls.weight - rate}, synchronize_session='fetch')
def generation_null_relation(cls, sound_quantity): DBSession.query(cls).delete() for i in xrange(1, sound_quantity + 1): for j in xrange(1, sound_quantity + 1): DBSession.add( Relation(left_sound_id=i, weight=int(100 - 100 / 1.618), right_sound_id=j))
def generation_new_relation(cls, sound_quantity): DBSession.query(cls).delete() for i in xrange(1, sound_quantity + 1): for j in xrange(1, sound_quantity + 1): DBSession.add( Relation(left_sound_id=i, weight=random.randint(0, 100), right_sound_id=j))
def reduce_relation(cls, previous_id, current_id): current_rel = DBSession.query(cls).filter_by( left_sound_id=previous_id, right_sound_id=current_id).first() rate = int(current_rel.weight - current_rel.weight / 1.618) DBSession.query(cls).\ filter(cls.left_sound_id==previous_id).\ filter(cls.right_sound_id==current_id).\ update({"weight": cls.weight - rate}, synchronize_session='fetch')
def increase_relation(cls, previous_id, current_id): current_rel = DBSession.query(cls).filter_by( left_sound_id=previous_id, right_sound_id=current_id).first() rate = int((100 - current_rel.weight) - (100 - current_rel.weight) / 1.618) DBSession.query(cls).\ filter(cls.left_sound_id==previous_id).\ filter(cls.right_sound_id==current_id).\ update({"weight": cls.weight + rate})
def get_previous_sound(cls, soung_id): #fibonacci = [1, 1, 2, 3, 5, 8] sounds = DBSession.query(Sound).all() random.seed() next_sound = random.randint(1, len(sounds)) return next_sound
def index(self, id=2, previous_id=1): try: sound = DBSession.query(Sound).get(id) sound_url = '/music/' + str(sound.sound_id) + '.mp3' except: redirect('/sound') return dict(page='player', sound=sound, sound_url=sound_url, previous_id=previous_id)
def get_next_sound(cls, soung_id): sounds = DBSession.query(Sound).all() random.seed() next_sound = random.randint(1, len(sounds)) #fibonacci = [1, 1, 2, 3, 5, 8] #relations = DBSession.query(cls).\ # filter(cls.left_sound_id==soung_id).\ # filter(cls.left_sound_id!=cls.right_sound_id).\ # all() return next_sound
def index(self, **kw): relations = DBSession.query(Relation).all() sounds = DBSession.query(Sound).all() #relations_table = [] #relations_table = [[0 for i in range(0, len(sounds))] for j in range(0, len(sounds))] try: relations_table = [] relations_table = [[0 for i in range(0, len(sounds))] for j in range(0, len(sounds))] for i in relations: relations_table[i.left_sound_id - 1][i.right_sound_id - 1] = i.weight except: pass return dict(page='relation', relations=relations, relations_table=relations_table)
def generation_test_data(cls, quantity): try: last_sound = DBSession.query(cls).order_by( cls.sound_id.desc()).first() last = last_sound.sound_id + 1 except: last = 1 for i in xrange(last, last + quantity): DBSession.add( Sound(sound_name='Test Song #%s' % i, data='Test Data #%s' % i, user_id=1))
def album(self, **kw): sounds = DBSession.query(Sound).all() sorted_dict = {} for sound in sounds: try: sorted_dict[sound.album].append([sound.sound_name, sound.data]) except: sorted_dict[sound.album] = [[sound.sound_name, sound.data]] sorted_dict = collections.OrderedDict(sorted(sorted_dict.items())) keys = sorted_dict.keys() return dict(page='album', sorted_dict=sorted_dict, keys=keys, tag='Album')
def index(self): sounds = DBSession.query(Sound).all() return dict(page='sound', sounds=sounds)
def clear_data(cls): DBSession.query(cls).delete()
def get(cls, id): return DBSession.query(cls).filter_by(sound_id=id).first()
def gener_null_relation(self): sounds = DBSession.query(Sound).all() Relation.generation_null_relation(len(sounds)) redirect('/relation')
def get_by_left(cls, id): return DBSession.query(cls).filter_by(left_sound_id=id).first()
def get_by_right(cls, id): return DBSession.query(cls).filter_by(right_sound_id=id).first()