1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Made most event lookups case insensitive

Slightly more than `s/((el)?if event_type (in|==) \(?('(?:.*[A-Z].*).*')\)?:)$/\L$1`.

Closes #1087
This commit is contained in:
Athanasius 2021-06-18 10:42:13 +01:00
parent d823082a51
commit 6ad22541fe

View File

@ -489,8 +489,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
entry: MutableMapping[str, Any] = json.loads(line, object_pairs_hook=OrderedDict) entry: MutableMapping[str, Any] = json.loads(line, object_pairs_hook=OrderedDict)
entry['timestamp'] # we expect this to exist # TODO: replace with assert? or an if key in check entry['timestamp'] # we expect this to exist # TODO: replace with assert? or an if key in check
event_type = entry['event'] event_type = entry['event'].lower()
if event_type == 'Fileheader': if event_type == 'fileheader':
self.live = False self.live = False
self.version = entry['gameversion'] self.version = entry['gameversion']
self.is_beta = any(v in entry['gameversion'].lower() for v in ('alpha', 'beta')) self.is_beta = any(v in entry['gameversion'].lower() for v in ('alpha', 'beta'))
@ -513,10 +513,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['GameVersion'] = entry['gameversion'] self.state['GameVersion'] = entry['gameversion']
self.state['GameBuild'] = entry['build'] self.state['GameBuild'] = entry['build']
elif event_type == 'Commander': elif event_type == 'commander':
self.live = True # First event in 3.0 self.live = True # First event in 3.0
elif event_type == 'LoadGame': elif event_type == 'loadgame':
# alpha4
# Odyssey: bool
self.cmdr = entry['Commander'] self.cmdr = entry['Commander']
# 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event) # 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event)
self.mode = entry.get('GameMode') self.mode = entry.get('GameMode')
@ -551,11 +553,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if entry.get('Ship') is not None and self._RE_SHIP_ONFOOT.search(entry['Ship']): if entry.get('Ship') is not None and self._RE_SHIP_ONFOOT.search(entry['Ship']):
self.state['OnFoot'] = True self.state['OnFoot'] = True
elif event_type == 'NewCommander': elif event_type == 'newcommander':
self.cmdr = entry['Name'] self.cmdr = entry['Name']
self.group = None self.group = None
elif event_type == 'SetUserShipName': elif event_type == 'setusershipname':
self.state['ShipID'] = entry['ShipID'] self.state['ShipID'] = entry['ShipID']
if 'UserShipId' in entry: # Only present when changing the ship's ident if 'UserShipId' in entry: # Only present when changing the ship's ident
self.state['ShipIdent'] = entry['UserShipId'] self.state['ShipIdent'] = entry['UserShipId']
@ -563,7 +565,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['ShipName'] = entry.get('UserShipName') self.state['ShipName'] = entry.get('UserShipName')
self.state['ShipType'] = self.canonicalise(entry['Ship']) self.state['ShipType'] = self.canonicalise(entry['Ship'])
elif event_type == 'ShipyardBuy': elif event_type == 'shipyardbuy':
self.state['ShipID'] = None self.state['ShipID'] = None
self.state['ShipIdent'] = None self.state['ShipIdent'] = None
self.state['ShipName'] = None self.state['ShipName'] = None
@ -575,7 +577,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Credits'] -= entry.get('ShipPrice', 0) self.state['Credits'] -= entry.get('ShipPrice', 0)
elif event_type == 'ShipyardSwap': elif event_type == 'shipyardswap':
self.state['ShipID'] = entry['ShipID'] self.state['ShipID'] = entry['ShipID']
self.state['ShipIdent'] = None self.state['ShipIdent'] = None
self.state['ShipName'] = None self.state['ShipName'] = None
@ -585,9 +587,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Rebuy'] = None self.state['Rebuy'] = None
self.state['Modules'] = None self.state['Modules'] = None
elif (event_type == 'Loadout' and elif (
'fighter' not in self.canonicalise(entry['Ship']) and event_type == 'loadout' and
'buggy' not in self.canonicalise(entry['Ship'])): 'fighter' not in self.canonicalise(entry['Ship']) and
'buggy' not in self.canonicalise(entry['Ship'])
):
self.state['ShipID'] = entry['ShipID'] self.state['ShipID'] = entry['ShipID']
self.state['ShipIdent'] = entry['ShipIdent'] self.state['ShipIdent'] = entry['ShipIdent']
@ -615,7 +619,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Modules'][module['Slot']] = module self.state['Modules'][module['Slot']] = module
elif event_type == 'ModuleBuy': elif event_type == 'modulebuy':
self.state['Modules'][entry['Slot']] = { self.state['Modules'][entry['Slot']] = {
'Slot': entry['Slot'], 'Slot': entry['Slot'],
'Item': self.canonicalise(entry['BuyItem']), 'Item': self.canonicalise(entry['BuyItem']),
@ -627,21 +631,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Credits'] -= entry.get('BuyPrice', 0) self.state['Credits'] -= entry.get('BuyPrice', 0)
elif event_type == 'ModuleRetrieve': elif event_type == 'moduleretrieve':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'ModuleSell': elif event_type == 'modulesell':
self.state['Modules'].pop(entry['Slot'], None) self.state['Modules'].pop(entry['Slot'], None)
self.state['Credits'] += entry.get('SellPrice', 0) self.state['Credits'] += entry.get('SellPrice', 0)
elif event_type == 'ModuleSellRemote': elif event_type == 'modulesellremote':
self.state['Credits'] += entry.get('SellPrice', 0) self.state['Credits'] += entry.get('SellPrice', 0)
elif event_type == 'ModuleStore': elif event_type == 'modulestore':
self.state['Modules'].pop(entry['Slot'], None) self.state['Modules'].pop(entry['Slot'], None)
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'ModuleSwap': elif event_type == 'moduleswap':
to_item = self.state['Modules'].get(entry['ToSlot']) to_item = self.state['Modules'].get(entry['ToSlot'])
to_slot = entry['ToSlot'] to_slot = entry['ToSlot']
from_slot = entry['FromSlot'] from_slot = entry['FromSlot']
@ -653,13 +657,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
modules.pop(from_slot, None) modules.pop(from_slot, None)
elif event_type == 'Undocked': elif event_type == 'undocked':
self.station = None self.station = None
self.station_marketid = None self.station_marketid = None
self.stationtype = None self.stationtype = None
self.stationservices = None self.stationservices = None
elif event_type == 'Embark': elif event_type == 'embark':
# This event is logged when a player (on foot) gets into a ship or SRV # This event is logged when a player (on foot) gets into a ship or SRV
# Parameters: # Parameters:
# • SRV: true if getting into SRV, false if getting into a ship # • SRV: true if getting into SRV, false if getting into a ship
@ -686,7 +690,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# ShipLocker. # ShipLocker.
self.backpack_set_empty() self.backpack_set_empty()
elif event_type == 'Disembark': elif event_type == 'disembark':
# This event is logged when the player steps out of a ship or SRV # This event is logged when the player steps out of a ship or SRV
# #
# Parameters: # Parameters:
@ -704,7 +708,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# • StationType # • StationType
# • MarketID # • MarketID
if entry.get('OnStation', False): if entry.get('onstation', False):
self.station = entry.get('StationName', '') self.station = entry.get('StationName', '')
else: else:
@ -717,13 +721,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Taxi'] = False self.state['Taxi'] = False
self.state['Dropship'] = False self.state['Dropship'] = False
elif event_type == 'DropshipDeploy': elif event_type == 'dropshipdeploy':
# We're definitely on-foot now # We're definitely on-foot now
self.state['OnFoot'] = True self.state['OnFoot'] = True
self.state['Taxi'] = False self.state['Taxi'] = False
self.state['Dropship'] = False self.state['Dropship'] = False
elif event_type == 'Docked': elif event_type == 'docked':
self.station = entry.get('StationName') # May be None self.station = entry.get('StationName') # May be None
self.station_marketid = entry.get('MarketID') # May be None self.station_marketid = entry.get('MarketID') # May be None
self.stationtype = entry.get('StationType') # May be None self.stationtype = entry.get('StationType') # May be None
@ -731,7 +735,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# No need to set self.state['Taxi'] or Dropship here, if its those, the next event is a Disembark anyway # No need to set self.state['Taxi'] or Dropship here, if its those, the next event is a Disembark anyway
elif event_type in ('Location', 'FSDJump', 'CarrierJump'): elif event_type in ('location', 'fsdjump', 'carrierjump'):
# alpha4 - any changes ? # alpha4 - any changes ?
# Location: # Location:
# New in Odyssey: # New in Odyssey:
@ -739,15 +743,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# • Multicrew: bool # • Multicrew: bool
# • InSRV: bool # • InSRV: bool
# • OnFoot: bool # • OnFoot: bool
if event_type in ('Location', 'CarrierJump'): if event_type in ('location', 'carrierjump'):
self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None
self.state['Body'] = entry.get('Body') self.state['Body'] = entry.get('Body')
self.state['BodyType'] = entry.get('BodyType') self.state['BodyType'] = entry.get('BodyType')
# if event_type == 'Location': # if event_type == 'location':
# logger.trace('"Location" event') # logger.trace('"Location" event')
elif event_type == 'FSDJump': elif event_type == 'fsdjump':
self.planet = None self.planet = None
self.state['Body'] = None self.state['Body'] = None
self.state['BodyType'] = None self.state['BodyType'] = None
@ -776,37 +780,37 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if not self.state['Taxi']: if not self.state['Taxi']:
self.state['Dropship'] = None self.state['Dropship'] = None
elif event_type == 'ApproachBody': elif event_type == 'approachbody':
self.planet = entry['Body'] self.planet = entry['Body']
self.state['Body'] = entry['Body'] self.state['Body'] = entry['Body']
self.state['BodyType'] = 'Planet' # Best guess. Journal says always planet. self.state['BodyType'] = 'Planet' # Best guess. Journal says always planet.
elif event_type in ('LeaveBody', 'SupercruiseEntry'): elif event_type in ('leavebody', 'supercruiseentry'):
self.planet = None self.planet = None
self.state['Body'] = None self.state['Body'] = None
self.state['BodyType'] = None self.state['BodyType'] = None
elif event_type in ('Rank', 'Promotion'): elif event_type in ('rank', 'promotion'):
payload = dict(entry) payload = dict(entry)
payload.pop('event') payload.pop('event')
payload.pop('timestamp') payload.pop('timestamp')
self.state['Rank'].update({k: (v, 0) for k, v in payload.items()}) self.state['Rank'].update({k: (v, 0) for k, v in payload.items()})
elif event_type == 'Progress': elif event_type == 'progress':
rank = self.state['Rank'] rank = self.state['Rank']
for k, v in entry.items(): for k, v in entry.items():
if k in rank: if k in rank:
# perhaps not taken promotion mission yet # perhaps not taken promotion mission yet
rank[k] = (rank[k][0], min(v, 100)) rank[k] = (rank[k][0], min(v, 100))
elif event_type in ('Reputation', 'Statistics'): elif event_type in ('reputation', 'statistics'):
payload = OrderedDict(entry) payload = OrderedDict(entry)
payload.pop('event') payload.pop('event')
payload.pop('timestamp') payload.pop('timestamp')
self.state[event_type] = payload self.state[event_type] = payload
elif event_type == 'EngineerProgress': elif event_type == 'engineerprogress':
# Sanity check - at least once the 'Engineer' (name) was missing from this in early # Sanity check - at least once the 'Engineer' (name) was missing from this in early
# Odyssey 4.0.0.100. Might only have been a server issue causing incomplete data. # Odyssey 4.0.0.100. Might only have been a server issue causing incomplete data.
@ -826,7 +830,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
engineers[engineer] = entry['Progress'] engineers[engineer] = entry['Progress']
elif event_type == 'Cargo' and entry.get('Vessel') == 'Ship': elif event_type == 'cargo' and entry.get('Vessel') == 'Ship':
self.state['Cargo'] = defaultdict(int) self.state['Cargo'] = defaultdict(int)
# From 3.3 full Cargo event (after the first one) is written to a separate file # From 3.3 full Cargo event (after the first one) is written to a separate file
if 'Inventory' not in entry: if 'Inventory' not in entry:
@ -838,7 +842,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean})
elif event_type == 'CargoTransfer': elif event_type == 'cargotransfer':
for c in entry['Transfers']: for c in entry['Transfers']:
name = self.canonicalise(c['Type']) name = self.canonicalise(c['Type'])
if c['Direction'] == 'toship': if c['Direction'] == 'toship':
@ -848,7 +852,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# So it's *from* the ship # So it's *from* the ship
self.state['Cargo'][name] -= c['Count'] self.state['Cargo'][name] -= c['Count']
elif event_type == 'ShipLocker': elif event_type == 'shiplocker':
# As of 4.0.0.400 (2021-06-10) # As of 4.0.0.400 (2021-06-10)
# "ShipLocker" will be a full list written to the journal at startup/boarding/disembarking, and also # "ShipLocker" will be a full list written to the journal at startup/boarding/disembarking, and also
# written to a separate shiplocker.json file - other updates will just update that file and mention it # written to a separate shiplocker.json file - other updates will just update that file and mention it
@ -904,12 +908,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
) )
# Journal v31 implies this was removed before Odyssey launch # Journal v31 implies this was removed before Odyssey launch
elif event_type == 'BackPackMaterials': elif event_type == 'backpackmaterials':
# Last seen in a 4.0.0.102 journal file. # Last seen in a 4.0.0.102 journal file.
logger.warning(f'We have a BackPackMaterials event, defunct since > 4.0.0.102 ?:\n{entry}\n') logger.warning(f'We have a BackPackMaterials event, defunct since > 4.0.0.102 ?:\n{entry}\n')
pass pass
elif event_type in ('BackPack', 'Backpack'): # WORKAROUND 4.0.0.200: BackPack becomes Backpack elif event_type == 'backpack':
# TODO: v31 doc says this is`backpack.json` ... but Howard Chalkley # TODO: v31 doc says this is`backpack.json` ... but Howard Chalkley
# said it's `Backpack.json` # said it's `Backpack.json`
backpack_file = pathlib.Path(str(self.currentdir)) / 'Backpack.json' backpack_file = pathlib.Path(str(self.currentdir)) / 'Backpack.json'
@ -964,7 +968,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
{self.canonicalise(x['Name']): x['Count'] for x in clean_data} {self.canonicalise(x['Name']): x['Count'] for x in clean_data}
) )
elif event_type == 'BackpackChange': elif event_type == 'backpackchange':
# Changes to Odyssey Backpack contents *other* than from a Transfer # Changes to Odyssey Backpack contents *other* than from a Transfer
# See TransferMicroResources event for that. # See TransferMicroResources event for that.
@ -997,21 +1001,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if self.state['BackPack'][c][m] < 0: if self.state['BackPack'][c][m] < 0:
self.state['BackPack'][c][m] = 0 self.state['BackPack'][c][m] = 0
elif event_type == 'BuyMicroResources': elif event_type == 'buymicroresources':
# From 4.0.0.400 we get an empty (see file) `ShipLocker` event, # From 4.0.0.400 we get an empty (see file) `ShipLocker` event,
# so we can ignore this for inventory purposes. # so we can ignore this for inventory purposes.
# But do record the credits balance change. # But do record the credits balance change.
self.state['Credits'] -= entry.get('Price', 0) self.state['Credits'] -= entry.get('Price', 0)
elif event_type == 'SellMicroResources': elif event_type == 'sellmicroresources':
# As of 4.0.0.400 we can ignore this as an empty (see file) # As of 4.0.0.400 we can ignore this as an empty (see file)
# `ShipLocker` event is written for the full new inventory. # `ShipLocker` event is written for the full new inventory.
# But still record the credits balance change. # But still record the credits balance change.
self.state['Credits'] += entry.get('Price', 0) self.state['Credits'] += entry.get('Price', 0)
elif event_type in ('TradeMicroResources', 'CollectItems', 'DropItems', 'UseConsumable'): elif event_type in ('tradeMicroResources', 'collectitems', 'dropitems', 'useconsumable'):
# As of 4.0.0.400 we can ignore these as an empty (see file) # As of 4.0.0.400 we can ignore these as an empty (see file)
# `ShipLocker` event and/or a `BackpackChange` is also written. # `ShipLocker` event and/or a `BackpackChange` is also written.
pass pass
@ -1021,7 +1025,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# also there's one additional journal event that was missed out from # also there's one additional journal event that was missed out from
# this version of the docs: "SuitLoadout": # when starting on foot, or # this version of the docs: "SuitLoadout": # when starting on foot, or
# when disembarking from a ship, with the same info as found in "CreateSuitLoadout" # when disembarking from a ship, with the same info as found in "CreateSuitLoadout"
elif event_type == 'SuitLoadout': elif event_type == 'suitloadout':
suit_slotid, suitloadout_slotid = self.suitloadout_store_from_event(entry) suit_slotid, suitloadout_slotid = self.suitloadout_store_from_event(entry)
if not self.suit_and_loadout_setcurrent(suit_slotid, suitloadout_slotid): if not self.suit_and_loadout_setcurrent(suit_slotid, suitloadout_slotid):
logger.error(f"Event was: {entry}") logger.error(f"Event was: {entry}")
@ -1061,7 +1065,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# if not self.suit_and_loadout_setcurrent(suitid, suitloadout_slotid): # if not self.suit_and_loadout_setcurrent(suitid, suitloadout_slotid):
# logger.error(f"Event was: {entry}") # logger.error(f"Event was: {entry}")
elif event_type == 'DeleteSuitLoadout': elif event_type == 'deletesuitloadout':
# alpha4: # alpha4:
# { "timestamp":"2021-04-29T10:32:27Z", "event":"DeleteSuitLoadout", "SuitID":1698365752966423, # { "timestamp":"2021-04-29T10:32:27Z", "event":"DeleteSuitLoadout", "SuitID":1698365752966423,
# "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003,
@ -1076,7 +1080,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# This should no longer happen, as we're now handling CreateSuitLoadout properly # This should no longer happen, as we're now handling CreateSuitLoadout properly
logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?")
elif event_type == 'RenameSuitLoadout': elif event_type == 'renamesuitloadout':
# alpha4 # alpha4
# Parameters: # Parameters:
# • SuitID # • SuitID
@ -1095,7 +1099,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
except KeyError: except KeyError:
logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?")
elif event_type == 'BuySuit': elif event_type == 'buysuit':
# alpha4 : # alpha4 :
# { "timestamp":"2021-04-29T09:03:37Z", "event":"BuySuit", "Name":"UtilitySuit_Class1", # { "timestamp":"2021-04-29T09:03:37Z", "event":"BuySuit", "Name":"UtilitySuit_Class1",
# "Name_Localised":"Maverick Suit", "Price":150000, "SuitID":1698364934364699 } # "Name_Localised":"Maverick Suit", "Price":150000, "SuitID":1698364934364699 }
@ -1116,7 +1120,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
self.state['Credits'] -= price self.state['Credits'] -= price
elif event_type == 'SellSuit': elif event_type == 'sellsuit':
# Remove from known suits # Remove from known suits
# As of Odyssey Alpha Phase 2, Hotfix 5 (4.0.0.13) this isn't possible as this event # As of Odyssey Alpha Phase 2, Hotfix 5 (4.0.0.13) this isn't possible as this event
# doesn't contain the specific suit ID as per CAPI `suits` dict. # doesn't contain the specific suit ID as per CAPI `suits` dict.
@ -1144,7 +1148,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
self.state['Credits'] += price self.state['Credits'] += price
elif event_type == 'UpgradeSuit': elif event_type == 'upgradesuit':
# alpha4 # alpha4
# This event is logged when the player upgrades their flight suit # This event is logged when the player upgrades their flight suit
# #
@ -1156,7 +1160,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# TODO: Update self.state['Suits'] when we have an example to work from # TODO: Update self.state['Suits'] when we have an example to work from
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'LoadoutEquipModule': elif event_type == 'loadoutequipmodule':
# alpha4: # alpha4:
# { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutEquipModule", "LoadoutName":"Dom L/K/K", # { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutEquipModule", "LoadoutName":"Dom L/K/K",
# "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit",
@ -1176,7 +1180,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
except KeyError: except KeyError:
logger.error(f"LoadoutEquipModule: {entry}") logger.error(f"LoadoutEquipModule: {entry}")
elif event_type == 'LoadoutRemoveModule': elif event_type == 'loadoutremovemodule':
# alpha4 - triggers if selecting an already-equipped weapon into a different slot # alpha4 - triggers if selecting an already-equipped weapon into a different slot
# { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutRemoveModule", "LoadoutName":"Dom L/K/K", # { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutRemoveModule", "LoadoutName":"Dom L/K/K",
# "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit",
@ -1190,7 +1194,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
except KeyError: except KeyError:
logger.error(f"LoadoutRemoveModule: {entry}") logger.error(f"LoadoutRemoveModule: {entry}")
elif event_type == 'BuyWeapon': elif event_type == 'buyweapon':
# alpha4 # alpha4
# { "timestamp":"2021-04-29T11:10:51Z", "event":"BuyWeapon", "Name":"Wpn_M_AssaultRifle_Laser_FAuto", # { "timestamp":"2021-04-29T11:10:51Z", "event":"BuyWeapon", "Name":"Wpn_M_AssaultRifle_Laser_FAuto",
# "Name_Localised":"TK Aphelion", "Price":125000, "SuitModuleID":1698372938719590 } # "Name_Localised":"TK Aphelion", "Price":125000, "SuitModuleID":1698372938719590 }
@ -1201,7 +1205,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
self.state['Credits'] -= price self.state['Credits'] -= price
elif event_type == 'SellWeapon': elif event_type == 'sellweapon':
# We're not actually keeping track of all owned weapons, only those in # We're not actually keeping track of all owned weapons, only those in
# Suit Loadouts. # Suit Loadouts.
# alpha4: # alpha4:
@ -1225,20 +1229,20 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
self.state['Credits'] += price self.state['Credits'] += price
elif event_type == 'UpgradeWeapon': elif event_type == 'upgradeweapon':
# We're not actually keeping track of all owned weapons, only those in # We're not actually keeping track of all owned weapons, only those in
# Suit Loadouts. # Suit Loadouts.
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'ScanOrganic': elif event_type == 'scanorganic':
# Nothing of interest to our state. # Nothing of interest to our state.
pass pass
elif event_type == 'SellOrganicData': elif event_type == 'sellorganicdata':
for bd in entry['BioData']: for bd in entry['BioData']:
self.state['Credits'] += bd.get('Value', 0) + bd.get('Bonus', 0) self.state['Credits'] += bd.get('Value', 0) + bd.get('Bonus', 0)
elif event_type == 'BookDropship': elif event_type == 'bookdropship':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
self.state['Dropship'] = True self.state['Dropship'] = True
# Technically we *might* now not be OnFoot. # Technically we *might* now not be OnFoot.
@ -1252,20 +1256,20 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# not still on-foot, BUT it doesn't really matter as the next significant # not still on-foot, BUT it doesn't really matter as the next significant
# event is going to be Disembark to on-foot anyway. # event is going to be Disembark to on-foot anyway.
elif event_type == 'BookTaxi': elif event_type == 'booktaxi':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
# Dont set taxi state here, as we're not IN a taxi yet. Set it on Embark # Dont set taxi state here, as we're not IN a taxi yet. Set it on Embark
elif event_type == 'CancelDropship': elif event_type == 'canceldropship':
self.state['Credits'] += entry.get('Refund', 0) self.state['Credits'] += entry.get('Refund', 0)
self.state['Dropship'] = False self.state['Dropship'] = False
self.state['Taxi'] = False self.state['Taxi'] = False
elif event_type == 'CancelTaxi': elif event_type == 'canceltaxi':
self.state['Credits'] += entry.get('Refund', 0) self.state['Credits'] += entry.get('Refund', 0)
self.state['Taxi'] = False self.state['Taxi'] = False
elif event_type == 'NavRoute': elif event_type == 'navroute':
# Added in ED 3.7 - multi-hop route details in NavRoute.json # Added in ED 3.7 - multi-hop route details in NavRoute.json
with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore
try: try:
@ -1277,7 +1281,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
self.state['NavRoute'] = entry self.state['NavRoute'] = entry
elif event_type == 'ModuleInfo': elif event_type == 'moduleinfo':
with open(join(self.currentdir, 'ModulesInfo.json'), 'rb') as mf: # type: ignore with open(join(self.currentdir, 'ModulesInfo.json'), 'rb') as mf: # type: ignore
try: try:
entry = json.load(mf) entry = json.load(mf)
@ -1288,30 +1292,30 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
else: else:
self.state['ModuleInfo'] = entry self.state['ModuleInfo'] = entry
elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'): elif event_type in ('collectcargo', 'marketbuy', 'buydrones', 'miningrefined'):
commodity = self.canonicalise(entry['Type']) commodity = self.canonicalise(entry['Type'])
self.state['Cargo'][commodity] += entry.get('Count', 1) self.state['Cargo'][commodity] += entry.get('Count', 1)
if event_type == 'BuyDrones': if event_type == 'buydrones':
self.state['Credits'] -= entry.get('TotalCost', 0) self.state['Credits'] -= entry.get('TotalCost', 0)
elif event_type == 'MarketBuy': elif event_type == 'marketbuy':
self.state['Credits'] -= entry.get('TotalCost', 0) self.state['Credits'] -= entry.get('TotalCost', 0)
elif event_type in ('EjectCargo', 'MarketSell', 'SellDrones'): elif event_type in ('ejectcargo', 'marketsell', 'selldrones'):
commodity = self.canonicalise(entry['Type']) commodity = self.canonicalise(entry['Type'])
cargo = self.state['Cargo'] cargo = self.state['Cargo']
cargo[commodity] -= entry.get('Count', 1) cargo[commodity] -= entry.get('Count', 1)
if cargo[commodity] <= 0: if cargo[commodity] <= 0:
cargo.pop(commodity) cargo.pop(commodity)
if event_type == 'MarketSell': if event_type == 'marketsell':
self.state['Credits'] += entry.get('TotalSale', 0) self.state['Credits'] += entry.get('TotalSale', 0)
elif event_type == 'SellDrones': elif event_type == 'selldrones':
self.state['Credits'] += entry.get('TotalSale', 0) self.state['Credits'] += entry.get('TotalSale', 0)
elif event_type == 'SearchAndRescue': elif event_type == 'searchandrescue':
for item in entry.get('Items', []): for item in entry.get('Items', []):
commodity = self.canonicalise(item['Name']) commodity = self.canonicalise(item['Name'])
cargo = self.state['Cargo'] cargo = self.state['Cargo']
@ -1319,25 +1323,25 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if cargo[commodity] <= 0: if cargo[commodity] <= 0:
cargo.pop(commodity) cargo.pop(commodity)
elif event_type == 'Materials': elif event_type == 'materials':
for category in ('Raw', 'Manufactured', 'Encoded'): for category in ('Raw', 'Manufactured', 'Encoded'):
self.state[category] = defaultdict(int) self.state[category] = defaultdict(int)
self.state[category].update({ self.state[category].update({
self.canonicalise(x['Name']): x['Count'] for x in entry.get(category, []) self.canonicalise(x['Name']): x['Count'] for x in entry.get(category, [])
}) })
elif event_type == 'MaterialCollected': elif event_type == 'materialcollected':
material = self.canonicalise(entry['Name']) material = self.canonicalise(entry['Name'])
self.state[entry['Category']][material] += entry['Count'] self.state[entry['Category']][material] += entry['Count']
elif event_type in ('MaterialDiscarded', 'ScientificResearch'): elif event_type in ('materialdiscarded', 'scientificresearch'):
material = self.canonicalise(entry['Name']) material = self.canonicalise(entry['Name'])
state_category = self.state[entry['Category']] state_category = self.state[entry['Category']]
state_category[material] -= entry['Count'] state_category[material] -= entry['Count']
if state_category[material] <= 0: if state_category[material] <= 0:
state_category.pop(material) state_category.pop(material)
elif event_type == 'Synthesis': elif event_type == 'synthesis':
for category in ('Raw', 'Manufactured', 'Encoded'): for category in ('Raw', 'Manufactured', 'Encoded'):
for x in entry['Materials']: for x in entry['Materials']:
material = self.canonicalise(x['Name']) material = self.canonicalise(x['Name'])
@ -1346,7 +1350,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if self.state[category][material] <= 0: if self.state[category][material] <= 0:
self.state[category].pop(material) self.state[category].pop(material)
elif event_type == 'MaterialTrade': elif event_type == 'materialtrade':
category = self.category(entry['Paid']['Category']) category = self.category(entry['Paid']['Category'])
state_category = self.state[category] state_category = self.state[category]
paid = entry['Paid'] paid = entry['Paid']
@ -1391,7 +1395,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
module['Engineering'].pop('ExperimentalEffect', None) module['Engineering'].pop('ExperimentalEffect', None)
module['Engineering'].pop('ExperimentalEffect_Localised', None) module['Engineering'].pop('ExperimentalEffect_Localised', None)
elif event_type == 'MissionCompleted': elif event_type == 'missioncompleted':
self.state['Credits'] += entry.get('Reward', 0) self.state['Credits'] += entry.get('Reward', 0)
for reward in entry.get('CommodityReward', []): for reward in entry.get('CommodityReward', []):
@ -1404,7 +1408,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
material = self.canonicalise(reward['Name']) material = self.canonicalise(reward['Name'])
self.state[category][material] += reward.get('Count', 1) self.state[category][material] += reward.get('Count', 1)
elif event_type == 'EngineerContribution': elif event_type == 'engineercontribution':
commodity = self.canonicalise(entry.get('Commodity')) commodity = self.canonicalise(entry.get('Commodity'))
if commodity: if commodity:
self.state['Cargo'][commodity] -= entry['Quantity'] self.state['Cargo'][commodity] -= entry['Quantity']
@ -1419,7 +1423,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if self.state[category][material] <= 0: if self.state[category][material] <= 0:
self.state[category].pop(material) self.state[category].pop(material)
elif event_type == 'TechnologyBroker': elif event_type == 'technologybroker':
for thing in entry.get('Ingredients', []): # 3.01 for thing in entry.get('Ingredients', []): # 3.01
for category in ('Cargo', 'Raw', 'Manufactured', 'Encoded'): for category in ('Cargo', 'Raw', 'Manufactured', 'Encoded'):
item = self.canonicalise(thing['Name']) item = self.canonicalise(thing['Name'])
@ -1441,7 +1445,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
if self.state[category][material] <= 0: if self.state[category][material] <= 0:
self.state[category].pop(material) self.state[category].pop(material)
elif event_type == 'JoinACrew': elif event_type == 'joinacrew':
self.state['Captain'] = entry['Captain'] self.state['Captain'] = entry['Captain']
self.state['Role'] = 'Idle' self.state['Role'] = 'Idle'
self.planet = None self.planet = None
@ -1457,10 +1461,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Body'] = None self.state['Body'] = None
self.state['BodyType'] = None self.state['BodyType'] = None
elif event_type == 'ChangeCrewRole': elif event_type == 'changecrewrole':
self.state['Role'] = entry['Role'] self.state['Role'] = entry['Role']
elif event_type == 'QuitACrew': elif event_type == 'quitacrew':
self.state['Captain'] = None self.state['Captain'] = None
self.state['Role'] = None self.state['Role'] = None
self.planet = None self.planet = None
@ -1476,7 +1480,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['BodyType'] = None self.state['BodyType'] = None
# TODO: on_foot: Will we get an event after this to know ? # TODO: on_foot: Will we get an event after this to know ?
elif event_type == 'Friends': elif event_type == 'friends':
if entry['Status'] in ('Online', 'Added'): if entry['Status'] in ('Online', 'Added'):
self.state['Friends'].add(entry['Name']) self.state['Friends'].add(entry['Name'])
@ -1484,75 +1488,75 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Friends'].discard(entry['Name']) self.state['Friends'].discard(entry['Name'])
# Try to keep Credits total updated # Try to keep Credits total updated
elif event_type in ('MultiSellExplorationData', 'SellExplorationData'): elif event_type in ('multisellexplorationdata', 'sellexplorationdata'):
self.state['Credits'] += entry.get('TotalEarnings', 0) self.state['Credits'] += entry.get('TotalEarnings', 0)
elif event_type == 'BuyExplorationData': elif event_type == 'buyexplorationdata':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'BuyTradeData': elif event_type == 'buytradedata':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'BuyAmmo': elif event_type == 'buyammo':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'CommunityGoalReward': elif event_type == 'communitygoalreward':
self.state['Credits'] += entry.get('Reward', 0) self.state['Credits'] += entry.get('Reward', 0)
elif event_type == 'CrewHire': elif event_type == 'crewhire':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'FetchRemoteModule': elif event_type == 'fetchremotemodule':
self.state['Credits'] -= entry.get('TransferCost', 0) self.state['Credits'] -= entry.get('TransferCost', 0)
elif event_type == 'MissionAbandoned': elif event_type == 'missionabandoned':
# Is this paid at this point, or just a fine to pay later ? # Is this paid at this point, or just a fine to pay later ?
# self.state['Credits'] -= entry.get('Fine', 0) # self.state['Credits'] -= entry.get('Fine', 0)
pass pass
elif event_type in ('PayBounties', 'PayFines', 'PayLegacyFines'): elif event_type in ('paybounties', 'payfines', 'paylegacyfines'):
self.state['Credits'] -= entry.get('Amount', 0) self.state['Credits'] -= entry.get('Amount', 0)
elif event_type == 'RedeemVoucher': elif event_type == 'redeemvoucher':
self.state['Credits'] += entry.get('Amount', 0) self.state['Credits'] += entry.get('Amount', 0)
elif event_type in ('RefuelAll', 'RefuelPartial', 'Repair', 'RepairAll', 'RestockVehicle'): elif event_type in ('refuelall', 'refuelpartial', 'repair', 'repairall', 'restockvehicle'):
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'SellShipOnRebuy': elif event_type == 'sellshiponrebuy':
self.state['Credits'] += entry.get('ShipPrice', 0) self.state['Credits'] += entry.get('ShipPrice', 0)
elif event_type == 'ShipyardSell': elif event_type == 'shipyardsell':
self.state['Credits'] += entry.get('ShipPrice', 0) self.state['Credits'] += entry.get('ShipPrice', 0)
elif event_type == 'ShipyardTransfer': elif event_type == 'shipyardtransfer':
self.state['Credits'] -= entry.get('TransferPrice', 0) self.state['Credits'] -= entry.get('TransferPrice', 0)
elif event_type == 'PowerplayFastTrack': elif event_type == 'powerplayfasttrack':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
elif event_type == 'PowerplaySalary': elif event_type == 'powerplaysalary':
self.state['Credits'] += entry.get('Amount', 0) self.state['Credits'] += entry.get('Amount', 0)
elif event_type == 'SquadronCreated': elif event_type == 'squadroncreated':
# v30 docs don't actually say anything about credits cost # v30 docs don't actually say anything about credits cost
pass pass
elif event_type == 'CarrierBuy': elif event_type == 'carrierbuy':
self.state['Credits'] -= entry.get('Price', 0) self.state['Credits'] -= entry.get('Price', 0)
elif event_type == 'CarrierBankTransfer': elif event_type == 'carrierbanktransfer':
if (newbal := entry.get('PlayerBalance')): if (newbal := entry.get('PlayerBalance')):
self.state['Credits'] = newbal self.state['Credits'] = newbal
elif event_type == 'CarrierDecommission': elif event_type == 'carrierdecommission':
# v30 doc says nothing about citing the refund amount # v30 doc says nothing about citing the refund amount
pass pass
elif event_type == 'NpcCrewPaidWage': elif event_type == 'npccrewpaidwage':
self.state['Credits'] -= entry.get('Amount', 0) self.state['Credits'] -= entry.get('Amount', 0)
elif event_type == 'Resurrect': elif event_type == 'resurrect':
self.state['Credits'] -= entry.get('Cost', 0) self.state['Credits'] -= entry.get('Cost', 0)
# There should be a `Backpack` event as you 'come to' in the # There should be a `Backpack` event as you 'come to' in the