def _trained(self, code, marine, per='FY'): code = code.upper() code_dtg = marine.code_dtg(code) #set training event period period = self._period[per] if code in self._cy_events: period = self._period['CY'] #P* will select the appropriate NLAMB code to check based on rank if code == 'P*': nlamb = {'JR' : 'PW', 'NCO' : 'PS', 'SNCO' : 'PU', 'OFFICER' : 'PV'} return self._trained(nlamb[marine.rank_group()], marine) #D3 (DADT Brief) one time brief if code == 'D3' and marine.code_dtg(code) != 0: return True #return training status if it isn't handled by the above if type(code_dtg) is dt.date: return code_dtg >= period else: return False
def weekly_report(self, roster, filter=None, delim=',', describe=False): scope = self._select(roster, filter) #btry = [] #shouldn't need this btry_counts = {} nco_count = 0 #generate list and strength of each btry in scope for marine in scope: if marine.rank_group() == 'NCO': nco_count += 1 if marine.btry not in btry_counts: #btry.append(marine.btry) btry_counts[marine.btry] = 1 else: btry_counts[marine.btry] += 1 print btry_counts out = 'Filter ({filters}){nl}Code{dl}Description{dl}{btrys}{dl}Bn{dl}Bn%{nl}'.format( dl=delim, filters=filter.upper(), btrys=delim.join(btry_counts.iterkeys()), nl=self._eol) for code in self._weekly_codes: if code == 'SB': bn_count = nco_count else: bn_count = sum(btry_counts.itervalues()) out += code + delim if describe: out += self._desc[code] + delim trained_count = 0 for btry in btry_counts.iterkeys(): btry_trained = len(self.select_trained(code, scope, 'btry = ' + btry)) trained_count += btry_trained out += str(btry_trained) + delim try: pct = float(trained_count) / bn_count * 100 except ZeroDivisionError: pct = 0.0 out += '{0}/{2}{dl}{1:.1f}%{dl}{nl}'.format(trained_count, pct, bn_count, dl=delim, nl=self._eol) return out