Пример #1
0
def _checkIfFirstTrackIsLongerOrEqual(clipId1, clipId2):
    track1Len = QueryRunner.getTrackLength(clipId1)
    track2Len = QueryRunner.getTrackLength(clipId2)

    if track1Len == track2Len or track1Len > track2Len:
        return True
    else:
        return False
Пример #2
0
 def _getHighIntenseTracks(self, bpm, key, instrumentID):
     songList1 = QueryRunner.GetSongsWithBPMandKeyAndInstrumentAndInstense(
         bpm=bpm, key=key, instrumentId=instrumentID, intense=4)
     songList2 = QueryRunner.GetSongsWithBPMandKeyAndInstrumentAndInstense(
         bpm=bpm, key=key, instrumentId=instrumentID, intense=5)
     for item in songList2:
         songList1.append(item)
     return songList1
Пример #3
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
Пример #4
0
def selectRecommendationEngine(profile, useItemBased, writer):

	engine = None

	userIdList = QueryRunner.getAllUserProfileIds()
	if userIdList is None:
		useItemBased = False


	writer.PrintAndWrite("user list: " + str(userIdList))

	#need to check if the user has enough items in his profile to create a valid recomendation

	if useItemBased is True and profile in userIdList:
		#get content based
		writer.PrintAndWrite("ITEM BASED", False)
		engine = _getItemBasedEngine(writer)

	else:
		#get knowledge based
		writer.PrintAndWrite("KNOWLEDGE BASED", False)
		engine = _getKnowledgeBasedEngine()

	print()
	return engine
Пример #5
0
def GetFeedbackOnSong(profileKey, elementDict, writer):
    # should get feedback on the three tracks in context of the song
    writer.PrintAndWrite("** Feedback on song ** ", False)

    for i in range(0, 3):

        currentInstruments = []

        for j in elementDict:
            current = elementDict[j].getElements()[i]
            currentInstruments.append(current)

        if int(i) == 0:
            writer.PrintAndWrite(
                "Rate the GUITAR track from the generated song ",
                onlyWrite=False)
        elif i == 1:
            writer.PrintAndWrite(
                "Rate the BASS track from the generated song ", False)
        elif i == 2:
            writer.PrintAndWrite(
                "Rate the DRUM track from the generated song ", False)

        feedbackGuitar = GetFeedback(writer)
        normalizedRating = Normalizer.normalizeRating(feedbackGuitar)
        QueryRunner.InsertUserPreferenceFromSlice(profileKey,
                                                  currentInstruments,
                                                  normalizedRating)
Пример #6
0
    def _registerClipRelations(self, elementDictionary):
        self.writer.PrintAndWrite("", False)
        self.writer.PrintAndWrite("** REGISTERING CLIP RELATIONS **", False)

        for i in range(0, 3):
            currentItem = None
            previousItem = None
            for element in elementDictionary:
                previousItem = currentItem
                temp = elementDictionary[element].getElements()

                if len(temp) < 3:
                    previousItem = None
                    currentItem = None
                    break

                currentItem = temp[i]
                if previousItem is None:
                    continue

                self.clipclipRelation.append([previousItem, currentItem])
                insertSuccess = QueryRunner.InsertClipClipRelation(
                    previousItem, currentItem)
                if insertSuccess:
                    continue
                else:
                    print("insert fail")
                    break
Пример #7
0
	def _randomSliceStructure(self):
		if self.sliceStructs is None:
			self.sliceStructs = QueryRunner.getAllSliceStructures()

		randomSelection = Util.GetRandomElementFromList(self.sliceStructs)

		return randomSelection
Пример #8
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)
Пример #9
0
def GetRandomClip(bpm, key, instrumentId):
    songList = QueryRunner.getSongsWithBPMKeyAndInstrumentId(
        bpm, key, instrumentId)
    if songList is []:
        return None

    length = len(songList) - 1
    randomIndex = randint(0, length)

    return songList[randomIndex][0]
Пример #10
0
def GetFeedbackForKNumberOfSlices(profileKey,
                                  elementDictionary,
                                  writer,
                                  numRandom=3):
    writer.PrintAndWrite("", False)
    writer.PrintAndWrite("** SLICE FEEDBACK ** ", False)

    ratedList = []

    elementDicKeyList = list(elementDictionary.keys())

    loop = 0

    if len(elementDicKeyList) < numRandom:
        loop = len(elementDicKeyList)
    else:
        loop = numRandom

    for i in range(0, loop):

        randomKey = random.choice(elementDicKeyList)

        while randomKey in ratedList:
            randomKey = random.choice(elementDicKeyList)

        ratedList.append(randomKey)

        sliceIdList = elementDictionary[randomKey].getElements()

        success = FeedbackFileCreator.CreateSliceAudioFileForEvaluation(
            sliceIdList)
        if success is False:
            writer.PrintAndWrite(
                "something went wrong with creating the audio file for evaluation"
            )
            continue

        writer.PrintAndWrite("")
        writer.PrintAndWrite("slice id: " + str(sliceIdList), False)
        writer.PrintAndWrite(
            "Listen to the clips and come back. I'll be waiting :) ")

        feedback = GetFeedback(writer)
        normalizedRating = Normalizer.normalizeRating(feedback)

        QueryRunner.InsertUserPreferenceFromSlice(profileKey, sliceIdList,
                                                  normalizedRating)

    writer.PrintAndWrite("Slice Feedback done", False)
    writer.PrintAndWrite("")
Пример #11
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
Пример #12
0
def CreateCCRelationAudioFileForEvaluation(ccID, filename=""):
    print("exporting clip-clip relation audio track")

    result = QueryRunner.getClipsFromClipClipLinkId(ccID)

    clip1 = result[0]
    clip2 = result[1]

    audioclip = AudioMerger.chainClips(clipId1=clip1, clipId2=clip2)
    if audioclip is None:
        return False

    print("audioclip: {0}".format(audioclip))

    nameofFile = "ccrel" + str(filename)
    filename = Util.GeneratePathAndFileNameForAudiofile(filename=nameofFile)
    exportSuccess = AudioMerger.exportAudio(audio=audioclip, filename=filename)

    print("export success: {0}".format(exportSuccess))
    print()
    return True
Пример #13
0
    def _setValidKeys(self, key):
        self.key = str(key)

        if key is not "None":
            self.keyFifth = QueryRunner.getFifthFromKey(key)
Пример #14
0
	def __init__(self, writer):
		self.engine = None
		self.sliceStructs = QueryRunner.getAllSliceStructures()
		self.generatedSlices = {}
		self.writer = writer
Пример #15
0
 def testGetFifth(self):
     key = "A"
     answer = "E"
     result = QueryRunner.getFifthFromKey(key)
     self.assertEqual(answer, result)
Пример #16
0
def _GetListOfStructuresFromDb(inputStr):
	return QueryRunner.getSongStructureList(inputStr)
Пример #17
0
def GetNumOfRandomFromClipRelations(profileKey,
                                    clipclipRelation,
                                    writer,
                                    numRandom=3):
    writer.PrintAndWrite("", False)
    writer.PrintAndWrite("** CLIP CLIP RELATION FEEDBACK ** ", False)

    writer.PrintAndWrite(
        "* getting ratings for {0} number of clips".format(numRandom))

    writer.PrintAndWrite("* getting not rated")
    notRatedList = QueryRunner.GetAllClipClipRelationsThatUserHasNotRated(
        userid=profileKey, relevantIdList=clipclipRelation, writer=writer)

    notRatedListLength = len(notRatedList)
    if notRatedListLength is 0:
        writer.PrintAndWrite("user has rated every item", False)
        writer.PrintAndWrite("Clip-clip realtion aborted", False)
        writer.PrintAndWrite()
        return False

    seenRelationsIndexes = []

    for index in range(0, numRandom):

        randomCCRelIndex = randint(0, notRatedListLength - 1)
        randomChoice = notRatedList[randomCCRelIndex]

        while randomChoice in seenRelationsIndexes:
            randomCCRelIndex = randint(0, notRatedListLength - 1)
            randomChoice = notRatedList[randomCCRelIndex]

        seenRelationsIndexes.append(randomChoice)

        success1 = FeedbackFileCreator.CreateCCRelationAudioFileForEvaluation(
            ccID=randomChoice, filename=randomChoice)

        if not success1:
            writer.PrintAndWrite(
                "something went wrong with creating the audio file for evaluation",
                False)
            continue

        writer.PrintAndWrite("", False)
        writer.PrintAndWrite("Clip-clip id: " + str(randomChoice), False)

        writer.PrintAndWrite(
            "Listen to the clips and come back. I'll be waiting :) ")

        feedback = GetFeedback(writer)
        normalizedFeedback = Normalizer.normalizeRating(feedback)

        success2 = QueryRunner.InsertUserPreferenceFromCCid(
            userId=profileKey,
            clipclipID=randomChoice,
            rating=normalizedFeedback)

        if success2 is False:
            print("something went wrong with inserting user preference")
            break

    writer.PrintAndWrite("Clip-clip Relation feedback is done", False)
    writer.PrintAndWrite("", False)
Пример #18
0
 def testGetFifthWrongInput(self):
     key = "W"
     answer = "None"
     result = QueryRunner.getFifthFromKey(key)
     self.assertEqual(answer, result)
Пример #19
0
 def _getAllTracks(self, bpm, key, instrumentID):
     songList = QueryRunner.getSongsWithBPMKeyAndInstrumentId(
         bpm, key, instrumentID)
     return songList