Skip to content

Commit

Permalink
fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
arihant2math committed Jun 10, 2023
2 parents 87624d3 + 3f6d6a3 commit 25734c2
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 61 deletions.
14 changes: 7 additions & 7 deletions autotraders/faction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from autotraders.paginated_list import PaginatedList
from autotraders.space_traders_entity import SpaceTradersEntity
from autotraders.session import AutoTradersSession
Expand All @@ -8,12 +6,14 @@


class Faction(SpaceTradersEntity):
is_recruiting: bool
traits: list[Trait]
headquarters: MapSymbol
description: str
name: str
symbol: str

def __init__(self, symbol, session: AutoTradersSession, data=None):
self.is_recruiting: Optional[bool] = None
self.traits: Optional[list[Trait]] = None
self.headquarters: Optional[MapSymbol] = None
self.description: Optional[str] = None
self.name: Optional[str] = None
self.symbol: str = symbol
super().__init__(session, "factions/" + self.symbol, data)

Expand Down
16 changes: 9 additions & 7 deletions autotraders/faction/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from autotraders.space_traders_entity import SpaceTradersEntity
from autotraders.session import AutoTradersSession
from autotraders.shared_models.map_symbol import MapSymbol
from autotraders.util import parse_time
from autotraders.time import parse_time


class Deliver:
Expand All @@ -17,15 +17,17 @@ def __init__(self, data):


class Contract(SpaceTradersEntity):
accepted: bool
fulfilled: bool
deadline: datetime
accept_deadline: datetime
on_fulfilled: str
on_accepted: str
contract_id: str

def __init__(self, contract_id: str, session: AutoTradersSession, data=None):
self.contract_data = None
self.accepted: Optional[bool] = None
self.fulfilled: Optional[bool] = None
self.deadline: Optional[datetime] = None
self.accept_deadline: Optional[datetime] = None
self.contract_type = None
self.on_fulfilled: Optional[str] = None
self.on_accepted: Optional[str] = None
self.contract_id: str = contract_id
super().__init__(session, "my/contracts/" + self.contract_id, data)

Expand Down
6 changes: 3 additions & 3 deletions autotraders/map/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def paginated_func(p, num_per_page):
+ "&page="
+ str(p)
)
j = r.json()["data"]
j = r.json()
if "error" in j:
raise IOError(j["error"]["message"])
systems = []
for system in j:
for system in j["data"]:
s = System(system["symbol"], session, system)
systems.append(s)
return systems, r.json()["meta"]["total"]
return systems, j["meta"]["total"]

return PaginatedList(paginated_func, page)

Expand Down
2 changes: 1 addition & 1 deletion autotraders/shared_models/transaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from autotraders.shared_models.item import Item
from autotraders.shared_models.map_symbol import MapSymbol
from autotraders.util import parse_time
from autotraders.time import parse_time


class ShipyardTransaction:
Expand Down
41 changes: 29 additions & 12 deletions autotraders/ship/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from autotraders.shared_models.map_symbol import MapSymbol
from autotraders.ship.ship_components import Frame, Reactor, Engine, Module, Mount
from autotraders.ship.survey import Survey
from autotraders.util import parse_time
from autotraders.time import parse_time
from autotraders.map.waypoint import Waypoint


Expand Down Expand Up @@ -42,19 +42,32 @@ def __init__(self, data):
self.role = data["role"]


class Capabilities:
def __init__(self, modules, mounts):
warp_drives = [module for module in modules if "warp" in module.symbol.lower()]
jump_drives = [module for module in modules if "jump" in module.symbol.lower()]
mine = [mount for mount in mounts if "mine" in mount.symbol.lower()]
self.warp = len(warp_drives) > 0
self.jump = len(jump_drives) > 0
self.mine = len(mine) > 0


class Ship(SpaceTradersEntity):
cargo: Cargo
fuel: Fuel
nav: Nav
symbol: str
frame: Frame
reactor: Reactor
engine: Engine
modules: list[Module]
mounts: list[Mount]
crew: Crew
registration: Registration
capabilities: Optional[Capabilities]

def __init__(self, symbol, session: AutoTradersSession, data=None):
self.cargo: Optional[Cargo] = None
self.fuel: Optional[Fuel] = None
self.nav: Optional[Nav] = None
self.symbol: str = symbol
self.frame: Optional[Frame] = None
self.reactor: Optional[Reactor] = None
self.engine: Optional[Engine] = None
self.modules: Optional[list[Module]] = None
self.mounts: Optional[list[Mount]] = None
self.crew: Optional[Crew] = None
self.registration: Optional[Registration] = None
self.symbol = symbol
super().__init__(session, "my/ships/" + self.symbol, data)

def update(self, data: dict = None) -> None:
Expand All @@ -81,6 +94,10 @@ def update(self, data: dict = None) -> None:
self.cargo = Cargo(self.symbol, self.session, data["cargo"])
if "registration" in data:
self.registration = Registration(data["registration"])
try:
self.capabilities = Capabilities(self.modules, self.mounts)
except:
pass

async def navigate_async(self, waypoint: Union[str, MapSymbol], interval=1):
"""Attempts to move ship to the provided waypoint.
Expand Down
2 changes: 1 addition & 1 deletion autotraders/ship/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autotraders import AutoTradersSession
from autotraders.shared_models.map_symbol import MapSymbol
from autotraders.space_traders_entity import SpaceTradersEntity
from autotraders.util import parse_time
from autotraders.time import parse_time


class Route:
Expand Down
14 changes: 14 additions & 0 deletions autotraders/ship/states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from enum import Enum


class FlightMode(str, Enum):
CRUISE = "CRUISE"
DRIFT = "DRIFT"
BURN = "BURN"
STEALTH = "STEALTH"


class NavState(str, Enum):
DOCK = "DOCK"
ORBIT = "ORBIT"
IN_TRANSIT = "IN_TRANSIT"
2 changes: 1 addition & 1 deletion autotraders/ship/survey.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from autotraders.util import parse_time
from autotraders.time import parse_time


class Survey:
Expand Down
2 changes: 1 addition & 1 deletion autotraders/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import requests

from autotraders.util import parse_time
from autotraders.time import parse_time


class LeaderboardPlayer:
Expand Down
17 changes: 17 additions & 0 deletions autotraders/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
from datetime import datetime, timezone


def parse_time(time: str) -> datetime:
if sys.version_info.minor >= 11:
return datetime.fromisoformat(time)
else:
try:
d = datetime.strptime(time, "%Y-%m-%dT%H:%M:%S.%fZ")
except ValueError:
try:
d = datetime.strptime(time, "%Y-%m-%dT%H:%M:%SZ")
except ValueError:
d = datetime.fromisoformat(time)
d = d.replace(tzinfo=timezone.utc)
return d
34 changes: 9 additions & 25 deletions autotraders/util.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
import sys
from datetime import datetime, timezone


def parse_time(time: str) -> datetime:
if sys.version_info.minor >= 11:
return datetime.fromisoformat(time)
else:
try:
d = datetime.strptime(time, "%Y-%m-%dT%H:%M:%S.%fZ")
except ValueError:
try:
d = datetime.strptime(time, "%Y-%m-%dT%H:%M:%SZ")
except ValueError:
d = datetime.fromisoformat(time)
d = d.replace(tzinfo=timezone.utc)
return d
from autotraders.ship.states import FlightMode


def travel_fuel(distance, mode):
if mode == "CRUISE":
if mode == FlightMode.CRUISE:
return distance
elif mode == "DRIFT":
elif mode == FlightMode.DRIFT:
return 1
elif mode == "BURN":
elif mode == FlightMode.BURN:
return 2 * distance
elif mode == "STEALTH":
elif mode == FlightMode.STEALTH:
return distance


def travel_time(distance, ship_speed, mode):
if mode == "CRUISE":
if mode == FlightMode.CRUISE:
return 15 + 10 * distance / ship_speed
elif mode == "DRIFT":
elif mode == FlightMode.DRIFT:
return 15 + 100 * distance / ship_speed
elif mode == "BURN":
elif mode == FlightMode.BURN:
return 15 + 5 * distance / ship_speed
elif mode == "STEALTH":
elif mode == FlightMode.STEALTH:
return 15 + 20 * distance / ship_speed
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "autotraders"
version = "1.4.3"
version = "1.5.0"
authors = [
{ name="Ashwin Naren", email="arihant2math@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
project = "Autotraders"
copyright = "2023, cosmictraders"
author = "cosmictraders"
release = "1.4.2"
release = "1.5.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from autotraders.shared_models.map_symbol import MapSymbol
from autotraders.util import parse_time
from autotraders.time import parse_time


def test_time_parser():
Expand Down

0 comments on commit 25734c2

Please sign in to comment.