0
0
mirror of https://github.com/sp-tarkov/loot-dump-processor.git synced 2025-02-12 17:30:43 -05:00

dumps after certain date for containers

This commit is contained in:
Alex 2023-08-13 17:26:49 +01:00
parent a69d83b50d
commit 5600ba1783
12 changed files with 132 additions and 16 deletions

View File

@ -4,6 +4,9 @@
"threadPoolingTimeoutMs": 1000,
"jsonSerializer": "DotNet",
"manualGarbageCollectionCalls": false,
"dumpProcessorConfig": {
"spawnContainerChanceIncludeAfterDate": "2023-08-01 00:00:00"
},
"dataStorageConfig": {
"dataStorageType": "Memory",
"fileDataStorageTempLocation": "D:\\Spt Stuff\\Lootgenerator\\Dumps\\cache"

View File

@ -41,6 +41,10 @@ public class Config
[JsonProperty("processorConfig")]
[JsonPropertyName("processorConfig")]
public ProcessorConfig ProcessorConfig { get; set; }
[JsonProperty("dumpProcessorConfig")]
[JsonPropertyName("dumpProcessorConfig")]
public DumpProcessorConfig DumpProcessorConfig { get; set; }
[JsonProperty("writerConfig")]
[JsonPropertyName("writerConfig")]

View File

@ -0,0 +1,14 @@
using System.Text.Json.Serialization;
using LootDumpProcessor.Serializers.Json.Converters;
using Newtonsoft.Json;
namespace LootDumpProcessor.Model.Config;
public class DumpProcessorConfig
{
[JsonProperty("spawnContainerChanceIncludeAfterDate")]
[JsonPropertyName("spawnContainerChanceIncludeAfterDate")]
[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftDateTimeConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(NetDateTimeConverter))]
public DateTime SpawnContainerChanceIncludeAfterDate { get; set; }
}

View File

@ -1,5 +1,5 @@
using LootDumpProcessor.Storage;
using Newtonsoft.Json;
using LootDumpProcessor.Serializers.Json.Converters;
using LootDumpProcessor.Storage;
namespace LootDumpProcessor.Model.Processing;
@ -7,7 +7,8 @@ public class PreProcessedLooseLoot : IKeyable
{
public Dictionary<string, int> Counts { get; set; }
[JsonConverter(typeof(NewtonsoftJsonKeyConverter))]
[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftJsonKeyConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(NetJsonKeyConverter))]
public IKey ItemProperties { get; set; }
public int MapSpawnpointCount { get; set; }

View File

@ -78,14 +78,21 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
}
}
foreach (var dynamicStaticContainer in StaticLootProcessor.CreateDynamicStaticContainers(data))
// Only process the dump file if the date is higher (after) the configuration date
if (FileDateParser.TryParseFileDate(dumped.BasicInfo.FileName, out var fileDate) &&
fileDate.HasValue &&
fileDate.Value > LootDumpProcessorContext.GetConfig().DumpProcessorConfig
.SpawnContainerChanceIncludeAfterDate)
{
lock (mapStaticContainersAggregatedLock)
foreach (var dynamicStaticContainer in StaticLootProcessor.CreateDynamicStaticContainers(data))
{
if (mapAggregatedData.ContainsKey(dynamicStaticContainer))
mapAggregatedData[dynamicStaticContainer] += 1;
else
mapAggregatedData.Add(dynamicStaticContainer, 1);
lock (mapStaticContainersAggregatedLock)
{
if (mapAggregatedData.ContainsKey(dynamicStaticContainer))
mapAggregatedData[dynamicStaticContainer] += 1;
else
mapAggregatedData.Add(dynamicStaticContainer, 1);
}
}
}

View File

@ -0,0 +1,22 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace LootDumpProcessor.Serializers.Json.Converters;
public class NetDateTimeConverter : JsonConverter<DateTime>
{
private static string _dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var stringDate = reader.GetString() ?? "";
if (!DateTime.TryParseExact(stringDate, _dateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
throw new Exception($"Invalid value for DateTime format: {_dateTimeFormat}");
return parsedDate;
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString(_dateTimeFormat));
}
}

View File

@ -1,7 +1,8 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using LootDumpProcessor.Storage;
namespace LootDumpProcessor.Storage;
namespace LootDumpProcessor.Serializers.Json.Converters;
public class NetJsonKeyConverter : JsonConverter<IKey?>
{

View File

@ -0,0 +1,28 @@
using System.Globalization;
using Newtonsoft.Json;
namespace LootDumpProcessor.Serializers.Json.Converters;
public class NewtonsoftDateTimeConverter : JsonConverter<DateTime>
{
private static string _dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString(_dateTimeFormat));
}
public override DateTime ReadJson(
JsonReader reader,
Type objectType,
DateTime existingValue,
bool hasExistingValue,
JsonSerializer serializer
)
{
var stringDate = reader.Value?.ToString() ?? "";
if (!DateTime.TryParseExact(stringDate, _dateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
throw new Exception($"Invalid value for DateTime format: {_dateTimeFormat}");
return parsedDate;
}
}

View File

@ -1,6 +1,7 @@
using Newtonsoft.Json;
using LootDumpProcessor.Storage;
using Newtonsoft.Json;
namespace LootDumpProcessor.Storage;
namespace LootDumpProcessor.Serializers.Json.Converters;
public class NewtonsoftJsonKeyConverter : JsonConverter<AbstractKey>
{

View File

@ -1,6 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using LootDumpProcessor.Storage;
using LootDumpProcessor.Serializers.Json.Converters;
namespace LootDumpProcessor.Serializers.Json;
@ -12,9 +12,11 @@ public class NetJsonSerializer : IJsonSerializer
Converters =
{
new NetJsonKeyConverter(),
new JsonStringEnumConverter()
new JsonStringEnumConverter(),
new NetDateTimeConverter()
}
};
public string Serialize<T>(T obj)
{
return JsonSerializer.Serialize(obj, _serializeOptions);

View File

@ -1,4 +1,4 @@
using LootDumpProcessor.Storage;
using LootDumpProcessor.Serializers.Json.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@ -11,7 +11,8 @@ public class NewtonsoftJsonSerializer : IJsonSerializer
Converters =
{
new NewtonsoftJsonKeyConverter(),
new StringEnumConverter()
new StringEnumConverter(),
new NewtonsoftDateTimeConverter()
}
};

32
Utils/FileDateParser.cs Normal file
View File

@ -0,0 +1,32 @@
using System.Text.RegularExpressions;
namespace LootDumpProcessor.Process.Processor;
public static class FileDateParser
{
private static readonly Regex _fileDateRegex =
new(".*([0-9]{4})[-]([0-9]{2})[-]([0-9]{2})[_]([0-9]{2})[-]([0-9]{2})[-]([0-9]{2}).*");
public static bool TryParseFileDate(string fileName, out DateTime? date)
{
date = null;
if (!_fileDateRegex.IsMatch(fileName))
return false;
var match = _fileDateRegex.Match(fileName);
var year = match.Groups[1].Value;
var month = match.Groups[2].Value;
var day = match.Groups[3].Value;
var hour = match.Groups[4].Value;
var mins = match.Groups[5].Value;
var secs = match.Groups[6].Value;
date = new DateTime(
int.Parse(year),
int.Parse(month),
int.Parse(day),
int.Parse(hour),
int.Parse(mins),
int.Parse(secs)
);
return true;
}
}