mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-13 06:50:45 -05:00
Refactored static loot processor to process maps in parallel
This commit is contained in:
parent
7eb932f603
commit
0af0c9f9c3
@ -193,7 +193,7 @@ public class MultithreadSteppedDumpProcessor(
|
|||||||
LoggerFactory.GetInstance().Log("Processing ammo distribution", LogLevel.Info);
|
LoggerFactory.GetInstance().Log("Processing ammo distribution", LogLevel.Info);
|
||||||
|
|
||||||
var staticAmmo = new ConcurrentDictionary<string, IReadOnlyDictionary<string, List<AmmoDistribution>>>();
|
var staticAmmo = new ConcurrentDictionary<string, IReadOnlyDictionary<string, List<AmmoDistribution>>>();
|
||||||
Parallel.ForEach(dumpProcessData.ContainerCounts.Keys, (mapId) =>
|
Parallel.ForEach(dumpProcessData.ContainerCounts.Keys, mapId =>
|
||||||
{
|
{
|
||||||
var preProcessedStaticLoots = dumpProcessData.ContainerCounts[mapId];
|
var preProcessedStaticLoots = dumpProcessData.ContainerCounts[mapId];
|
||||||
var ammoDistribution = _ammoProcessor.CreateAmmoDistribution(mapId, preProcessedStaticLoots);
|
var ammoDistribution = _ammoProcessor.CreateAmmoDistribution(mapId, preProcessedStaticLoots);
|
||||||
@ -207,10 +207,19 @@ public class MultithreadSteppedDumpProcessor(
|
|||||||
|
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
||||||
LoggerFactory.GetInstance().Log("Processing static loot distribution", LogLevel.Info);
|
LoggerFactory.GetInstance().Log("Processing static loot distribution", LogLevel.Info);
|
||||||
|
|
||||||
|
var staticLoot = new ConcurrentDictionary<string, IReadOnlyDictionary<string, StaticItemDistribution>>();
|
||||||
|
Parallel.ForEach(dumpProcessData.ContainerCounts.Keys, mapId =>
|
||||||
|
{
|
||||||
|
var preProcessedStaticLoots = dumpProcessData.ContainerCounts[mapId];
|
||||||
|
var staticLootDistribution =
|
||||||
|
_staticLootProcessor.CreateStaticLootDistribution(mapId, preProcessedStaticLoots);
|
||||||
|
staticLoot[mapId] = staticLootDistribution;
|
||||||
|
});
|
||||||
// Static loot distribution
|
// Static loot distribution
|
||||||
output.Add(
|
output.Add(
|
||||||
OutputFileType.StaticLoot,
|
OutputFileType.StaticLoot,
|
||||||
_staticLootProcessor.CreateStaticLootDistribution(dumpProcessData.ContainerCounts, staticContainers)
|
staticLoot
|
||||||
);
|
);
|
||||||
|
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using LootDumpProcessor.Model;
|
using LootDumpProcessor.Model;
|
||||||
using LootDumpProcessor.Model.Output;
|
using LootDumpProcessor.Model.Output;
|
||||||
using LootDumpProcessor.Model.Output.StaticContainer;
|
|
||||||
using LootDumpProcessor.Model.Processing;
|
using LootDumpProcessor.Model.Processing;
|
||||||
|
|
||||||
namespace LootDumpProcessor.Process.Processor.v2.StaticLootProcessor;
|
namespace LootDumpProcessor.Process.Processor.v2.StaticLootProcessor;
|
||||||
@ -9,7 +8,7 @@ public interface IStaticLootProcessor
|
|||||||
{
|
{
|
||||||
IReadOnlyList<PreProcessedStaticLoot> PreProcessStaticLoot(IReadOnlyList<Template> staticLoot);
|
IReadOnlyList<PreProcessedStaticLoot> PreProcessStaticLoot(IReadOnlyList<Template> staticLoot);
|
||||||
|
|
||||||
IReadOnlyDictionary<string, IReadOnlyDictionary<string, StaticItemDistribution>> CreateStaticLootDistribution(
|
IReadOnlyDictionary<string, StaticItemDistribution> CreateStaticLootDistribution(
|
||||||
IReadOnlyDictionary<string, List<PreProcessedStaticLoot>> containerCounts,
|
string mapName,
|
||||||
IReadOnlyDictionary<string, MapStaticLoot> staticContainers);
|
IReadOnlyList<PreProcessedStaticLoot> containers);
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
using LootDumpProcessor.Model;
|
using LootDumpProcessor.Model;
|
||||||
using LootDumpProcessor.Model.Output;
|
using LootDumpProcessor.Model.Output;
|
||||||
using LootDumpProcessor.Model.Output.StaticContainer;
|
|
||||||
using LootDumpProcessor.Model.Processing;
|
using LootDumpProcessor.Model.Processing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
@ -43,48 +42,39 @@ public class StaticLootProcessor(ILogger<StaticLootProcessor> logger) : IStaticL
|
|||||||
return nonWeaponContainers;
|
return nonWeaponContainers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyDictionary<string, IReadOnlyDictionary<string, StaticItemDistribution>>
|
public IReadOnlyDictionary<string, StaticItemDistribution> CreateStaticLootDistribution(
|
||||||
CreateStaticLootDistribution(
|
string mapName,
|
||||||
IReadOnlyDictionary<string, List<PreProcessedStaticLoot>> containerCounts,
|
IReadOnlyList<PreProcessedStaticLoot> containers)
|
||||||
IReadOnlyDictionary<string, MapStaticLoot> staticContainers)
|
|
||||||
{
|
{
|
||||||
var allMapsStaticLootDistribution =
|
var staticLootDistribution = new Dictionary<string, StaticItemDistribution>();
|
||||||
new Dictionary<string, IReadOnlyDictionary<string, StaticItemDistribution>>();
|
var uniqueContainerTypes = containers.Select(container => container.Type).Distinct();
|
||||||
|
|
||||||
foreach (var (mapName, containers) in containerCounts)
|
foreach (var containerType in uniqueContainerTypes)
|
||||||
{
|
{
|
||||||
var staticLootDistribution = new Dictionary<string, StaticItemDistribution>();
|
var selectedContainers = containers.Where(container => container.Type == containerType).ToArray();
|
||||||
var uniqueContainerTypes = containers.Select(container => container.Type).Distinct();
|
var itemCounts = GetItemCountsInContainers(selectedContainers);
|
||||||
|
var itemDistribution = GenerateItemDistribution(selectedContainers);
|
||||||
|
|
||||||
foreach (var containerType in uniqueContainerTypes)
|
staticLootDistribution[containerType] = new StaticItemDistribution
|
||||||
{
|
{
|
||||||
var selectedContainers = containers.Where(container => container.Type == containerType).ToArray();
|
ItemCountDistribution = itemCounts
|
||||||
var itemCounts = GetItemCountsInContainers(selectedContainers);
|
.GroupBy(count => count)
|
||||||
var itemDistribution = GenerateItemDistribution(selectedContainers);
|
.Select(group => new ItemCountDistribution
|
||||||
|
{
|
||||||
|
Count = group.Key,
|
||||||
|
RelativeProbability = group.Count()
|
||||||
|
})
|
||||||
|
.ToList(),
|
||||||
|
ItemDistribution = itemDistribution
|
||||||
|
};
|
||||||
|
|
||||||
staticLootDistribution[containerType] = new StaticItemDistribution
|
_logger.LogDebug(
|
||||||
{
|
"Processed static loot distribution for ContainerType `{ContainerType}` in Map `{MapName}`.",
|
||||||
ItemCountDistribution = itemCounts
|
containerType, mapName);
|
||||||
.GroupBy(count => count)
|
|
||||||
.Select(group => new ItemCountDistribution
|
|
||||||
{
|
|
||||||
Count = group.Key,
|
|
||||||
RelativeProbability = group.Count()
|
|
||||||
})
|
|
||||||
.ToList(),
|
|
||||||
ItemDistribution = itemDistribution
|
|
||||||
};
|
|
||||||
|
|
||||||
_logger.LogDebug(
|
|
||||||
"Processed static loot distribution for ContainerType {ContainerType} in Map {MapName}.",
|
|
||||||
containerType, mapName);
|
|
||||||
}
|
|
||||||
|
|
||||||
allMapsStaticLootDistribution[mapName] = staticLootDistribution;
|
|
||||||
_logger.LogInformation("Created static loot distribution for Map {MapName}.", mapName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return allMapsStaticLootDistribution;
|
_logger.LogInformation("Created static loot distribution for Map `{MapName}`.", mapName);
|
||||||
|
return staticLootDistribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IReadOnlyList<int> GetItemCountsInContainers(IReadOnlyList<PreProcessedStaticLoot> selectedContainers)
|
private static IReadOnlyList<int> GetItemCountsInContainers(IReadOnlyList<PreProcessedStaticLoot> selectedContainers)
|
||||||
@ -112,6 +102,6 @@ public class StaticLootProcessor(ILogger<StaticLootProcessor> logger) : IStaticL
|
|||||||
{
|
{
|
||||||
Tpl = kv.Key,
|
Tpl = kv.Key,
|
||||||
RelativeProbability = kv.Value
|
RelativeProbability = kv.Value
|
||||||
}).ToArray();
|
}).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user