From 2060233ae1bd6d0237cc781ea85de45aa0083286 Mon Sep 17 00:00:00 2001 From: Dima Date: Sun, 21 Mar 2021 20:05:50 -0400 Subject: [PATCH 1/2] Separate count and fir_count and convert to dict 1. Separate count and found in raid count for quest items to prevent overwriting in case an item has separate FiR and not FiR requirements. No items currently seem to have both a fir and non-fir requirement, but seems like this can't hurt rather than using a flag which can overwrite state. 2. Replace both lists with dictionaries. This removes the nested lookup loops when building the files and allows you to look up items in constant time. --- scanner.py | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/scanner.py b/scanner.py index 3d9fc52..7994262 100644 --- a/scanner.py +++ b/scanner.py @@ -22,8 +22,8 @@ def Import(): questsOutput = outputDir + "/quest.json" hideoutOutput = outputDir + "/hideout.json" - questItemList = [] - hideoutItemList = [] + questItemList = {} + hideoutItemList = {} # Create quest object for line in questText.splitlines(): @@ -36,24 +36,16 @@ def Import(): if (match): matchSplit = match.groups()[0] .split('|') if (len(matchSplit) > 0): - # If the item already exists, make sure findInRaid is set if it should be for any of them - itemExists = False - for obj in questItemList: - if obj["name"] == matchSplit[0]: - itemExists = True - obj["count"] = obj["count"] + GetAmount(line) - if (item["raid"] or findInRaid): - item["raid"] = True - - # Only add items once - if (not itemExists): + name = matchSplit[0] + if name in questItemList: + item = questItemList[name] + else: item = {} - item["wiki"] = "https://escapefromtarkov.gamepedia.com/" + matchSplit[0] - item["name"] = matchSplit[0] - item["count"] = GetAmount(line) - - item["raid"] = findInRaid - questItemList.append(item) + item["name"] = name + item["wiki"] = "https://escapefromtarkov.gamepedia.com/" + name + questItemList[name] = item + countKey = "fir_count" if findInRaid else "count" + item[countKey] = item.get(countKey) or 0 + GetAmount(line) # Create hideout object for line in hideoutText.splitlines(): @@ -62,19 +54,15 @@ def Import(): if (match): matchSplit = match.groups()[0] .split('|') if (len(matchSplit) > 0): - itemExists = False - for obj in hideoutItemList: - if obj["name"] == matchSplit[0]: - itemExists = True - obj["count"] = obj["count"] + GetAmount(line) - - if not itemExists: + name = matchSplit[0] + if name in hideoutItemList: + item = hideoutItemList[name] + else: item = {} - item["wiki"] = "https://escapefromtarkov.gamepedia.com/" + matchSplit[0] - item["name"] = matchSplit[0] - item["count"] = GetAmount(line) - - hideoutItemList.append(item) + hideoutItemList[name] = item + item["name"] = name + item["wiki"] = "https://escapefromtarkov.gamepedia.com/" + name + item["count"] = item.get("count") or 0 + GetAmount(line) # Create quest.json if not os.path.exists(os.path.dirname(questsOutput)): From 0644405975030e6dec9954a6130b48e723c0dc24 Mon Sep 17 00:00:00 2001 From: Dima Vartanian Date: Sun, 21 Mar 2021 23:25:57 -0400 Subject: [PATCH 2/2] Convert names to lower case to fix duplicate rows due to inconsistent wiki casing. --- scanner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scanner.py b/scanner.py index 7994262..e223dc1 100644 --- a/scanner.py +++ b/scanner.py @@ -36,7 +36,7 @@ def Import(): if (match): matchSplit = match.groups()[0] .split('|') if (len(matchSplit) > 0): - name = matchSplit[0] + name = matchSplit[0].lower() if name in questItemList: item = questItemList[name] else: @@ -54,7 +54,7 @@ def Import(): if (match): matchSplit = match.groups()[0] .split('|') if (len(matchSplit) > 0): - name = matchSplit[0] + name = matchSplit[0].lower() if name in hideoutItemList: item = hideoutItemList[name] else: