def extract_all_ops(opts): entries = hhist.import_from_save(sys.stdin, crew_hist=True) init = entries.pop(0) assert init['class'] == 'I', init assert init['data']['event'] == 'INIT', init initfile = os.path.join('save', init['data']['filename']) initsave = hsave.Save.parse(open(initfile, 'r')) return extract_ops(opts, entries, initsave)
#!/usr/bin/python """prodloss - production and loss figures""" import sys import hhist, hdata 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) if __name__ == '__main__': entries = hhist.import_from_save(sys.stdin) prodloss = extract_prodloss(entries) for d in sorted(prodloss): print '%s: %s' % (d, prodloss[d])
#!/usr/bin/python2 """prodlossgraph - graph of production & losses Requires matplotlib, see http://matplotlib.org or search your package manager (Debian: apt-get install python-matplotlib) """ import sys import hhist, hdata, prodloss from extra_data import Bombers as extra import matplotlib.pyplot as plt if __name__ == '__main__': legend = '--nolegend' not in sys.argv entries = hhist.import_from_save(sys.stdin) data = prodloss.extract_prodloss(entries) fig = plt.figure() ax = fig.add_subplot(1,1,1) dates = [key.ordinal() for key in sorted(data)] total = [[sum(d[0] for d in data[key]), sum(d[1] for d in data[key])] for key in sorted(data)] top = max(zip(*total)[0]) bottom = min(zip(*total)[1]) plt.axis(ymax=max(top, -bottom), ymin=min(-top, bottom)) gt = plt.plot_date(dates, zip(*total)[0], fmt='k+-', tz=None, xdate=True, ydate=False, label='total', zorder=-2) gb = plt.plot_date(dates, zip(*total)[1], fmt='k+-', tz=None, xdate=True, ydate=False, label=None, zorder=-2) for bi,b in enumerate(hdata.Bombers.data): bprod = [data[key][bi][0] for key in sorted(data) if hdata.inservice(key, b)] bloss = [data[key][bi][1] for key in sorted(data) if hdata.inservice(key, b)] if not any(bprod+bloss): continue bdate = [key.ordinal() for key in sorted(data) if hdata.inservice(key, b)] gp = plt.plot_date(bdate, bprod, fmt='o-', mew=0, color=extra[b['name']]['colour'], tz=None, xdate=True, ydate=False, label=b['name'], zorder=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) if __name__ == "__main__": entries = hhist.import_from_save(sys.stdin, crew_hist=True) tombstone, pw, ex = count_losses(entries) if not tombstone: print "No losses have yet been incurred!" else: if tombstone == 1: print "1 airman has been Killed In Action" else: print "%d airmen have been Killed In Action" % tombstone print r""" ---- / \ / \ | RIP | | | |WE WILL |
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) if __name__ == '__main__': entries = hhist.import_from_save(sys.stdin, crew_hist=True) tombstone, pw, ex = count_losses(entries) if not tombstone: print 'No losses have yet been incurred!' else: if tombstone == 1: print '1 airman has been Killed In Action' else: print '%d airmen have been Killed In Action' % tombstone print r''' ---- / \ / \ | RIP | | | |WE WILL |