Пример #1
0
    def _getData(self, key, bpm, instrumentKey):
        self.writer.PrintAndWrite("** getting data")

        # gets all the songs with the correct bpm, key and instrument
        clipList = QueryRunner.getSongsWithBPMKeyAndInstrumentId(
            bpm, key, instrumentKey)
        if len(clipList) is 0:
            return False

        idClipList = []

        for item in clipList:
            idClipList.append(item[0])

        # need to have the preference for all users
        preferences = {}
        allPreferences = QueryRunner.getAllUsersPreferenceFull()
        if allPreferences is None:
            return False

        for pref in allPreferences:
            resultDict = {}
            user = pref[0]
            item1 = pref[1]
            item2 = pref[2]
            rating = pref[3]

            if item1 in idClipList:
                if item1 not in resultDict:
                    resultDict[item1] = rating
                else:
                    resultDict[item1] += rating

            if item2 in idClipList:
                if item2 not in resultDict:
                    resultDict[item2] = rating
                else:
                    resultDict[item2] += rating

            if user not in preferences:
                # if the user is not known, just add the generated dictionary
                preferences[user] = resultDict

            else:
                # if the user is known, update the existing dictionary with new data
                existingDict = preferences[user]
                for (subkey, subitem) in resultDict.items():
                    existingDict[subkey] = subitem
                preferences[user] = existingDict

        self.data = preferences
Пример #2
0
def findAllTracksNotUsed():
    clipsUsed = {}
    instrumentUsed = {}
    cursor, connection = QueryRunner._createcursorandconnection()

    allTracks = QueryRunner.getAllTracks()
    for track in allTracks:
        trackId = track[0]
        instrument = track[1]

        if trackId not in clipsUsed.keys():
            clipsUsed[trackId] = 0

        if instrument not in instrumentUsed.keys():
            instrumentUsed[instrument] = 0

    allUsersPref = QueryRunner.getAllUsersPreferenceFull(cursor=cursor)

    for rating in allUsersPref:

        item1 = rating[1]
        item2 = rating[2]

        clipsUsed[item1] += 1

        item1Inst = QueryRunner.getInstrumentIDFromInstrumentKey(item1,
                                                                 cursor=cursor)
        instrumentUsed[item1Inst] += 1

        if item1 != item2:
            clipsUsed[item2] += 1

            item2Inst = QueryRunner.getInstrumentIDFromInstrumentKey(
                item2, cursor=cursor)
            instrumentUsed[item2Inst] += 1

    sorted_mostused = sorted(clipsUsed.items(),
                             key=operator.itemgetter(1),
                             reverse=True)
    print(sorted_mostused)

    print()

    sorted_inst = sorted(instrumentUsed.items(),
                         key=operator.itemgetter(1),
                         reverse=True)
    print(sorted_inst)
Пример #3
0
def WriteScoresToFile():
    print("*** WRITING USER PREFERENCES TO FILE ***")

    path = "testData/scores"

    cursor = QueryRunner._createcursor()
    data = QueryRunner.getAllUsersPreferenceFull(cursor=cursor)

    if data is None:
        return False

    print(data)

    with open(path, 'w') as f:

        for row in data:

            user = str(row[0])
            item1 = str(row[1])
            item2 = str(row[2])
            score = str(row[3])

            clips = QueryRunner.getClipClipIdFromClips(clip1=item1,
                                                       clip2=item2,
                                                       cursor=cursor)
            if clips is None:
                continue

            strClip = str(clips)

            f.write(user + "\t" + str(strClip) + "\t" + score + "\n")

    print("*** WRITING DONE ***")
    print()

    return True