Skip to content

Commit

Permalink
feat: add option to ignore TCU when collecting adm
Browse files Browse the repository at this point in the history
  • Loading branch information
agelito committed Aug 8, 2023
1 parent 3a1538d commit 6ae4fdd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ DISCORD_APP_ID=ABCD1234
DISCORD_CHANNEL=adm
DISCORD_GUILD_ID=guild-id
ALLIANCE_ID=00000000
ALLIANCE_IGNORE_TCU=True
DB_SERVICE=mysql
DB_CONNECTION_STRING=root:root@127.0.0.1:3600/pydisadm
DB_KEEP_ADM_DAYS=7
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Configuration is done using environment variables or `dotenv`. See `.env.example
- `DISCORD_GUILD_ID` - the discord server bot should be part of
- `DISCORD_APP_ID` - the bot application ID
- `ALLIANCE_ID` - the alliance ID for collecting ADM values, only systems owned by this alliance will be collected.
- `ALLIANCE_IGNORE_TCU` - set to any value to ignore TCU's when collecting ADM values
- `DB_SERVICE` - which database to use, can be: sqlite or mysql
- `DB_CONNECTION_STRING` - the connection string
- `DB_KEEP_ADM_DAYS` - how many days adm history should be kept in database (default 7).
Expand Down
4 changes: 3 additions & 1 deletion pydisadm/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def __init__(self):
)

self.alliance = {
'id': os.getenv('ALLIANCE_ID')
'id': os.getenv('ALLIANCE_ID'),
'ignore_tcu': os.getenv('ALLIANCE_IGNORE_TCU')
}

keep_adm_days = self.database['keep_adm_days']
Expand Down Expand Up @@ -61,6 +62,7 @@ def pretty_print(self):
f'discord_app_id={self.discord["app_id"]}, ' +
f'discord_guild_id={self.discord["guild_id"]}, ' +
f'alliance_id={self.alliance["id"]}, ' +
f'alliance_ignore_tcu={self.alliance["ignore_tcu"]}, ' +
f'db_keep_adm_days={self.database["keep_adm_days"]}, ' +
f'db_service={self.database["service"]}, ' +
f'db_connection_string={self.database["connection_string"]})')
Expand Down
12 changes: 8 additions & 4 deletions pydisadm/controller/adm_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ def create_system_adm(self, system, adm):

return system_adm

def get_alliance_structures(self, structures, alliance_id):
def get_alliance_structures(self, structures, alliance_id, ignore_tcu):

Check warning on line 130 in pydisadm/controller/adm_controller.py

View check run for this annotation

Codecov / codecov/patch

pydisadm/controller/adm_controller.py#L130

Added line #L130 was not covered by tests
"""Retrieve a list of alliance sovreignty structures"""
structure_data = pd.DataFrame.from_dict(structures)

if ignore_tcu:
structure_data = structure_data[structure_data['structure_type_id'] != 32226]

Check warning on line 135 in pydisadm/controller/adm_controller.py

View check run for this annotation

Codecov / codecov/patch

pydisadm/controller/adm_controller.py#L134-L135

Added lines #L134 - L135 were not covered by tests

drop_columns = [
'structure_id',
'structure_type_id',
Expand Down Expand Up @@ -173,10 +176,10 @@ def update_system_adm_from_index(self,

return (True, insert_systems['adm'][0])

def get_system_adms(self, alliance_id):
def get_system_adms(self, alliance_id, ignore_tcu):

Check warning on line 179 in pydisadm/controller/adm_controller.py

View check run for this annotation

Codecov / codecov/patch

pydisadm/controller/adm_controller.py#L179

Added line #L179 was not covered by tests
"""Retrieve ADM for systems controlled by alliance"""
structures = sovereignty_structures()
system_adms = self.get_alliance_structures(structures, alliance_id)
system_adms = self.get_alliance_structures(structures, alliance_id, ignore_tcu)

Check warning on line 182 in pydisadm/controller/adm_controller.py

View check run for this annotation

Codecov / codecov/patch

pydisadm/controller/adm_controller.py#L182

Added line #L182 was not covered by tests

system_adms.drop_duplicates(inplace=True)

Expand All @@ -201,7 +204,8 @@ def get_recommended_system(self):
def update_adm_data(self):
"""Update ADM data"""
alliance_id = self.configuration.alliance['id']
system_adms = self.get_system_adms(alliance_id)
ignore_tcu = self.configuration.alliance['ignore_tcu']
system_adms = self.get_system_adms(alliance_id, ignore_tcu)

Check warning on line 208 in pydisadm/controller/adm_controller.py

View check run for this annotation

Codecov / codecov/patch

pydisadm/controller/adm_controller.py#L206-L208

Added lines #L206 - L208 were not covered by tests

self.database.insert_systems(system_adms)

Expand Down

0 comments on commit 6ae4fdd

Please sign in to comment.