fix bug with unknown map types

This commit is contained in:
Styrr 2022-07-17 16:38:31 +02:00
parent 0b58147250
commit f47bc9a6a6

View File

@ -34,7 +34,8 @@ with open(f'config/{config["server"]["map_directory_mapping_yaml"]}', 'r') as fi
directory_mapping = yaml.load(fin, Loader=yaml.FullLoader) directory_mapping = yaml.load(fin, Loader=yaml.FullLoader)
tarkov_server_dir = Path(config["server"]["location"]) tarkov_server_dir = Path(config["server"]["location"])
loot_dump_archive = Path(config["archives"]["target_folder"]) / config["archives"]["loot_filename"] loot_dump_archive = Path(config["archives"]["target_folder"]) / config["archives"][
"loot_filename"]
def hash_file(text): def hash_file(text):
@ -51,10 +52,15 @@ def parse_dumps(input):
text = bio.read() text = bio.read()
fi = json.loads(text) fi = json.loads(text)
threshold_date = datetime.datetime.strptime(
directory_mapping[fi["data"]["Name"]]["threshold_date"], try:
"%Y-%m-%d" threshold_date = datetime.datetime.strptime(
) directory_mapping[fi["data"]["Name"]]["threshold_date"],
"%Y-%m-%d"
)
except TypeError:
print(fi["data"]["Name"])
return None
datestr = fname.split(".getLocalloot_")[-1].split(".")[0] datestr = fname.split(".getLocalloot_")[-1].split(".")[0]
date = datetime.datetime.strptime(datestr, "%Y-%m-%d_%H-%M-%S") date = datetime.datetime.strptime(datestr, "%Y-%m-%d_%H-%M-%S")
@ -105,7 +111,8 @@ def main():
with futures.ProcessPoolExecutor() as executor: with futures.ProcessPoolExecutor() as executor:
print("Gathering dumps") print("Gathering dumps")
for result in list( for result in list(
tqdm(executor.map(parse_dumps, archive.read(archive_files).items()), total=len(archive_files))): tqdm(executor.map(parse_dumps, archive.read(archive_files).items()),
total=len(archive_files))):
if result is not None: if result is not None:
gather_loot_results.append(result) gather_loot_results.append(result)
# get the newest dump per map # get the newest dump per map
@ -127,7 +134,8 @@ def main():
# remove duplicate dumps # remove duplicate dumps
time_start = time.time() time_start = time.time()
gather_loot_results = sorted(gather_loot_results, key=lambda x: x["basic_info"]["filehash"]) gather_loot_results = sorted(gather_loot_results,
key=lambda x: x["basic_info"]["filehash"])
gather_loot_results_unique = [] gather_loot_results_unique = []
for _, g in groupby(gather_loot_results, key=lambda x: x["basic_info"]["filehash"]): for _, g in groupby(gather_loot_results, key=lambda x: x["basic_info"]["filehash"]):
g = list(g) g = list(g)
@ -145,11 +153,13 @@ def main():
# Map Reduce # Map Reduce
print("Map reducing dumps", end="; ") print("Map reducing dumps", end="; ")
time_start = time.time() time_start = time.time()
gather_loot_results_unique = sorted(gather_loot_results_unique, key=lambda x: x["basic_info"]["map"]) gather_loot_results_unique = sorted(gather_loot_results_unique,
key=lambda x: x["basic_info"]["map"])
looseloot_counts = {} looseloot_counts = {}
container_counts = [] container_counts = []
map_counts = {} map_counts = {}
for mapi, g in groupby(gather_loot_results_unique, key=lambda x: x["basic_info"]["map"]): for mapi, g in groupby(gather_loot_results_unique,
key=lambda x: x["basic_info"]["map"]):
g = list(g) g = list(g)
map_counts[mapi] = len(g) map_counts[mapi] = len(g)
looseloot_counts[mapi] = {} looseloot_counts[mapi] = {}
@ -170,7 +180,8 @@ def main():
for k, v in gi["looseloot"]["itemproperties"].items(): for k, v in gi["looseloot"]["itemproperties"].items():
looseloot_counts[mapi]["itemproperties"][k] += v looseloot_counts[mapi]["itemproperties"][k] += v
looseloot_counts[mapi]["map_spawnpoint_count"] += [gi["looseloot"]["map_spawnpoint_count"]] looseloot_counts[mapi]["map_spawnpoint_count"] += [
gi["looseloot"]["map_spawnpoint_count"]]
del gather_loot_results_unique del gather_loot_results_unique
print(f"took {time.time() - time_start} seconds.") print(f"took {time.time() - time_start} seconds.")
@ -188,7 +199,8 @@ def main():
targets = [datename_tuple[1] for _, datename_tuple in map_files.items()] targets = [datename_tuple[1] for _, datename_tuple in map_files.items()]
targets = sorted(targets) targets = sorted(targets)
for fname, bio in archive.read(targets).items(): for fname, bio in archive.read(targets).items():
mapi, static_containers_mi = static_loot_processor.create_static_containers(bio) mapi, static_containers_mi = static_loot_processor.create_static_containers(
bio)
static_containers[mapi] = static_containers_mi static_containers[mapi] = static_containers_mi
print(f"took {time.time() - time_start} seconds.") print(f"took {time.time() - time_start} seconds.")
with open(static_loot_dir / "staticContainers.json", "w") as fout: with open(static_loot_dir / "staticContainers.json", "w") as fout:
@ -205,7 +217,8 @@ def main():
# Static loot distribution # Static loot distribution
time_start = time.time() time_start = time.time()
print(f"Creating \"static container\"", end='; ') print(f"Creating \"static container\"", end='; ')
static_loot_distribution = static_loot_processor.create_static_loot_distribution(container_counts) static_loot_distribution = static_loot_processor.create_static_loot_distribution(
container_counts)
print(f"took {time.time() - time_start} seconds.") print(f"took {time.time() - time_start} seconds.")
with open(static_loot_dir / "staticLoot.json", 'w') as fout: with open(static_loot_dir / "staticLoot.json", 'w') as fout:
json.dump(static_loot_distribution, fout, indent=1) json.dump(static_loot_distribution, fout, indent=1)
@ -217,7 +230,8 @@ def main():
) )
time_start = time.time() time_start = time.time()
print(f"Calculating \"loose loot\" distribution", end='; ') print(f"Calculating \"loose loot\" distribution", end='; ')
loose_loot_distribution = loose_loot_processor.create_loose_loot_distribution(map_counts, looseloot_counts) loose_loot_distribution = loose_loot_processor.create_loose_loot_distribution(
map_counts, looseloot_counts)
print(f"took {time.time() - time_start} seconds") print(f"took {time.time() - time_start} seconds")
for mi, cnt in map_counts.items(): for mi, cnt in map_counts.items():