Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/volume #62

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions structure-audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
'type_name',
'name',
'state',
'state_timer_end',
'unanchoring',
'fuel_expires',
'fuel_rate',
'needs_fuel',
'jump_fuel',
'needs_core',
'unanchoring',
'profile_id'
'profile_id',
'packaged_volume',
'system_name',
'constellation_name',
'region_name'
]
writer = csv.writer(sys.stdout)
writer.writerow(columns)
Expand Down
20 changes: 17 additions & 3 deletions structurebot/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(self, type_id, name, description, published, group_id,
group=None, market_group_id=None, radius=None, volume=None,
packaged_volume=None, icon_id=None, capacity=None,
portion_size=None, mass=None, graphic_id=None,
dogma_attributes=[], dogma_effects=[]):
dogma_attributes=[], dogma_effects=[], **kwargs):
super(BaseType, self).__init__()
self.type_id = type_id
self.name = name
Expand All @@ -196,7 +196,9 @@ def __init__(self, type_id, name, description, published, group_id,
self.mass = mass
self.graphic_id = graphic_id
self.dogma_attributes = dogma_attributes
self.attributes = {a['attribute_id']: a['value'] for a in dogma_attributes}
self.dogma_effects = dogma_effects
self.effects = {e['effect_id']: e['is_default'] for e in dogma_effects}

@classmethod
def from_id(cls, id):
Expand Down Expand Up @@ -379,11 +381,11 @@ class Fitting(object):

slots = ['Cargo', 'DroneBay', 'FighterBay', 'FighterTube', 'HiSlot',
'LoSlot', 'MedSlot', 'RigSlot', 'ServiceSlot', 'SubSystemSlot',
'QuantumCoreRoom']
'StructureFuel', 'QuantumCoreRoom']

def __init__(self, Cargo=[], DroneBay=[], FighterBay=[], FighterTube=[],
HiSlot=[], LoSlot=[], MedSlot=[], RigSlot=[], ServiceSlot=[],
SubSystemSlot=[], QuantumCoreRoom=[]):
SubSystemSlot=[], StructureFuel=[], QuantumCoreRoom=[]):
super(Fitting, self).__init__()
self.Cargo = Cargo
self.DroneBay = DroneBay
Expand All @@ -395,6 +397,7 @@ def __init__(self, Cargo=[], DroneBay=[], FighterBay=[], FighterTube=[],
self.RigSlot = RigSlot
self.ServiceSlot = ServiceSlot
self.SubSystemSlot = SubSystemSlot
self.StructureFuel = StructureFuel
self.QuantumCoreRoom = QuantumCoreRoom

@classmethod
Expand All @@ -406,6 +409,9 @@ def from_assets(cls, assets):
continue
for slot in Fitting.slots:
if flag.startswith(slot):
if flag.startswith('FighterTube'):
# Fighter tubes report squadrons, which consist of variable quantities
asset.quantity = int(asset.attributes.get(2215, 1))
fittings[slot].append(asset)
fit = True
return cls(**fittings)
Expand All @@ -417,6 +423,14 @@ def _name_count(asset):
name += ' ({})'.format(asset.quantity)
return name

@property
def packaged_volume(self):
volume = 0
for slot in self.slots:
for item in getattr(self, slot):
volume += item.packaged_volume * item.quantity
return volume

def _compare(self, other):
"""Generates a Counter of items in self minus items in other

Expand Down
10 changes: 10 additions & 0 deletions structurebot/citadels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .config import CONFIG
from .util import esi, esi_client, name_to_id, ids_to_names
from .assets import Fitting, Asset, Type
from .universe import System
import six


Expand All @@ -25,6 +26,11 @@ def __init__(self, structure_id, corporation_id=None, type_id=None, type_name=No
self.type = Type.from_id(type_id)
self.type_name = type_name or self.type.name
self.system_id = system_id
if self.system_id:
self.system = System.from_id(self.system_id)
self.system_name = self.system.name
self.constellation_name = self.system.constellation.name
self.region_name = self.system.constellation.region.name
self.fuel = fuel
self.fuel_expires = getattr(fuel_expires, 'v', None)
self.accessible = accessible
Expand Down Expand Up @@ -58,6 +64,10 @@ def __init__(self, structure_id, corporation_id=None, type_id=None, type_name=No
if service['state'] == 'offline':
self.offline_services.append(service.get('name'))

@property
def packaged_volume(self):
return self.type.packaged_volume + self.fitting.packaged_volume

@property
def fuel_rate(self):
if self._fuel_rate:
Expand Down
97 changes: 97 additions & 0 deletions structurebot/universe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from __future__ import absolute_import

from .util import esi, esi_client, name_to_id, HTTPError


class EsiLocation(object):
@classmethod
def from_id(cls, id):
"""Base utility class to pull ESI universe info by id

Args:
id (int): location ESI ID

Raises:
ValueError: ID must be an int
HTTPError: ESI failure

Returns:
cls: child class populated from ESI
"""
id_op = cls.id_op
id_arg = {cls.id_arg: id}
if not isinstance(id, int):
raise ValueError('ID must be an integer')
type_request = esi.op[id_op](**id_arg)
type_response = esi_client.request(type_request)
if type_response.status == 200:
return cls(**type_response.data)
else:
raise HTTPError(type_response.data['error'])

@classmethod
def from_name(cls, name):
"""Base utility class to pull ESI universe info by name

Args:
name (str): EVE universe name (region, constellation or system)

Returns:
cls: child class populated from ESI
"""
id = name_to_id(name, cls.name_arg)
return cls.from_id(id)


class Region(EsiLocation):
id_op = 'get_universe_regions_region_id'
id_arg = 'region_id'
name_arg = 'region'

def __init__(self, region_id, name, **kwargs):
"""EVE Region

Args:
region_id (int): EVE region id
name (str): EVE region name
"""
self.region_id = region_id
self.name = name


class Constellation(EsiLocation):
id_op = 'get_universe_constellations_constellation_id'
id_arg = 'constellation_id'
name_arg = 'constellation'

def __init__(self, constellation_id, region_id, name, **kwargs):
"""EVE Constellation

Args:
constellation_id (int): EVE constellation id
region_id (int): EVE region id
name (str): EVE constellation name
"""
self.constellation_id = constellation_id
self.region_id = region_id
self.region = Region.from_id(self.region_id)
self.name = name


class System(EsiLocation):
id_op = 'get_universe_systems_system_id'
id_arg = 'system_id'
name_arg = 'solar_system'

def __init__(self, system_id, constellation_id, name, **kwargs):
"""EVE System

Args:
system_id (int): EVE system id
constellation_id (int): EVE constellation id
name (str): EVE system name
"""
self.system_id = system_id
self.constellation_id = constellation_id
self.constellation = Constellation.from_id(self.constellation_id)
self.name = name
8 changes: 7 additions & 1 deletion tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ def test_fitting_greater_quantity(self):

def test_fitting_bad_compare(self):
with pytest.raises(NotImplementedError):
self.fittings[0] == 'not a fitting'
self.fittings[0] == 'not a fitting'

def test_fitting_volume(self):
self.assertEqual(self.fittings[0].packaged_volume, 4000)
self.assertEqual(self.fittings[1].packaged_volume, 8000)
self.assertEqual(self.fittings[2].packaged_volume, 6000)
self.assertEqual(self.fittings[3].packaged_volume, 8000)
2 changes: 1 addition & 1 deletion tests/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ def test_inaccessible(self):

def test_accessible(self):
bravestar = citadels.Structure(1032110505696, type_id=35834)
self.assertEqual(str(bravestar), 'GE-8JV - Mothership Bellicose (1032110505696) - Keepstar')
self.assertEqual(str(bravestar), 'GE-8JV - Mothership Bellicose -R (1032110505696) - Keepstar')
self.assertTrue(bravestar.accessible)
11 changes: 11 additions & 0 deletions tests/test_universe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import absolute_import
import unittest
from structurebot import universe


class TestUniverse(unittest.TestCase):
def test_system(self):
system = universe.System.from_name('GE-8JV')
self.assertEqual('GE-8JV', system.name)
self.assertEqual('9HXQ-G', system.constellation.name)
self.assertEqual('Catch', system.constellation.region.name)