From: <gea...@us...> - 2009-05-27 21:20:03
|
Revision: 353 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=353&view=rev Author: gearmonkey Date: 2009-05-27 21:19:59 +0000 (Wed, 27 May 2009) Log Message: ----------- more auto-format detection added a new file with some common helper functions also a new executable that is designed to be the entry point for the backend of the radio player. At some point fairly soon the svn may need some restructuring. Modified Paths: -------------- graphRDF/branches/songsAsNodes/loadWeights.py Added Paths: ----------- graphRDF/branches/songsAsNodes/common.py graphRDF/branches/songsAsNodes/radioCore.py Added: graphRDF/branches/songsAsNodes/common.py =================================================================== --- graphRDF/branches/songsAsNodes/common.py (rev 0) +++ graphRDF/branches/songsAsNodes/common.py 2009-05-27 21:19:59 UTC (rev 353) @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +common.py + +Some common functions to speed access for song graphs + +Created by Benjamin Fields on 2009-05-18. +Copyright (c) 2009 Goldsmiths University of London. All rights reserved. +""" + +import sys +import os +import os.path +import igraph +import graphRDF + +def getTrackList(graph, nodeList): + trackList = [] + for vert in nodeList: + trackList.append(graph.vs[vert]['track']) + return trackList + +def avgDelta(graph, nodeList): + delta = 0 + for idx, node in enumerate(nodeList[1:]): + delta += igraph.EdgeSeq(graph, [nodeList[idx], node])[0]['audioWeight'] + return delta/(len(nodeList)-1) + +def deltaList(graph, nodeList): + deltaList = [] + for idx, node in enumerate(nodeList[1:]): + deltaList.append(igraph.EdgeSeq(graph, [nodeList[idx], node])[0]['audioWeight']) + return deltaList + + + +def main(): + pass + + +if __name__ == '__main__': + main() + Modified: graphRDF/branches/songsAsNodes/loadWeights.py =================================================================== --- graphRDF/branches/songsAsNodes/loadWeights.py 2009-05-27 21:16:28 UTC (rev 352) +++ graphRDF/branches/songsAsNodes/loadWeights.py 2009-05-27 21:19:59 UTC (rev 353) @@ -104,7 +104,7 @@ typoOutHandle.write(str(idx) + " : typo : " + line) typoOutHandle.flush() typos += 1 - print >> sys.stderr, str(err) + "\n" + str(typos) + " typos found." + print >> sys.stderr, str(Exception) + " : " + str(err) + "\n" + str(typos) + " typos found." continue foundWeight += 1 Added: graphRDF/branches/songsAsNodes/radioCore.py =================================================================== --- graphRDF/branches/songsAsNodes/radioCore.py (rev 0) +++ graphRDF/branches/songsAsNodes/radioCore.py 2009-05-27 21:19:59 UTC (rev 353) @@ -0,0 +1,130 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +radioCore.py + +This is the entry point for the backend of + +Created by Benjamin Fields on 2009-05-21. +Copyright (c) 2009 Goldsmiths University of London. All rights reserved. +""" + +import sys +import getopt +import igraph +import graphRDF +from common import * + + +help_message = ''' +Core utility end point to the automatic ong selection and aggregation toolkit, built around mypyspace's graphRDF project. + +modes available: + help print this message and exit + + makePlaylist create a playlist for MP3Broadcaster. Args as follows: + + >radioCore.py makePlaylist [options] graph.graphmlz srcNode destNode outfile.playlist + + graph.graphmlz -- the graph that will be used + --note this may change to a pickled igraph to speed load time.-- + srcNode -- where the playlist will start, specified as a filename that exists in graph.graphmlz + destNode -- where the playlist will end, specified as a filename that exists in graph.graphmlz + outfile.playlist -- the full path where the playlist will be written. + + destFinder given various circumstances determine all possible destination nodes for a +''' + +playlistheader = """*PLAY-LIST* +# +# Created by radioCore.py +# +""" + +class Usage(Exception): + def __init__(self, msg): + self.msg = msg + + +def main(argv=None): + verbose = False + weighted = True + if argv is None: + argv = sys.argv + try: + if len(argv) < 2: + raise Usage(help_message) + if argv[1] == 'help': + raise Usage(help_message) + elif argv[1] == 'makePlaylist': + if len(argv) < 6: + raise Usage(help_message) + mode = 'makePlaylist' + graphFile = argv[-4] + srcNode = argv[-3] + destNode = argv[-2] + outfile = argv[-1] + if len(argv) > 6: + generalOpts = argv[2:-4] + else: + generalOpts = [] + elif argv[1] == 'destFinder': + mode = 'destFinder' + + else: + raise Usage("Poor mode specification. Run 'radioCore.py help' for more detailed usage.") + try: + opts, args = getopt.getopt(generalOpts, "hvw", ["help", "vebose", "unweighted"]) + except getopt.error, msg: + raise Usage(msg) + + # option processing + for option, value in opts: + if option == ("-v", "--verbose"): + verbose = True + if option in ("-h", "--help"): + raise Usage(help_message) + if option in ("-w", "--unweighted"): + weighted = False + + except Usage, err: + print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg) + print >> sys.stderr, "\t for help use --help" + return 2 + songGraph = graphRDF.graph('media_seed_134901208') + if mode == 'makePlaylist': + try: + outHandle = open(outfile, 'w') + if os.path.splitext(graphFile)[1] in ['.pkl', '.pickle']: + songGraph.S = igraph.Graph.Load(graphFile, format='pickle') + elif os.path.splitext(graphFile)[1] in ['.mlz', '.graphmlz']: + songGraph.S = igraph.Graph.Load(graphFile, format='graphmlz') + else: + songGraph.S = igraph.Graph.Load(graphFile) + except Exception, err: + print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err) + print >> sys.stderr, "\t for help use --help" + return 12 + if weighted and (len(songGraph.S.es.select(audioWeight_lt=0)) > 0): + print "radioCore.py: makePlaylist: WARNING: attempting to use weights, but some of the weights are negative. This may cause in some odd results." + try: + srcIDX = songGraph.S.vs.select(track=srcNode)[0].index + destIDX = songGraph.S.vs.select(track=destNode)[0].index + except Exception, err: + print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err) + print >> sys.stderr, "\t source or destination track path poorly specified, unable to dereference." + return 13 + outHandle.write(playlistheader) + if weighted: + trackList = getTrackList(songGraph.S, songGraph.shortestPath(srcIDX, destIDX, graph='S', weight='audioWeight')) + else: + trackList = getTrackList(songGraph.S, songGraph.shortestPath(srcIDX, destIDX, graph='S', weight=None)) + + for track in trackList: + outHandle.write('"'+track +'" 5\n') + outHandle.close() + + + +if __name__ == "__main__": + sys.exit(main()) Property changes on: graphRDF/branches/songsAsNodes/radioCore.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |