コード例 #1
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 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')
コード例 #2
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 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')
コード例 #3
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 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')
コード例 #4
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 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))
コード例 #5
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 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))
コード例 #6
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 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})
コード例 #7
0
ファイル: sound.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
    def upload_files(cls, directory):
        tree = 'C:\\Users\\Leafmen\\Desktop\\python\\diploma\\webplayer\\webplayer\\public'
        directory = tree + '\\music' + directory
        #files = listdir(tg.url('/music' + directory))
        files = listdir(directory)

        for file in files:
            sound = {}
            meta = mutagen.File(directory + '/' + file)

            try:
                sound['name'] = str(meta['TIT2']).encode('utf8')
            except:
                sound['name'] = 'Null'

            try:
                sound['date'] = str(meta['TDRC']).encode('utf8')
            except:
                sound['date'] = 'Null'

            try:
                sound['album'] = str(meta['TALB']).encode('utf8')
            except:
                sound['album'] = 'Null'

            try:
                sound['genre'] = str(meta['TCON']).encode('utf8')
            except:
                sound['genre'] = 'Null'

            try:
                sound['artist'] = str(meta['TPE1']).encode('utf8')
            except:
                sound['artist'] = 'Null'

            sound['data'] = str(file).encode('utf8')

            try:
                pic = meta.tags.getall("APIC")[0].data
                with open(tree + '\\img\\%s.jpg' % sound['data'], 'wb') as img:
                    img.write(pic)
                sound['picture'] = '%s.jpg' % sound['data']
            except:
                sound['picture'] = 'Null'

            DBSession.add(
                Sound(sound_name=sound['name'],
                      date=sound['date'],
                      album=sound['album'],
                      genre=sound['genre'],
                      artist=sound['artist'],
                      data=sound['data'],
                      picture=sound['picture'],
                      user_id=1))
コード例 #8
0
ファイル: sound.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
    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))
コード例 #9
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
    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
コード例 #10
0
ファイル: player.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
    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)
コード例 #11
0
    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)
コード例 #12
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
    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
コード例 #13
0
   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')
コード例 #14
0
ファイル: sound.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 def index(self):
     sounds = DBSession.query(Sound).all()
     return dict(page='sound', sounds=sounds)
コード例 #15
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 def get_by_right(cls, id):
     return DBSession.query(cls).filter_by(right_sound_id=id).first()
コード例 #16
0
ファイル: sound.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 def clear_data(cls):
     DBSession.query(cls).delete()
コード例 #17
0
ファイル: relation.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 def get_by_left(cls, id):
     return DBSession.query(cls).filter_by(left_sound_id=id).first()
コード例 #18
0
ファイル: sound.py プロジェクト: DmitriyLeaf/SPA_WebPlayer
 def get(cls, id):
     return DBSession.query(cls).filter_by(sound_id=id).first()
コード例 #19
0
 def gener_null_relation(self):
     sounds = DBSession.query(Sound).all()
     Relation.generation_null_relation(len(sounds))
     redirect('/relation')