示例#1
0
文件: costs.py 项目: megawidget/veu
    def print_stats_for_tag(self, tag):
        name, ideas = get_ideas_for_tag(tag)
        stats = self.stats_for_ideas(ideas)

        self.print_legend()
        print name, "ideas:"
        for slot, k, v, level, cost in stats["ideas"]:
            print IDEA_COSTS_FMT.format(slot, k, v, level, cost)
        print LINE
        print "Total: %.2f %s" % (stats["total"], self.get_flags(stats))
示例#2
0
文件: costs.py 项目: megawidget/veu
def main():
    import argparse
    p = argparse.ArgumentParser(
        description="Prints costs for a tag or idea cost stats if not specified."
    )
    p.add_argument('--dryrun', '-n', action='store_true', help="dry run")
    p.add_argument('--ideas', '-i', action='store_true', help="idea costs only")
    p.add_argument('--provinces', '-p', action='store_true', help="province costs only")
    p.add_argument('tag', nargs='?', help="tag or group name")
    options = p.parse_args()

    i = None
    if not options.provinces:
        i = Ideas()

    c = None
    if not options.ideas:
        c = Countries()

    if options.dryrun:
        return

    if options.tag != None:
        tag = options.tag.lower()
        if i:
            i.print_stats_for_tag(tag)
        if i and c:
            print DOUBLE_LINE, '\n'
        if c:
            c.print_stats_for_owner(tag)

    else:
        if not c:
            i.print_stats()
        elif not i:
            c.print_stats()
        else:
            totals = {}
            for owner in c.owners():
                ideas_stats = i.stats_for_ideas(get_ideas_for_tag(owner)[1])
                cost = c.stats_for_owner(owner)['total']
                cost += ideas_stats['total']
                flags = i.get_flags(ideas_stats)
                try:
                    totals[cost].append(owner + flags)
                except KeyError:
                    totals[cost] = [ owner + flags ]
            for key in sorted(totals.keys()):
                print key, ', '.join(totals[key])