Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mauxion2 authored Jun 20, 2024
1 parent c103903 commit fc60aaf
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 33 deletions.
56 changes: 56 additions & 0 deletions src/data_progress/data_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@


import datetime
import os
# from typing import List
from typing import Optional
from sqlalchemy import Engine, create_engine, Executable, Result, MetaData # , ForeignKey
Expand Down Expand Up @@ -139,6 +141,18 @@ class DockedFleet(Base):
market_id: Mapped[int] = mapped_column(default='0')


class BioShell(Base):
__tablename__ = 'bio_shell'

id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
system_id: Mapped[int] = mapped_column(default='0')
planet_id: Mapped[int] = mapped_column(default='0')
bio_codex: Mapped[str] = mapped_column(default='')
bio_name: Mapped[str] = mapped_column(default='')
bio_cost: Mapped[int] = mapped_column(default='0')
bio_time: Mapped[str] = mapped_column(default='')


def run_statement(engine: Engine, statement: Executable) -> Result:
"""
Execute a SQLAlchemy statement. Creates a fresh connection, commits, and closes the connection.
Expand Down Expand Up @@ -345,6 +359,21 @@ def check_system(system_address: int, system_name: str) -> bool:
return system_check


def name_system(system_id: int) -> str:
data: SystemList = this.sql_session_factory.scalar(select(SystemList).where(SystemList.system_id == system_id))
if not data:
return 'None'
return data.system_name


def name_planet(system_id: int, planet_id: int) -> str:
data: PlanetBioSAA = this.sql_session_factory.scalar(select(PlanetBioSAA).where(PlanetBioSAA.system_id == system_id)
.where(PlanetBioSAA.planet_id == planet_id))
if data:
return data.planet_name
return 'id {str(planet_id)}'


def set_bio(system_id: int, planet_id: int, bio_codex: str, bio_name: str):
data: BioList = this.sql_session_factory.scalar(select(BioList).where(BioList.system_id == system_id)
.where(BioList.planet_id == planet_id)
Expand All @@ -357,6 +386,15 @@ def set_bio(system_id: int, planet_id: int, bio_codex: str, bio_name: str):
this.sql_session_factory.commit()


def sell_bio(system_id: int, planet_id: int, bio_codex: str, bio_name: str, bio_cost: int):
bio_time = datetime.datetime.now()
bio_time = bio_time.strftime('%Y_%m_%d_%H_%M')
data = BioShell(system_id=system_id, planet_id=planet_id, bio_codex=bio_codex,
bio_name=bio_name, bio_cost=bio_cost, bio_time=bio_time)
this.sql_session_factory.add(data)
this.sql_session_factory.commit()


def get_bio_cost(bio_codex: str) -> int:
price = 0
data: BioListCost = this.sql_session_factory.scalar(select(BioListCost).where(BioListCost.bio_codex == bio_codex))
Expand Down Expand Up @@ -404,3 +442,21 @@ def get_docked_fleet(market_id: int) -> bool:
if not data:
find_fleet = True
return find_fleet


def export_bio_lost() -> None:
if this.sql_session_factory.query(func.count(BioShell.id)).scalar() > 0:
export_path = config.app_dir_path / 'data_lost'
if not export_path.exists():
os.makedirs(export_path)
stamp_time = datetime.datetime.now()
stamp_time = stamp_time.strftime('%Y_%m_%d_%H_%M')
filename = 'bio_' + stamp_time + '.txt'
file = open(export_path / filename, 'w')
table = this.sql_session_factory.query(BioShell).all()
for data in table:
text_exp = '{} | Name: {} | cost: {} |'.format(data.bio_time, data.bio_name, str(data.bio_cost))
text_exp += ' System: {} |'.format(name_system(data.system_id))
text_exp += ' Planet: {}'.format(name_planet(data.system_id, data.planet_id))
file.write(text_exp + '\n')
file.close()
2 changes: 0 additions & 2 deletions src/data_progress/journal_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ def parse_journal(journal_path: Path, tg: bool) -> int:

def clear_db(session1: Session):

#session1.execute(Table(table_name, metadata, autoload=True).delete())

session1.query(db.JournalLog).delete()
session1.query(db.SystemList).delete()
session1.query(db.ThargoidList).delete()
Expand Down
2 changes: 1 addition & 1 deletion src/inara_progress/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugin_name = 'InaraProgress'
plugin_version = '1.4.1'
plugin_version = '1.4.5'

combat_ranks = {0: "Harmless", 1: "Mostly Harmless", 2: "Novice", 3: "Competent", 4: "Expert",
5: "Master", 6: "Dangerous", 7: "Deadly", 8: "Elite", 9: "Elite I", 10: "Elite II",
Expand Down
2 changes: 1 addition & 1 deletion src/inara_progress/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def display(self, message_id: str, text: str, x: int = 0, y: int = 0,
logger.debug(err)

def draw(self, message_id: str, text: str, x: int = 0, y: int = 0,
color: str = "#ffffff", size: str = "normal", ttl: float = 60) -> None:
color: str = "#ffffff", size: str = "normal", ttl: float = 60) -> None:
"""
Displays text with given attributes. Only draws text once which expires after 'ttl'.
Expand Down
6 changes: 3 additions & 3 deletions src/inara_progress/progresslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class ProgressLog(object):
LEVEL_MAPPING = {"DEBUG": logging.DEBUG, "INFO": logging.INFO,
"WARNING": logging.WARNING, "ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL}
#PLUGIN_NAME = os.path.basename(os.path.dirname(__file__))
# PLUGIN_NAME = os.path.basename(os.path.dirname(__file__))

def __init__(self):
self.logger = logging.getLogger(f'{appname}.{const.plugin_name}')
level = self.LEVEL_MAPPING.get("INFO", logging.NOTSET)
self.logger.setLevel(level)

if self.logger.hasHandlers():
if self.logger.hasHandlers():
logger_channel = logging.StreamHandler()
#logger_formatter = logging.Formatter(f'%(asctime)s - %(name)s - %(levelname)s - %(module)s:%(lineno)d:%(funcName)s: %(message)s')
# logger_formatter = logging.Formatter(f'%(asctime)s - %(name)s - %(levelname)s - %(module)s:%(lineno)d:%(funcName)s: %(message)s')
logger_formatter = logging.Formatter(f'%(asctime)s - %(levelname)s - %(name)s - %(message)s')
logger_formatter.default_time_format = '%Y-%m-%d %H:%M:%S'
logger_formatter.default_msec_format = '%s.%03d'
Expand Down
Loading

0 comments on commit fc60aaf

Please sign in to comment.