def run(): if '-k' in sys.argv: idx = sys.argv.index('-k') kill = KillMail(int(sys.argv[idx + 1])) process(kill) return look_back_days = int(_config.get_option('look_back_days')) _log.info('Classifying killmails for the past %d days.' % look_back_days) start_time = datetime.now() - timedelta(look_back_days) for kill in KillMail.losses_after(start_time): process(kill)
def run(): if '-k' in sys.argv: idx = sys.argv.index('-k') kill = KillMail(int(sys.argv[idx+1])) process(kill) return look_back_days = int(_config.get_option('look_back_days')) _log.info('Consolidating payments for losses for the past %d days.' % look_back_days) outstanding_payments = { p.character_id: p for p in Payment.all_outstanding() } start_time = datetime.now() - timedelta(look_back_days) control = Control() for kill in KillMail.losses_after(start_time): cid = kill.victim.character_id if cid not in outstanding_payments: _log.info('Creating new payment for character %d.' % cid) p = Payment(control.next_payment_id) p.character_id = cid p.character_name = kill.victim.character_name p.corp_id = kill.victim.corporation_id p.corp_name = kill.victim.corporation_name p.payment_amount = 0 if process(kill, p): control.next_payment_id += 1 outstanding_payments[cid] = p control.save() else: process(kill, outstanding_payments[cid])
def run(): if '-k' in sys.argv: idx = sys.argv.index('-k') kill = KillMail(int(sys.argv[idx+1])) process(kill) return look_back_days = int(_config.get_option('look_back_days')) _log.info('Classifying killmails for the past %d days.' % look_back_days) start_time = datetime.now() - timedelta(look_back_days) for kill in KillMail.losses_after(start_time): process(kill)
def run(): if '-k' in sys.argv: idx = sys.argv.index('-k') kill = KillMail(int(sys.argv[idx + 1])) process(kill) return look_back_days = int(_config.get_option('look_back_days')) _log.info('Consolidating payments for losses for the past %d days.' % look_back_days) outstanding_payments = { p.character_id: p for p in Payment.all_outstanding() } start_time = datetime.now() - timedelta(look_back_days) control = Control() for kill in KillMail.losses_after(start_time): cid = kill.victim.character_id if cid not in outstanding_payments: _log.info('Creating new payment for character %d.' % cid) p = Payment(control.next_payment_id) p.character_id = cid p.character_name = kill.victim.character_name p.corp_id = kill.victim.corporation_id p.corp_name = kill.victim.corporation_name p.payment_amount = 0 if process(kill, p): control.next_payment_id += 1 outstanding_payments[cid] = p control.save() else: process(kill, outstanding_payments[cid]) _log.info('Checking for out of alliance / declining SRP.') alliance_id = int(_config.get_option('alliance_id')) for cid, payment in outstanding_payments.iteritems(): c = Character(cid) eveapi.update_character(c) corp = Corporation(c.corp_id) ignore = c.alliance_id != alliance_id or c.declined_srp or not corp.srp if ignore != payment.ignore: payment.ignore = ignore payment.save()
def get_killmail(kill): url = None if type(kill) is str: url = kill elif type(kill) is KillMail: url = kill.crest_url elif type(kill) is int: kill = KillMail(kill) url = kill.crest_url if url is None: return None data = web.fetch_url(url) return json.loads(data)
def run(): if '-k' in sys.argv: idx = sys.argv.index('-k') kill = KillMail(int(sys.argv[idx+1])) process(kill) return look_back_days = int(_config.get_option('look_back_days')) _log.info('Consolidating payments for losses for the past %d days.' % look_back_days) outstanding_payments = { p.character_id: p for p in Payment.all_outstanding() } start_time = datetime.now() - timedelta(look_back_days) control = Control() for kill in KillMail.losses_after(start_time): cid = kill.victim.character_id if cid not in outstanding_payments: _log.info('Creating new payment for character %d.' % cid) p = Payment(control.next_payment_id) p.character_id = cid p.character_name = kill.victim.character_name p.corp_id = kill.victim.corporation_id p.corp_name = kill.victim.corporation_name p.payment_amount = 0 if process(kill, p): control.next_payment_id += 1 outstanding_payments[cid] = p control.save() else: process(kill, outstanding_payments[cid]) _log.info('Checking for out of alliance / declining SRP.') alliance_id = int(_config.get_option('alliance_id')) for cid, payment in outstanding_payments.iteritems(): c = Character(cid) eveapi.update_character(c) corp = Corporation(c.corp_id) ignore = c.alliance_id != alliance_id or c.declined_srp or not corp.srp if ignore != payment.ignore: payment.ignore = ignore payment.save()
def convert_killmail(kill): km = KillMail() km.kill_id = kill['id'] _log.debug('Converting killmail %d.' % km.kill_id) km.kill_time = datetime.utcfromtimestamp(kill['time']) km.solar_system_id = kill['system_id'] solar_system = MapSolarSystem.by_id(km.solar_system_id) km.solar_system_name = solar_system.solarSystemName km.region_name = solar_system.region.regionName km.victim = convert_victim(kill['victim']) km.victim_id = km.victim.character_id or km.victim.corporation_id km.attackers = map(convert_attacker, kill['attackers'].values()) km.final_blow = filter(lambda a: a.final_blow, km.attackers) if km.final_blow is not None and type(km.final_blow) is list and len(km.final_blow) >= 1: km.final_blow = km.final_blow[0] km.items = map(convert_item, kill['items']) km.grouped_items = GroupedItems(km.items) km.loss_mail = km.victim.alliance_id == alliance_id ship_class = ShipClass(km.victim.ship_class) km.default_payment = 0 if ship_class.fixed_reimbursement > 0: km.default_payment = ship_class.fixed_reimbursement elif ship_class.market_reimbursement_multiplier > 0: price = market.get_default_price(km.victim.ship_type_id) km.default_payment = int(round(price * ship_class.market_reimbursement_multiplier, -6) / 1000000) km.srpable = km.loss_mail and km.victim.ship_class not in [ 'Capsule', 'Rookie Ship', 'Shuttle', 'Other' ] km.get_crest_hash() valuer.set_prices(km) return km
def get_new_kills(all_kills): _log.info('Filtering out kills that are already in the datastore.') ids = set(all_kills.keys()) old_ids = set(map((lambda k: k.kill_id), KillMail.load_multi(ids))) new_ids = ids.difference(old_ids) return [ all_kills[id] for id in new_ids ]
def convert_killmail(kill): km = KillMail() km.kill_id = int(kill['killID']) _log.debug('Converting killmail %d.' % km.kill_id) km.kill_time = datetime.strptime(kill['killTime'], '%Y-%m-%d %H:%M:%S') km.solar_system_id = int(kill['solarSystemID']) solar_system = MapSolarSystem.by_id(km.solar_system_id) km.solar_system_name = solar_system.solarSystemName km.region_name = solar_system.region.regionName km.victim = convert_victim(kill['victim']) km.victim_id = km.victim.character_id or km.victim.corporation_id km.attackers = map(convert_attacker, kill['attackers']) km.final_blow = filter(lambda a: a.final_blow, km.attackers) if type(km.final_blow) == list and len(km.final_blow) >= 1: km.final_blow = km.final_blow[0] km.items = map(convert_item, kill['items']) km.grouped_items = GroupedItems(km.items) km.loss_mail = km.victim.alliance_id == alliance_id ship_class = ShipClass(km.victim.ship_class) km.default_payment = 0 if ship_class.fixed_reimbursement > 0: km.default_payment = ship_class.fixed_reimbursement elif ship_class.market_reimbursement_multiplier > 0: price = market.get_default_price(km.victim.ship_type_id) km.default_payment = int( round(price * ship_class.market_reimbursement_multiplier, -6) / 1000000) km.srpable = km.loss_mail and km.victim.ship_class not in [ 'Capsule', 'Rookie Ship', 'Shuttle', 'Other' ] km.get_crest_hash() valuer.set_prices(km) return km
def get_new_kills(all_kills): _log.info('Filtering out kills that are already in the datastore.') ids = set([int(kill['killID']) for kill in all_kills if 'killID' in kill]) old_ids = set([k.kill_id for k in KillMail.load_multi(ids)]) new_ids = ids.difference(old_ids) return filter((lambda k: int(k['killID']) in new_ids), all_kills)
def get_new_kills(all_kills): _log.info('Filtering out kills that are already in the datastore.') ids = set(all_kills.keys()) old_ids = set(map((lambda k: k.kill_id), KillMail.load_multi(ids))) new_ids = ids.difference(old_ids) return [all_kills[id] for id in new_ids]
def get_losses(): look_back_days = int(_config.get_option('look_back_days')) _log.info('Getting losses for the last %d days.' % look_back_days) start_time = (datetime.now() - timedelta(look_back_days)) return KillMail.losses_after(start_time)
def import_kill(kill): kill = get_killmail(kill) km = KillMail(kill['killID']) _log.debug('Converting killmail %d.' % km.kill_id) km.kill_time = datetime.strptime(kill['killTime'], '%Y.%m.%d %H:%M:%S') km.solar_system_id = kill['solarSystem']['id'] km.solar_system_name = kill['solarSystem']['name'] solar_system = MapSolarSystem.by_id(km.solar_system_id) km.region_name = solar_system.region.regionName km.victim = convert_victim(kill['victim']) km.victim_id = km.victim.character_id or km.victim.corporation_id km.attackers = map(convert_attacker, kill['attackers']) km.final_blow = filter(lambda a: a.final_blow, km.attackers) if type(km.final_blow) == list and len(km.final_blow) >= 1: km.final_blow = km.final_blow[0] if 'items' in kill: km.items = map(convert_item, kill['items']) elif 'items' in kill['victim']: km.items = map(convert_item, kill['victim']['items']) km.grouped_items = GroupedItems(km.items) km.loss_mail = km.victim.alliance_id == alliance_id ship_class = ShipClass(km.victim.ship_class) if km.default_payment is None: km.default_payment = 0 if ship_class.fixed_reimbursement > 0: km.default_payment = ship_class.fixed_reimbursement elif ship_class.market_reimbursement_multiplier > 0: price = market.get_default_price(km.victim.ship_type_id) km.default_payment = int(round(price * ship_class.market_reimbursement_multiplier, -6) / 1000000) km.srpable = km.loss_mail and ship_class not in [ 'Capsule', 'Rookie Ship', 'Shuttle', 'Other' ] km.get_crest_hash() valuer.set_prices(km) km.save() return km