Ejemplo n.º 1
0
def extract_skills(opts, entries, initsave):
    crews = dict((c['id'], c['skill']) for c in initsave.crews
                 if c['type'] in opts.classes)
    students = set(
        [c['id'] for c in initsave.crews if c['status'] == 'Student'])
    days = sorted(hhist.group_by_date(entries))
    first = days[0][0].prev()
    results = {first: histogram(opts, skills_from_crews(crews, students))}
    for day, ents in days:
        for ent in ents:
            if ent['class'] != 'C':
                continue
            ent = ent['data']
            if ent['class'] not in opts.classes:
                continue
            cmid = ent['cmid']
            if ent['etyp'] == 'GE':
                students.add(cmid)
            elif ent['etyp'] == 'ST':
                students -= set([cmid])
            elif ent['etyp'] == 'SK':
                crews[cmid] = ent['data']['skill']
            elif ent['etyp'] in ['DE', 'PW']:
                del crews[cmid]
        results[day] = histogram(opts, skills_from_crews(crews, students))
    return results
Ejemplo n.º 2
0
def extract_targ_profit(save, before=None, after=None, typ=None):
    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]
    days = sorted(hhist.group_by_date(save.history))
    classes = [[tcls, tcls], [icls, icls]]
    for d in days:
        daily_profit(d,
                     bombers,
                     targets,
                     classes,
                     d[0] >= after if after else True,
                     d[0] >= before if before else False,
                     typ=typ)
    gains, losses = zip(*targets)[1:]
    lossvalue = [
        sum(l * hdata.Bombers[i]['cost'] for i, l in loss.items())
        for loss in losses
    ]
    return {
        i: {
            'gain': gains[i],
            'loss': losses[i],
            'cost': lossvalue[i]
        }
        for i in xrange(save.init.ntargets)
    }
Ejemplo n.º 3
0
def extract_ops(opts, entries, initsave):
    crews = dict(
        (c['id'],
         (c['tops'] if c['status'] == 'Crewman' else 0) + 30 * c['ft'])
        for c in initsave.crews if c['type'] in opts.classes)
    students = set(
        [c['id'] for c in initsave.crews if c['status'] == 'Student'])
    days = sorted(hhist.group_by_date(entries))
    first = days[0][0].prev()
    results = {first: histogram(opts, ops_from_crews(crews, students))}
    for day, ents in days:
        for ent in ents:
            if ent['class'] != 'C':
                continue
            ent = ent['data']
            if ent['class'] not in opts.classes:
                continue
            cmid = ent['cmid']
            if ent['etyp'] == 'GE':
                students.add(cmid)
            elif ent['etyp'] == 'ST':
                if cmid in students:
                    crews[cmid] = 0
                    students.remove(cmid)
            elif ent['etyp'] == 'OP':
                crews[cmid] += 1
            elif ent['etyp'] in ['DE', 'PW']:
                if cmid in crews: del crews[cmid]
        results[day] = histogram(opts, ops_from_crews(crews, students))
    return results
Ejemplo n.º 4
0
def extract_ops(opts, entries, initsave):
    crews = dict((c['id'], (c['tops'] if c['status'] == 'Crewman' else 0) + 30 * c['ft']) for c in initsave.crews if c['type'] in opts.classes)
    students = set([c['id'] for c in initsave.crews if c['status'] == 'Student'])
    days = sorted(hhist.group_by_date(entries))
    first = days[0][0].prev()
    results = {first: histogram(opts, ops_from_crews(crews, students))}
    for day, ents in days:
        for ent in ents:
            if ent['class'] != 'C':
                continue
            ent = ent['data']
            if ent['class'] not in opts.classes:
                continue
            cmid = ent['cmid']
            if ent['etyp'] == 'GE':
                students.add(cmid)
            elif ent['etyp'] == 'ST':
                if cmid in students:
                    crews[cmid] = 0
                    students.remove(cmid)
            elif ent['etyp'] == 'OP':
                crews[cmid] += 1
            elif ent['etyp'] in ['DE', 'PW']:
                if cmid in crews: del crews[cmid]
        results[day] = histogram(opts, ops_from_crews(crews, students))
    return results
Ejemplo n.º 5
0
def extract_totals(save, before=None, after=None):
	bombers = {b['id']:b['pff'] for b in save.init.bombers}
	days = sorted(hhist.group_by_date(save.history))
	totals = {}
	for d in days:
		total = daily_total(d, bombers, d[0]>=after if after else True, d[0]>=before if before else False)
		if total is not None:
			totals[d[0]] = total
	return totals
Ejemplo n.º 6
0
def extract_targ_profit(save, before=None, after=None, typ=None):
	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]
	days = sorted(hhist.group_by_date(save.history))
	classes = [[tcls,tcls], [icls,icls]]
	for d in days:
		daily_profit(d, bombers, targets, classes, d[0]>=after if after else True, d[0]>=before if before else False, typ=typ)
	gains, losses = zip(*targets)[1:]
	lossvalue = [sum(l*hdata.Bombers[i]['cost'] for i,l in loss.items()) for loss in losses]
	return {i: {'gain': gains[i], 'loss': losses[i], 'cost': lossvalue[i]} for i in xrange(save.init.ntargets)}
Ejemplo n.º 7
0
def extract_totals(save, before=None, after=None):
    bombers = {b['id']: b['pff'] for b in save.init.bombers}
    days = sorted(hhist.group_by_date(save.history))
    totals = {}
    for d in days:
        total = daily_total(d, bombers, d[0] >= after if after else True,
                            d[0] >= before if before else False)
        if total is not None:
            totals[d[0]] = total
    return totals
Ejemplo n.º 8
0
def count_losses(ents):
    days = sorted(hhist.group_by_date(ents))
    de = 0
    pw = 0
    ex = 0
    for d in days:
        for ent in d[1]:
            if ent['class'] != 'C': continue
            if ent['data']['etyp'] == 'DE':
                de += 1
            elif ent['data']['etyp'] == 'PW':
                pw += 1
            elif ent['data']['etyp'] == 'EX':
                ex += 1
    return (de, pw, ex)
Ejemplo n.º 9
0
def count_losses(ents):
	days = sorted(hhist.group_by_date(ents))
	de = 0
	pw = 0
	ex = 0
	for d in days:
		for ent in d[1]:
			if ent['class'] != 'C': continue
			if ent['data']['etyp'] == 'DE':
				de += 1
			elif ent['data']['etyp'] == 'PW':
				pw += 1
			elif ent['data']['etyp'] == 'EX':
				ex += 1
	return(de, pw, ex)
Ejemplo n.º 10
0
def count_losses(ents):
    days = sorted(hhist.group_by_date(ents))
    de = 0
    pw = 0
    ex = 0
    for d in days:
        for ent in d[1]:
            if ent["class"] != "C":
                continue
            if ent["data"]["etyp"] == "DE":
                de += 1
            elif ent["data"]["etyp"] == "PW":
                pw += 1
            elif ent["data"]["etyp"] == "EX":
                ex += 1
    return (de, pw, ex)
Ejemplo n.º 11
0
def extract_prodloss(ents):
	days = sorted(hhist.group_by_date(ents))
	bentry = [b.get('entry', hhist.date(0, 0, 0)) for b in hdata.Bombers]
	res = {}
	for d in days:
		row = [[0, 0] for b in hdata.Bombers]
		for ent in d[1]:
			if ent['class'] != 'A': continue
			if ent['data']['type']['fb'] != 'B': continue
			typ = ent['data']['type']['ti']
			if ent['data']['etyp'] == 'CT':
				if d[0].next() != bentry[typ]:
					row[typ][0] += 1
			elif ent['data']['etyp'] == 'CR':
				row[typ][1] -= 1
		res[d[0]] = row
	return(res)
Ejemplo n.º 12
0
def extract_prodloss(ents):
    days = sorted(hhist.group_by_date(ents))
    bentry = [b.get('entry', hhist.date(0, 0, 0)) for b in hdata.Bombers]
    res = {}
    for d in days:
        row = [[0, 0] for b in hdata.Bombers]
        for ent in d[1]:
            if ent['class'] != 'A': continue
            if ent['data']['type']['fb'] != 'B': continue
            typ = ent['data']['type']['ti']
            if ent['data']['etyp'] == 'CT':
                if d[0].next() != bentry[typ]:
                    row[typ][0] += 1
            elif ent['data']['etyp'] == 'CR':
                row[typ][1] -= 1
        res[d[0]] = row
    return (res)
Ejemplo n.º 13
0
def extract_profit(save, before=None, after=None, targ_id=None):
	bombers = {b['id']:[b['type'], 0, True, True] for b in save.init.bombers}
	targets = [[t['dmg'], 0, {i:0 for i in xrange(save.ntypes)}] for t in save.init.targets]
	classes = [[tcls,tcls], [icls,icls]]
	days = sorted(hhist.group_by_date(save.history))
	for d in days:
		daily_profit(d, bombers, targets, classes, d[0]>=after if after else True, d[0]>=before if before else False, targ_id=targ_id)
	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)}
	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]} for i in results}
	dead = {i: (len(deadresults[i]), sum(v[1] for v in deadresults[i].itervalues())) for i in results}
	if targ_id is None:
		return {i: {'full':full[i], 'fullr':full[i][1]/full[i][0] if full[i][0] else 0,
					'dead':dead[i], 'deadr':dead[i][1]/dead[i][0] if dead[i][0] else 0,
					'opti':full[i][1]/dead[i][0] if dead[i][0] else 0}
				for i in results
				if save.prio[i] is not None or full[i][0]}
	else:
		return {i: {'full':full[i], 'fullr':full[i][1]/full[i][0] if full[i][0] else 0,
					'dead':dead[i], 'deadr':dead[i][1]/targets[targ_id][2][i] if targets[targ_id][2][i] else 0,
					'opti':full[i][1]/targets[targ_id][2][i] if targets[targ_id][2][i] else 0}
				for i in results
				if save.prio[i] is not None or full[i][0]}
Ejemplo n.º 14
0
import matplotlib.pyplot as plt
import optparse

def parse_args(argv):
	x = optparse.OptionParser()
	x.add_option('--legend', action='store_true', default=True)
	x.add_option('--nolegend', dest='legend', action='store_false')
	opts, args = x.parse_args()
	return opts, args

if __name__ == '__main__':
	opts, args = parse_args(sys.argv)
	save = hsave.Save.parse(sys.stdin)
	data = []
	month = save.history[0]['date']
	history = sorted(hhist.group_by_date(save.history))
	i = 0
	while month <= save.history[-1]['date']:
		next = month.nextmonth()
		d = month.copy()
		types = {i:[0,0] for i in xrange(save.ntypes)}
		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])
			raiding = {}
Ejemplo n.º 15
0
def extract_profit(save, before=None, after=None, targ_id=None):
    bombers = {b['id']: [b['type'], 0, True, True] for b in save.init.bombers}
    targets = [[t['dmg'], 0, {i: 0
                              for i in xrange(save.ntypes)}]
               for t in save.init.targets]
    classes = [[tcls, tcls], [icls, icls]]
    days = sorted(hhist.group_by_date(save.history))
    for d in days:
        daily_profit(d,
                     bombers,
                     targets,
                     classes,
                     d[0] >= after if after else True,
                     d[0] >= before if before else False,
                     targ_id=targ_id)
    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)
    }
    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]}
        for i in results
    }
    dead = {
        i:
        (len(deadresults[i]), sum(v[1] for v in deadresults[i].itervalues()))
        for i in results
    }
    if targ_id is None:
        return {
            i: {
                'full': full[i],
                'fullr': full[i][1] / full[i][0] if full[i][0] else 0,
                'dead': dead[i],
                'deadr': dead[i][1] / dead[i][0] if dead[i][0] else 0,
                'opti': full[i][1] / dead[i][0] if dead[i][0] else 0
            }
            for i in results if save.prio[i] is not None or full[i][0]
        }
    else:
        return {
            i: {
                'full':
                full[i],
                'fullr':
                full[i][1] / full[i][0] if full[i][0] else 0,
                'dead':
                dead[i],
                'deadr':
                dead[i][1] /
                targets[targ_id][2][i] if targets[targ_id][2][i] else 0,
                'opti':
                full[i][1] /
                targets[targ_id][2][i] if targets[targ_id][2][i] else 0
            }
            for i in results if save.prio[i] is not None or full[i][0]
        }