if opts.opti and opts.dead: x.error("Can't have --opti and --dead!") return opts, args if __name__ == '__main__': opts, args = parse_args(sys.argv) after = hhist.date.parse(opts.after) if opts.after else None save = hsave.Save.parse(sys.stdin) bombers = {b['id']:[b['type'], 0, True, True] for b in save.init.bombers} targets = [[t['dmg'], 0, dict((i,0) for i in xrange(save.ntypes))] for t in save.init.targets] classes = [[profit.tcls,profit.tcls], [profit.icls,profit.icls]] costs = {b['i']:b['cost'] for b in hdata.Bombers} days = sorted(hhist.group_by_date(save.history)) data = [] for d in days: profit.daily_profit(d, bombers, targets, classes, d[0]>=after if after else True, False) bombers = {i:bombers[i] for i in bombers if bombers[i][3]} results = {i: {k:v for k,v in bombers.iteritems() if v[0] == i} for i in xrange(save.ntypes)} results[None] = {k:v for k,v in bombers.iteritems()} full = {i: (len(results[i]), sum(costs[d[0]] for d in results[i].itervalues()), sum(v[1] for v in results[i].itervalues())) for i in results} deadresults = {i: {k:v for k,v in results[i].iteritems() if not v[2]} for i in results} dead = {i: (len(deadresults[i]), sum(costs[d[0]] for d in deadresults[i].itervalues()), sum(v[1] for v in deadresults[i].itervalues())) for i in results} if opts.opti: value = {i: full[i][2]/float(dead[i][1]) if dead[i][0] >= opts.min else None for i in results} elif opts.dead: value = {i: dead[i][2]/float(dead[i][1]) if dead[i][0] else None for i in results} else: value = {i: full[i][2]/float(full[i][1]) if full[i][0] else None for i in results} if after is None or d[0]>=after: data.append((d[0], value)) fig = plt.figure()
classes = [[profit.tcls, profit.tcls], [profit.icls, profit.icls]] history = sorted(hhist.group_by_date(save.history)) i = 0 while month <= save.history[-1]['date']: next = month.nextmonth() d = month.copy() while d < next: if i >= len(history): d = d.next() continue if history[i][0] > d: d = d.next() continue if history[i][0] < d: raise hhist.OutOfOrder(d, history[i][0]) profit.daily_profit(history[i], bombers, targets, classes, True, False) bombers = {i: bombers[i] for i in bombers if bombers[i][3]} d = d.next() i += 1 results = { i: {k: v for k, v in bombers.iteritems() if v[0] == i} for i in xrange(save.ntypes) } full = { i: (len(results[i]), sum(v[1] for v in results[i].itervalues())) for i in results } deadresults = { i: {k: v for k, v in results[i].iteritems() if not v[2]}