Обновление вывода и временное отключение работы с актёрами
This commit is contained in:
+8
-1
@@ -15,6 +15,13 @@
|
||||
return this.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Фильтрация требуемых папок компендиума.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public CompendiumFolderCollection Filter()
|
||||
{
|
||||
return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+51
-24
@@ -35,6 +35,38 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
/// </summary>
|
||||
public Dictionary<string, SchemaNode> TypeSchemas = [];
|
||||
|
||||
private readonly string[] _equipmentTypes = ["equipment", "armor", "backpack", "consumable", "kit", "shield", "treasure", "weapon"];
|
||||
|
||||
private SchemaNode GetPackSchema(CompendiumFolder folder)
|
||||
{
|
||||
if (!PackSchemas.TryGetValue(folder, out SchemaNode? value))
|
||||
{
|
||||
value = new SchemaNode()
|
||||
{
|
||||
Resolver = Resolver,
|
||||
Path = folder.Name
|
||||
};
|
||||
PackSchemas[folder] = value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private SchemaNode GetTypeSchema(string key)
|
||||
{
|
||||
if (!TypeSchemas.TryGetValue(key, out SchemaNode? value))
|
||||
{
|
||||
value = new SchemaNode()
|
||||
{
|
||||
Resolver = Resolver,
|
||||
Path = key
|
||||
};
|
||||
TypeSchemas[key] = value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение набора схем, к которым относится проверяемый объект.
|
||||
/// </summary>
|
||||
@@ -43,27 +75,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
/// <returns></returns>
|
||||
protected List<SchemaNode> GetItemSchemas(CompendiumFolder folder, string? itemType)
|
||||
{
|
||||
if (!PackSchemas.ContainsKey(folder))
|
||||
{
|
||||
PackSchemas[folder] = new SchemaNode()
|
||||
{
|
||||
Resolver = Resolver,
|
||||
Path = folder.Name
|
||||
};
|
||||
}
|
||||
|
||||
var key = folder.Type.ToString() + (itemType is not null ? $".{itemType}" : "");
|
||||
|
||||
if (!TypeSchemas.ContainsKey(key))
|
||||
if (_equipmentTypes.Contains(itemType))
|
||||
{
|
||||
TypeSchemas[key] = new SchemaNode()
|
||||
{
|
||||
Resolver = Resolver,
|
||||
Path = key
|
||||
};
|
||||
return [GetPackSchema(folder), GetTypeSchema(key), GetTypeSchema("Equipment")];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [GetPackSchema(folder), GetTypeSchema(key)];
|
||||
}
|
||||
|
||||
return [PackSchemas[folder], TypeSchemas[key]];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,14 +182,14 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
/// <param name="schema">Сохраняемая схема.</param>
|
||||
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
||||
{
|
||||
var invalids = System.IO.Path.GetInvalidFileNameChars();
|
||||
var invalids = Path.GetInvalidFileNameChars();
|
||||
var fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
||||
|
||||
var path = Path.Combine(dir, fileName + ".txt");
|
||||
var path = Path.Combine(dir, fileName + ".yaml");
|
||||
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
|
||||
if (!Directory.Exists(dirPath))
|
||||
if (dirPath is not null && !Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.CreateDirectory(dirPath);
|
||||
}
|
||||
@@ -177,10 +198,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
|
||||
schema.Beautify();
|
||||
|
||||
writer.WriteLine(name);
|
||||
writer.WriteLine($"Different values: {schema.Values}");
|
||||
writer.WriteLine("=====================================");
|
||||
writer.Write(schema.ToString());
|
||||
writer.WriteLine(SchemaNode.FormatYaml(new Dictionary<string, string>()
|
||||
{
|
||||
["name"] = name,
|
||||
["values"] = schema.Values.ToString()
|
||||
}, schema.Types[0].GetYamlData()));
|
||||
|
||||
//writer.WriteLine(name);
|
||||
//writer.WriteLine($"Different values: {schema.Values}");
|
||||
//writer.WriteLine("=====================================");
|
||||
//writer.Write(schema.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
ProcessPackFolders((JArray)innerFolders!, folder);
|
||||
}
|
||||
}
|
||||
|
||||
Collection = Collection.Filter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<LangVersion>13.0</LangVersion>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
@@ -10,6 +11,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dotenv.net" Version="3.2.1" />
|
||||
<PackageReference Include="Goblinfactory.ProgressBar" Version="1.0.0" />
|
||||
<PackageReference Include="linq2db" Version="5.4.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -139,24 +139,31 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var result = new Dictionary<string, string>() {
|
||||
["type"] = GetTypeName(),
|
||||
["path"] = Path,
|
||||
["is_null"] = IsNullable ? "true" : "false",
|
||||
["values"] = Values.ToString()
|
||||
};
|
||||
|
||||
if (IsSimple)
|
||||
{
|
||||
return Types[0].ToString();
|
||||
return FormatYaml(result, Types[0].GetYamlData());
|
||||
}
|
||||
|
||||
if (Types.Count == 0)
|
||||
{
|
||||
return "empty";
|
||||
return FormatYaml(result, new() { ["is_empty"] = "true" });
|
||||
}
|
||||
|
||||
List<string> result = ["mixed"];
|
||||
List<string> types = [];
|
||||
|
||||
foreach (var type in Types)
|
||||
{
|
||||
result.Add(AbstractSchemaType.Indent(type?.ToString() ?? ""));
|
||||
types.Add(Indent(type?.ToString() ?? ""));
|
||||
}
|
||||
|
||||
return string.Join("\n" + AbstractSchemaType.Tab, result);
|
||||
return FormatYaml(result, new() { ["types"] = "- " + string.Join("\r\n- ", types) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -169,5 +176,68 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
type.Beautify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Отступ для строкового представления.
|
||||
/// </summary>
|
||||
public const string Tab = " ";
|
||||
|
||||
/// <summary>
|
||||
/// Предел количество отображаемых элементов.
|
||||
/// </summary>
|
||||
public const int ElementLimit = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Увеличение отступа строки.
|
||||
/// </summary>
|
||||
/// <param name="text">Изменяемая строка.</param>
|
||||
/// <returns>Строка с добавленными отступами.</returns>
|
||||
public static string Indent(string text)
|
||||
{
|
||||
return text.Replace("\r\n", "\r\n" + Tab);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Форматирование данных в YAML.
|
||||
/// </summary>
|
||||
/// <param name="input">Словарь данных.</param>
|
||||
/// <returns>Строка форматированных данных</returns>
|
||||
public static string FormatYaml(params List<Dictionary<string, string>> input)
|
||||
{
|
||||
var result = "";
|
||||
|
||||
foreach (var kvp in MergeDictionaries(input))
|
||||
{
|
||||
var val = kvp.Value.Contains("\r\n") ? $"\r\n{Tab}{Indent(kvp.Value)}" : kvp.Value;
|
||||
|
||||
result += $"{kvp.Key}: {val}\r\n";
|
||||
}
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> MergeDictionaries(params List<Dictionary<string, string>> input)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
|
||||
foreach (var item in input)
|
||||
{
|
||||
foreach (var kvp in item)
|
||||
{
|
||||
if (result.ContainsKey(kvp.Key))
|
||||
{
|
||||
result[kvp.Key] = kvp.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,33 +47,19 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
/// <returns>Строковое представоение типа элемента</returns>
|
||||
public abstract string GetTypeName();
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных для форматирования в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Словарь данных</returns>
|
||||
public abstract Dictionary<string, string> GetYamlData();
|
||||
|
||||
/// <summary>
|
||||
/// Полное строковое представление элемента.
|
||||
/// </summary>
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetTypeName()} {{{Parent.Path}}}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отступ для строкового представления.
|
||||
/// </summary>
|
||||
public const string Tab = " ";
|
||||
|
||||
/// <summary>
|
||||
/// Предел количество отображаемых элементов.
|
||||
/// </summary>
|
||||
public const int ElementLimit = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Увеличение отступа строки.
|
||||
/// </summary>
|
||||
/// <param name="text">Изменяемая строка.</param>
|
||||
/// <returns>Строка с добавленными отступами.</returns>
|
||||
public static string Indent(string text)
|
||||
{
|
||||
return text.Replace("\n", "\n" + Tab);
|
||||
return SchemaNode.FormatYaml(GetYamlData());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,16 +73,17 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Полное строковое представление элемента.
|
||||
/// Получение данных для форматирования в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
/// <returns>Словарь данных</returns>
|
||||
public override Dictionary<string, string> GetYamlData()
|
||||
{
|
||||
return string.Join("\n" + Tab, [
|
||||
base.ToString(),
|
||||
$"Length: min={MinCount} max={MaxCount}",
|
||||
"Value type: " + Indent(ElementSchema.ToString())
|
||||
]);
|
||||
return new()
|
||||
{
|
||||
["min_count"] = MinCount.ToString(),
|
||||
["max_count"] = MaxCount.ToString(),
|
||||
["value_type"] = ElementSchema.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,16 +62,16 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Полное строковое представление элемента.
|
||||
/// Получение данных для форматирования в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
/// <returns>Словарь данных</returns>
|
||||
public override Dictionary<string, string> GetYamlData()
|
||||
{
|
||||
return string.Join("\n" + Tab, [
|
||||
base.ToString(),
|
||||
"#key : " + Indent(KeyNode.ToString()),
|
||||
"#value : " + Indent(ItemNode.ToString())
|
||||
]);
|
||||
return new Dictionary<string, string>()
|
||||
{
|
||||
["_key"] = KeyNode.ToString(),
|
||||
["_value"] = ItemNode.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,5 +41,15 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
return "ignore";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных для форматирования в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Словарь данных</returns>
|
||||
public override Dictionary<string, string> GetYamlData()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,26 +84,39 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Полное строковое представление элемента.
|
||||
/// Получение данных для форматирования структуры в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
/// <returns>Словарь данных</returns>
|
||||
public Dictionary<string, string> GetSchemaYaml()
|
||||
{
|
||||
List<string> rows = [base.ToString()];
|
||||
var result = new Dictionary<string, string>();
|
||||
|
||||
foreach (var field in Fields)
|
||||
{
|
||||
var s = field.Name;
|
||||
|
||||
if (field.IsNullable)
|
||||
{
|
||||
s = $"[{s}]";
|
||||
}
|
||||
|
||||
rows.Add(Indent(s + " : " + field.ToString()));
|
||||
else
|
||||
{
|
||||
s = $"'{s}'";
|
||||
}
|
||||
result.Add(s, field.ToString());
|
||||
}
|
||||
|
||||
return string.Join("\n" + Tab, rows);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных для форматирования в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Словарь данных</returns>
|
||||
public override Dictionary<string, string> GetYamlData()
|
||||
{
|
||||
return new() {
|
||||
["schema"] = SchemaNode.FormatYaml(GetSchemaYaml())
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
@@ -51,7 +52,7 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
|
||||
foreach (var pair in Values)
|
||||
{
|
||||
var newValue = "'" + pair.Key.ToString().Trim().Replace("'", "\\'") + "'";
|
||||
var newValue = "\"" + pair.Key.ToString().Trim().Replace("\"", "\\\"") + "\"";
|
||||
newValues.TryAdd(newValue, 0);
|
||||
newValues[newValue] += pair.Value;
|
||||
}
|
||||
@@ -72,37 +73,30 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Полное строковое представление элемента.
|
||||
/// Получение данных для форматирования в YAML.
|
||||
/// </summary>
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
/// <returns>Словарь данных</returns>
|
||||
public override Dictionary<string, string> GetYamlData()
|
||||
{
|
||||
var result = base.ToString();
|
||||
var values = new List<string>();
|
||||
var count = Values.Count;
|
||||
|
||||
if (count == Root.Values)
|
||||
var prefix = (count == 1) ? "" : "- ";
|
||||
|
||||
if (count is <= SchemaNode.ElementLimit and > 0 && (Type != JTokenType.String || !Values.Any(s => s.ToString().Contains('\n'))))
|
||||
{
|
||||
result += " (all different values)";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (count == 1)
|
||||
foreach (var kvp in Values)
|
||||
{
|
||||
result += $" (same value: {Values.Keys.ToList()[0]})";
|
||||
return result;
|
||||
values.Add($"{prefix}{kvp.Key} (x{kvp.Value})");
|
||||
}
|
||||
}
|
||||
|
||||
result += $" ({count} different values)";
|
||||
|
||||
if (count is > ElementLimit or <= 0 || (Type == JTokenType.String && Values.Any(s => s.ToString().Contains('\n'))))
|
||||
{
|
||||
return result.Trim();
|
||||
}
|
||||
|
||||
result += "\n";
|
||||
result = Values.Aggregate(result, (current, value) => current + $"{Tab}{value.Key} (x{value.Value})\n");
|
||||
|
||||
return result.Trim();
|
||||
return new() {
|
||||
["different_values"] = count.ToString() +
|
||||
((count == Root.Values) ? " (all different)" : "") +
|
||||
((count == 1) ? " (all same)" : ""),
|
||||
["variants"] = (values.Count > 0) ? string.Join("\r\n", values) : "[omitted]"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user