def computePathsForChordPhrase(graph, chordPhrase): if len(chordPhrase) == 0: return None path = shortestPath(graph, chordCompare, graph[-1][0], chordPhrase[0]) paths = [] #print 'finding path for ' + str(chordPhrase) for c in chordPhrase[1:]: path = shortestPath(graph, chordCompare, path[-1], c) paths.append(path) #print 'path found is ' + str(paths) return paths
def GraphPath(request, mode_1, major_interval_1, minor_interval_1, name_1, mode_2, major_interval_2, minor_interval_2, name_2, x1, y1, x2, y2, shortcut = ""): [UTT1, UTT2] = createUTTStrings(mode_1, major_interval_1, minor_interval_1, name_1, mode_2, major_interval_2, minor_interval_2, name_2) startChord = chord.Chord([0,4,7]) uttS,uttT,dGraph = createUTTSpaceFromStringsAndStartChord(UTT1, UTT2, startChord) print "shortcut is " + str(shortcut) if (shortcut != None): addShortcutFromUrl(dGraph, shortcut) #print "finding path from chord '" + dGraph[int(x1)][int(y1)].chordName + "' to '" + dGraph[int(x2)][int(y2)].chordName + "'" #print "finding path from chord '" + chordToString(dGraph[int(x1)][int(y1)].chord) + "' to '" + chordToString(dGraph[int(x2)][int(y2)].chord) + "'" shortPath = shortestPath(dGraph, chordCompare, dGraph[int(x1)][int(y1)], dGraph[int(x2)][int(y2)].chord) distTransTuple = getDistancesAndTransformationsFromPath(dGraph, shortPath) #print [chordToString(i.chord) + ':' for i in shortPath] #the transformations returned from getDistanceAndTransformationFromPath are comma-delimited #let's make them bar delimited so we get consistency. print 'before replacing commas: ' + distTransTuple[1] barDelimTrans = distTransTuple[1].replace(",", "|") print 'after replacing commas: ' + barDelimTrans context = {'shortestPath': shortPath, 'distance': distTransTuple[0], 'transformations': barDelimTrans} #print nodeGraph2DToString(dGraph) #for nodeX in dGraph: # for nodeY in nodeX: # print nodeY.chordName return render(request, 'UTTs/path.html', context)#UTT1 + ',' + UTT2