Ejemplo n.º 1
0
def organize_assets_by_location(character, asset_list):
    asset_ids = set(entry['item_id'] for entry in asset_list)
    asset_dict = {entry['item_id']: entry for entry in asset_list}
    location_set = set(entry['location_id'] for entry in asset_list)
    location_data_dict = {id: {'items': {}} for id in location_set}
    for entry in asset_list:
        location_data_dict[entry['location_id']]['items'][
            entry['item_id']] = entry
    for item_id, entry in asset_dict.items():
        if item_id in location_data_dict:
            entry['items'] = location_data_dict[item_id]['items']

    location_id_list = list(
        set(location_data_dict.keys()).difference(asset_ids))
    location_model_dict = get_location_multi(character, location_id_list)

    systems_dict = {}
    for location_id in location_model_dict:
        location = location_model_dict[location_id]
        location_data_dict[location_id]['name'] = location.name
        if isinstance(location, System):
            system = location
        elif location.system_id is not None:
            system = System.get(location.system_id)
        else:
            system = DummySystem
        systems_dict[system.id] = systems_dict.get(system.id, (system, []))
        systems_dict[system.id][1].append(location_id)

    return_dict = {}
    for system, location_list in systems_dict.values():
        if system.region_id is not None:
            region = Region.get(system.region_id)
        else:
            region = DummyRegion
        if region.id not in return_dict:
            return_dict[region.id] = {
                'redlisted': [],
                'name': region.name,
                'items': {},
                'id': region.id,
            }
            if region.is_redlisted:
                return_dict[region.id]['redlisted'].append('name')
        return_dict[region.id]['items'][system.id] = {
            'redlisted': [],
            'name': system.name,
            'id': system.id,
            'items':
            {id: location_data_dict[id]
             for id in systems_dict[system.id][1]},
        }
        if system.is_redlisted:
            return_dict[region.id]['items'][system.id]['redlisted'].append(
                'name')
    return return_dict
Ejemplo n.º 2
0
def process_mining(mining_data):
    return_list = []
    for entry in mining_data:
        redlisted = []
        type = Type.get(entry['type_id'])
        system = System.get(entry['solar_system_id'])
        if system.is_redlisted:
            redlisted.append('system_name')
        return_list.append({
            'date': entry['date'],
            'quantity': entry['quantity'],
            'system_id': entry['solar_system_id'],
            'system_name': system.name,
            'type_id': entry['type_id'],
            'type_name': type.name,
            'value': entry['quantity'] * type.price,
            'redlisted': redlisted,
        })
    return {'info': return_list}
Ejemplo n.º 3
0
 def helper_test_assets_success(self, result):
     for region_id, region_data in result.items():
         if region_id > 0:
             region = Region.get(region_id)
             self.assertEqual(region_data['name'], region.name)
         self.assertIsInstance(region_data['items'], dict)
         for system_id, system_data in region_data['items'].items():
             if system_id > 0:
                 system = System.get(system_id)
                 self.assertIsInstance(system_data, dict)
                 self.assertEqual(system_data['name'], system.name)
             self.assertIsInstance(system_data['items'], dict)
             for structure_id, structure_data in system_data['items'].items(
             ):
                 self.assertIsInstance(structure_data, dict)
                 self.assertIsInstance(structure_data['name'], str)
                 self.assertIsInstance(structure_data['items'], dict)
                 for identifier, data in structure_data['items'].items():
                     self.assertIsInstance(identifier, int)
                     self.helper_process_asset_item(data)