mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-13 02:30:45 -05:00
dumps after certain date for containers
This commit is contained in:
parent
a69d83b50d
commit
5600ba1783
@ -4,6 +4,9 @@
|
|||||||
"threadPoolingTimeoutMs": 1000,
|
"threadPoolingTimeoutMs": 1000,
|
||||||
"jsonSerializer": "DotNet",
|
"jsonSerializer": "DotNet",
|
||||||
"manualGarbageCollectionCalls": false,
|
"manualGarbageCollectionCalls": false,
|
||||||
|
"dumpProcessorConfig": {
|
||||||
|
"spawnContainerChanceIncludeAfterDate": "2023-08-01 00:00:00"
|
||||||
|
},
|
||||||
"dataStorageConfig": {
|
"dataStorageConfig": {
|
||||||
"dataStorageType": "Memory",
|
"dataStorageType": "Memory",
|
||||||
"fileDataStorageTempLocation": "D:\\Spt Stuff\\Lootgenerator\\Dumps\\cache"
|
"fileDataStorageTempLocation": "D:\\Spt Stuff\\Lootgenerator\\Dumps\\cache"
|
||||||
|
@ -42,6 +42,10 @@ public class Config
|
|||||||
[JsonPropertyName("processorConfig")]
|
[JsonPropertyName("processorConfig")]
|
||||||
public ProcessorConfig ProcessorConfig { get; set; }
|
public ProcessorConfig ProcessorConfig { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("dumpProcessorConfig")]
|
||||||
|
[JsonPropertyName("dumpProcessorConfig")]
|
||||||
|
public DumpProcessorConfig DumpProcessorConfig { get; set; }
|
||||||
|
|
||||||
[JsonProperty("writerConfig")]
|
[JsonProperty("writerConfig")]
|
||||||
[JsonPropertyName("writerConfig")]
|
[JsonPropertyName("writerConfig")]
|
||||||
public WriterConfig WriterConfig { get; set; }
|
public WriterConfig WriterConfig { get; set; }
|
||||||
|
14
Model/Config/DumpProcessorConfig.cs
Normal file
14
Model/Config/DumpProcessorConfig.cs
Normal 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; }
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
using LootDumpProcessor.Storage;
|
using LootDumpProcessor.Serializers.Json.Converters;
|
||||||
using Newtonsoft.Json;
|
using LootDumpProcessor.Storage;
|
||||||
|
|
||||||
namespace LootDumpProcessor.Model.Processing;
|
namespace LootDumpProcessor.Model.Processing;
|
||||||
|
|
||||||
@ -7,7 +7,8 @@ public class PreProcessedLooseLoot : IKeyable
|
|||||||
{
|
{
|
||||||
public Dictionary<string, int> Counts { get; set; }
|
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 IKey ItemProperties { get; set; }
|
||||||
|
|
||||||
public int MapSpawnpointCount { get; set; }
|
public int MapSpawnpointCount { get; set; }
|
||||||
|
@ -78,6 +78,12 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
foreach (var dynamicStaticContainer in StaticLootProcessor.CreateDynamicStaticContainers(data))
|
foreach (var dynamicStaticContainer in StaticLootProcessor.CreateDynamicStaticContainers(data))
|
||||||
{
|
{
|
||||||
lock (mapStaticContainersAggregatedLock)
|
lock (mapStaticContainersAggregatedLock)
|
||||||
@ -88,6 +94,7 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
|
|||||||
mapAggregatedData.Add(dynamicStaticContainer, 1);
|
mapAggregatedData.Add(dynamicStaticContainer, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GCHandler.Collect();
|
GCHandler.Collect();
|
||||||
})
|
})
|
||||||
|
22
Serializers/Json/Converters/NetDateTimeConverter.cs
Normal file
22
Serializers/Json/Converters/NetDateTimeConverter.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using LootDumpProcessor.Storage;
|
||||||
|
|
||||||
namespace LootDumpProcessor.Storage;
|
namespace LootDumpProcessor.Serializers.Json.Converters;
|
||||||
|
|
||||||
public class NetJsonKeyConverter : JsonConverter<IKey?>
|
public class NetJsonKeyConverter : JsonConverter<IKey?>
|
||||||
{
|
{
|
||||||
|
28
Serializers/Json/Converters/NewtonsoftDateTimeConverter.cs
Normal file
28
Serializers/Json/Converters/NewtonsoftDateTimeConverter.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
public class NewtonsoftJsonKeyConverter : JsonConverter<AbstractKey>
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using LootDumpProcessor.Storage;
|
using LootDumpProcessor.Serializers.Json.Converters;
|
||||||
|
|
||||||
namespace LootDumpProcessor.Serializers.Json;
|
namespace LootDumpProcessor.Serializers.Json;
|
||||||
|
|
||||||
@ -12,9 +12,11 @@ public class NetJsonSerializer : IJsonSerializer
|
|||||||
Converters =
|
Converters =
|
||||||
{
|
{
|
||||||
new NetJsonKeyConverter(),
|
new NetJsonKeyConverter(),
|
||||||
new JsonStringEnumConverter()
|
new JsonStringEnumConverter(),
|
||||||
|
new NetDateTimeConverter()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public string Serialize<T>(T obj)
|
public string Serialize<T>(T obj)
|
||||||
{
|
{
|
||||||
return JsonSerializer.Serialize(obj, _serializeOptions);
|
return JsonSerializer.Serialize(obj, _serializeOptions);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using LootDumpProcessor.Storage;
|
using LootDumpProcessor.Serializers.Json.Converters;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
@ -11,7 +11,8 @@ public class NewtonsoftJsonSerializer : IJsonSerializer
|
|||||||
Converters =
|
Converters =
|
||||||
{
|
{
|
||||||
new NewtonsoftJsonKeyConverter(),
|
new NewtonsoftJsonKeyConverter(),
|
||||||
new StringEnumConverter()
|
new StringEnumConverter(),
|
||||||
|
new NewtonsoftDateTimeConverter()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
32
Utils/FileDateParser.cs
Normal file
32
Utils/FileDateParser.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user