Skip to content

Commit

Permalink
refactor: output sample system json if debug
Browse files Browse the repository at this point in the history
The entire galaxy_stations.json is too big and unwieldy to look at directly, so turning on debug will output only the `Shinrarta Dezhra` system to `./tmp/shin_dez.json`, making it much easier to see the data structure, and since `Jameson Mermorial` has all the things, we can also use it to check those things against the DB.
  • Loading branch information
eyeonus committed Jun 10, 2024
1 parent c07eb91 commit 3688683
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions tradedangerous/plugins/spansh_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,23 +569,28 @@ def ensure_commodity(self, commodity: Commodity):
def bool_yn(self, value: Optional[bool]) -> str:
""" translates a ternary (none, true, false) into the ?/Y/N representation """
return '?' if value is None else ('Y' if value else 'N')


def ingest_stream(stream):
"""Ingest a spansh-style galaxy dump, yielding system-level data."""
for system_data in ijson.items(stream, 'item', use_float=True):
coords = system_data.get('coords', {})
yield (
System(
id=system_data.get('id64'),
name=system_data.get('name', 'Unnamed').strip(),
pos_x=coords.get('x', 999999),
pos_y=coords.get('y', 999999),
pos_z=coords.get('z', 999999),
modified=parse_ts(system_data.get('date')),
),
ingest_stations(system_data),
)

def ingest_stream(self, stream):
"""Ingest a spansh-style galaxy dump, yielding system-level data."""
for system_data in ijson.items(stream, 'item', use_float=True):
if "Shinrarta Dezhra" in system_data.get('name') and self.tdenv.debug:
with open(Path(self.tdenv.tmpDir, "shin_dez.json"), 'w') as file:
# file.write(system_data)
import json
json.dump(system_data, file, indent=4)

coords = system_data.get('coords', {})
yield (
System(
id=system_data.get('id64'),
name=system_data.get('name', 'Unnamed').strip(),
pos_x=coords.get('x', 999999),
pos_y=coords.get('y', 999999),
pos_z=coords.get('z', 999999),
modified=parse_ts(system_data.get('date')),
),
ingest_stations(system_data),
)


def ingest_stations(system_data):
Expand Down

0 comments on commit 3688683

Please sign in to comment.