Exemplo n.º 1
0
def format(data):
    """Takes a list of MetricResults."""
    # Distinct values in data for forest plot variables:
    forestcombinations = util.combinations([util.unique(x, data) for x in config.fgraphs])
    forestcombinations = [dict(zip(config.fgraphs, x)) for x in forestcombinations]
    forestcombinations = filter(lambda x: x["benchmark"] in config.forests, forestcombinations)
    # Distinct values in data for bar chart variables:
    barcombinations = util.combinations([util.unique(x, data) for x in config.graphs])
    barcombinations = [dict(zip(config.graphs, x)) for x in barcombinations]
    barcombinations = filter(lambda x: not x["benchmark"] in config.forests, barcombinations)
    # Filter out omitted configurations.
    allcombinations = forestcombinations + barcombinations
    for omit in config.omit:
        sieve = lambda x: not util.all([x[y] == omit[y] for y in omit.keys() if x.has_key(y)])
        allcombinations = filter(sieve, allcombinations)
    # Create the graph objects.
    figures = []
    for configuration in allcombinations:
        if configuration in forestcombinations:
            graphtype = ForestPlot
        else:
            graphtype = BarChart
        sorteddata = graphtype.sortdata(data, configuration)
        if sorteddata:
            graph = graphtype(sorteddata)
        else:
            continue
        graph.create()
        figures.append(graph)
    return figures
Exemplo n.º 2
0
def format(data):
    """Takes a list of MetricResults."""
    # Distinct values in data for forest plot variables:
    forestcombinations = util.combinations(
        [util.unique(x, data) for x in config.fgraphs])
    forestcombinations = [
        dict(zip(config.fgraphs, x)) for x in forestcombinations
    ]
    forestcombinations = filter(lambda x: x["benchmark"] in config.forests,
                                forestcombinations)
    # Distinct values in data for bar chart variables:
    barcombinations = util.combinations(
        [util.unique(x, data) for x in config.graphs])
    barcombinations = [dict(zip(config.graphs, x)) for x in barcombinations]
    barcombinations = filter(lambda x: not x["benchmark"] in config.forests,
                             barcombinations)
    # Filter out omitted configurations.
    allcombinations = forestcombinations + barcombinations
    for omit in config.omit:
        sieve = lambda x: not util.all(
            [x[y] == omit[y] for y in omit.keys() if x.has_key(y)])
        allcombinations = filter(sieve, allcombinations)
    # Create the graph objects.
    figures = []
    for configuration in allcombinations:
        if configuration in forestcombinations:
            graphtype = ForestPlot
        else:
            graphtype = BarChart
        sorteddata = graphtype.sortdata(data, configuration)
        if sorteddata: graph = graphtype(sorteddata)
        else: continue
        graph.create()
        figures.append(graph)
    return figures
Exemplo n.º 3
0
def generate_track_name_possibilities(file, fileid, possible_releases):
    """Return all track ids matching the tracks.

	Args:
		fname: The file containing the track in question.
		track: A list of tracks to match against.
		possible_releases: Dictionary containing releases under consideration.
	
	Yields:
		All releated track_ids. Looks at all track names in the releases under
		consideration and case insensitively compares the tracks, returning any
		matches.
	"""
    ftrackname = file.getMDTrackTitle()
    for (rid, v) in possible_releases.items():
        release = lookups.get_release_by_releaseid(rid)
        for trackind in range(len(release.tracks)):
            rtrackname = release.tracks[trackind].title

            # Don't bother if we've already found this track!
            if trackind + 1 in v:
                continue

            if any(util.combinations(util.comp_name, rtrackname, ftrackname)):
                print "Using text based comparison for track", trackind + 1, ` rtrackname `, "(", repr(
                    ftrackname), ")"
                yield lookups.get_track_by_id(release.tracks[trackind].id)
Exemplo n.º 4
0
def generate_from_metadata(file, num_tracks):
	"""Return track id's by looking up the name on music brainz

	Args:
		fname: The file containing the track in question.
	
	Yields:
		A set of track_id, by querying based on id3 tags
	"""
	album = file.getMDAlbumTitle()
	title = file.getMDTrackTitle()
	artist = file.getMDTrackArtist()
	if album is None or title is None or artist is None:
		return # Can't get metadata
	
	util.update_progress("Searching albums by text lookup: "+`album`+" "+`artist`)
	for i in flatten(util.combinations(lookups.get_releases_by_cdtext,album, artist, num_tracks)):
		release = lookups.get_release_by_releaseid(i.release.id)
		util.update_progress("Trying "+release.title+" by text lookup")
		for trackind in range(len(release.tracks)):
			rtrackname = release.tracks[trackind].title
			if type(title) != type([]):
				title=[title]
			for t in title:
				if util.comp_name(rtrackname,t):
					print "Using album based text comparison for",artist.strip(),album.strip(),"'s track",trackind+1,`rtrackname`
					yield lookups.get_track_by_id(release.tracks[trackind].id)
				else:
					print "Failed text lookup for %s" % t
Exemplo n.º 5
0
def generate_from_metadata(file, num_tracks):
    """Return track id's by looking up the name on music brainz

	Args:
		fname: The file containing the track in question.
	
	Yields:
		A set of track_id, by querying based on id3 tags
	"""
    album = file.getMDAlbumTitle()
    title = file.getMDTrackTitle()
    artist = file.getMDTrackArtist()
    if album is None or title is None or artist is None:
        return  # Can't get metadata

    util.update_progress("Searching albums by text lookup: " + ` album ` +
                         " " + ` artist `)
    for i in flatten(
            util.combinations(lookups.get_releases_by_cdtext, album, artist,
                              num_tracks)):
        release = lookups.get_release_by_releaseid(i.release.id)
        util.update_progress("Trying " + release.title + " by text lookup")
        for trackind in range(len(release.tracks)):
            rtrackname = release.tracks[trackind].title
            if type(title) != type([]):
                title = [title]
            for t in title:
                if util.comp_name(rtrackname, t):
                    print "Using album based text comparison for", artist.strip(
                    ), album.strip(), "'s track", trackind + 1, ` rtrackname `
                    yield lookups.get_track_by_id(release.tracks[trackind].id)
                else:
                    print "Failed text lookup for %s" % t
def generate_track_name_possibilities(file, fileid, possible_releases):
	"""Return all track ids matching the tracks.

	Args:
		fname: The file containing the track in question.
		track: A list of tracks to match against.
		possible_releases: Dictionary containing releases under consideration.
	
	Yields:
		All releated track_ids. Looks at all track names in the releases under
		consideration and case insensitively compares the tracks, returning any
		matches.
	"""
	ftrackname = file.getMDTrackTitle()
	for (rid,v) in possible_releases.items():
		release = lookups.get_release_by_releaseid(rid)
		for trackind in range(len(release.tracks)):
			rtrackname = release.tracks[trackind].title

			# Don't bother if we've already found this track!
			if trackind+1 in v:
				continue

			if any(util.combinations(util.comp_name, rtrackname, ftrackname)):
				print "Using text based comparison for track",trackind+1,`rtrackname`,"(",repr(ftrackname),")"
				yield lookups.get_track_by_id(release.tracks[trackind].id)
Exemplo n.º 7
0
def keyword_combinations():
    keywords = parse_keywords(request.args["k"])
    combos = [list(combinations(keywords, i))
              for i in xrange(len(keywords), 1, -1)]
    ret = to_json([item for sublist in combos for item in sublist])
    return Response(response=ret,
                    status=200,
                    mimetype="application/json")
Exemplo n.º 8
0
    def get_command(self, description):
        """Return a command to execute given the current description."""
        # Return any queued commands
        if self.command_queue:
            command, inventory = self.command_queue.popleft()
            if inventory is not None:
                for item in inventory:
                    if item not in self.inv:
                        self.command_queue.appendleft((command, inventory))
                        self.inv.add(item)
                        return f"take {item}"
                for item in self.inv:
                    if item not in inventory:
                        self.command_queue.appendleft((command, inventory))
                        self.inv.remove(item)
                        return f"drop {item}"
            if isinstance(command, str):
                return command
            command(description)
            return self.get_command(description)
        # Get to the penultimate room
        if not self.at_end:
            explore_commands = list(self.explorer.get_commands(description))
            if explore_commands:
                self.queue_commands(explore_commands)
                return self.get_command(description)
            assert self.explorer.route is not None, "Could not find the exit"
            self.queue_commands(self.explorer.route)
            self.at_end = True
            return self.get_command(description)
        # Figure out which items are light
        if not self.light_items:
            for item in self.inv:
                self.queue_command(self.explorer.exit, inventory=[item])

                def check_was_light(description, item=item):
                    if "heavier" in description:
                        self.light_items.add(item)

                self.queue_command(check_was_light)
            return self.get_command(description)
        # Try all big enough combinations of light items
        for combination in sorted(combinations(self.light_items, min_size=2),
                                  key=len,
                                  reverse=True):
            self.queue_command(self.explorer.exit, inventory=combination)
        return self.get_command(description)
Exemplo n.º 9
0
import util

from config import logger

if __name__ == "__main__":
    if len(sys.argv) > 1:
        filename = sys.argv[1]
    else:
        filename = 'E.xlsx'

    table = datatools.get_data(filename)
    nrows = len(table)
    ncols = 0
    if nrows:
        ncols = len(table[0])
    if ncols:
        logger.info('Stats: rows: %s, columns: %s' % (nrows, ncols))
        comb_list = util.combinations(ncols)

#
# xl_workbook = xlrd.open_workbook(file_name)
# xl_sheet = xl_workbook.sheet_by_index(0)
# print('Open Excel workbook %s, sheetname: %s' % (file_name, xl_sheet.name))
#
# ncols = xl_sheet.ncols  # Number of columns
# nrows = xl_sheet.nrows
#
# print('Stats: \n\t rows: %s, columns: %s' % (nrows, ncols))
# #util.printsheet(xl_sheet)
# comb_list = util.getallcomb(ncols)
# # logic.q_inf(xl_sheet, 0, 0)