Skip to content

Commit

Permalink
Add unanchoring and profile to Structure()
Browse files Browse the repository at this point in the history
  • Loading branch information
eve-n0rman committed Dec 28, 2020
1 parent 35ab082 commit a16c634
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 4 additions & 1 deletion structure-audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
'state',
'fuel_expires',
'fuel_rate',
'needs_fuel',
'jump_fuel',
'has_core'
'has_core',
'unanchoring',
'profile_id'
]
writer = csv.writer(sys.stdout)
writer.writerow(columns)
Expand Down
16 changes: 14 additions & 2 deletions structurebot/citadels.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Structure(object):
def __init__(self, structure_id, corporation_id=None, type_id=None, type_name=None,
system_id=None, services=None, fuel_expires=None,
accessible=None, name=None, state=None, state_timer_end=None,
detonation=None, fuel=[], fitting=Fitting()):
detonation=None, unanchors_at=None, profile_id=None,
fuel=[], fitting=Fitting()):
super(Structure, self).__init__()
self.structure_id = structure_id
self.corporation_id = corporation_id
Expand All @@ -29,6 +30,8 @@ def __init__(self, structure_id, corporation_id=None, type_id=None, type_name=No
self.state = state
self.state_timer_end = getattr(state_timer_end, 'v', None)
self.detonation = getattr(detonation, 'v', None)
self.unanchors_at = getattr(unanchors_at, 'v', None)
self.profile_id = profile_id
self.fitting = fitting
self._fuel_rate = 0
# Grab structure name
Expand Down Expand Up @@ -113,6 +116,8 @@ def needs_ozone(self):
def needs_fuel(self):
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
if self.fuel_expires and (self.fuel_expires - now < CONFIG['TOO_SOON']):
if self.unanchoring and self.unanchors_at < self.fuel_expires:
return False
return True
return False

Expand All @@ -138,6 +143,12 @@ def has_core(self):
return True
return False

@property
def unanchoring(self):
if self.unanchors_at:
return True
return False

@classmethod
def from_corporation(cls, corporation_name, assets=None):
structure_list = []
Expand All @@ -154,7 +165,8 @@ def from_corporation(cls, corporation_name, assets=None):
detonations = {d['structure_id']: d['chunk_arrival_time']
for d in detonations}
structure_keys = ['structure_id', 'corporation_id', 'system_id', 'type_id',
'services', 'fuel_expires', 'state', 'state_timer_end']
'services', 'fuel_expires', 'state', 'state_timer_end',
'unanchors_at', 'profile_id']
for s in structures:
sid = s['structure_id']
kwargs = {k: v for k, v in s.items() if k in structure_keys}
Expand Down
23 changes: 22 additions & 1 deletion tests/test_structures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import unittest
import doctest
import datetime as dt
import pytz
from pyswagger.primitives import Datetime
from structurebot import citadels
from structurebot import assets
from structurebot.config import CONFIG
Expand All @@ -26,14 +29,25 @@ def setUpClass(cls):
manufacturing_type = assets.Type.from_name('Standup Manufacturing Plant I')
research_type = assets.Type.from_name('Standup Research Lab I')
quantum_core = assets.Type.from_name('Raitaru Upwell Quantum Core')
fuel_expires = Datetime()
now = dt.datetime.utcnow().replace(tzinfo=pytz.utc)
fuel_expires.apply_with(None, now + dt.timedelta(days=3), None)
raitaru_fitting = assets.Fitting(ServiceSlot=[manufacturing_type,
research_type],
QuantumCoreRoom=[quantum_core])
cls.raitaru = citadels.Structure(1, type_id=raitaru_type.type_id,
type_name=raitaru_type.name,
fitting=raitaru_fitting)
fitting=raitaru_fitting,
fuel_expires=fuel_expires)
cls.unfit_raitaru = citadels.Structure(2, type_id=raitaru_type.type_id,
type_name=raitaru_type.name)
unanchors_at = Datetime()
unanchors_at.apply_with(None, now + dt.timedelta(days=2), None)
cls.unanchoring_raitaru = citadels.Structure(1, type_id=raitaru_type.type_id,
type_name=raitaru_type.name,
fitting=raitaru_fitting,
fuel_expires=fuel_expires,
unanchors_at=unanchors_at)

def test_fitting(self):
self.assertTrue(self.raitaru.fitting)
Expand All @@ -43,9 +57,16 @@ def test_fuel(self):
self.assertEqual(self.raitaru.fuel_rate, 18)
# Do twice to test caching
self.assertEqual(self.raitaru.fuel_rate, 18)
self.assertTrue(self.raitaru.needs_fuel)
# Test unfit structure
self.assertEqual(self.unfit_raitaru.fuel_rate, 0)
self.assertFalse(self.unfit_raitaru.needs_fuel)
# Test unanchoring with enough fuel
self.assertFalse(self.unanchoring_raitaru.needs_fuel)

def test_unanchoring(self):
self.assertTrue(self.unanchoring_raitaru.unanchoring)
self.assertFalse(self.raitaru.unanchoring)

def test_core(self):
self.assertTrue(self.raitaru.has_core)

0 comments on commit a16c634

Please sign in to comment.