Продолжение

This commit is contained in:
2025-04-18 00:18:23 +04:00
parent 10e3e274d5
commit a78b01b15c
15 changed files with 182 additions and 7445 deletions
@@ -49,13 +49,19 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
Context.SaveChanges(); Context.SaveChanges();
} }
protected string AddedDescription(string path) => $"\n\n---\n[{path}]\n\n{Input.GetOptional<string>("markdown") ?? ""}";
protected string AddedDescription(string[] paths) => string.Join("", paths.Select(AddedDescription));
protected virtual string GetDescription() => Input.GetRequired<string>("markdown");
protected virtual void AddEntity() protected virtual void AddEntity()
{ {
Entity.Id = Helper.NextEntityId; Entity.Id = Helper.NextEntityId;
Entity.Type = Type; Entity.Type = Type;
Entity.Name = Input.GetRequired<string>("name"); Entity.Name = Input.GetRequired<string>("name");
Entity.Img = ""; // GetRequired<string>("img"); Entity.Img = ""; // GetRequired<string>("img");
Entity.Description = Input.GetRequired<string>("markdown"); Entity.Description = GetDescription();
Entity.Rarity = Input.EnumOptional<EntityRarity>("rarity", EntityRarity.Common); Entity.Rarity = Input.EnumOptional<EntityRarity>("rarity", EntityRarity.Common);
Entity.Slug = Helper.GenerateSlug(Entity.Name); Entity.Slug = Helper.GenerateSlug(Entity.Name);
Entity.IsTranslated = false; Entity.IsTranslated = false;
@@ -1,7 +1,11 @@
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
[AttributeUsage(AttributeTargets.Field)] [AttributeUsage(AttributeTargets.Field)]
internal class AonprdEnumAttribute(string value) : Attribute internal class AonprdEnumAttribute(string[] values) : Attribute
{ {
public readonly string Value = value; public readonly string[] Values = values;
public AonprdEnumAttribute(string value) : this([value])
{
}
} }
@@ -47,7 +47,7 @@ internal class ProcessorInput(JObject input)
} }
if (Attribute.GetCustomAttribute(field, typeof(AonprdEnumAttribute)) is AonprdEnumAttribute aonprdAttribute) if (Attribute.GetCustomAttribute(field, typeof(AonprdEnumAttribute)) is AonprdEnumAttribute aonprdAttribute)
{ {
variants.Add(aonprdAttribute.Value); variants.AddRange(aonprdAttribute.Values);
} }
if (variants.Contains(value)) if (variants.Contains(value))
@@ -1,10 +1,5 @@
using Pf2eDataScrapper.Model.Enum; using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Model.Structure; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
@@ -17,9 +12,74 @@ internal class ActionProcessor(ProcessorInput input) : AbstractProcessor(input)
public override void Process() public override void Process()
{ {
base.Process();
switch (Input.GetOptional<string>("actions"))
{
case "Single Action":
Object.Actions = Object.MaxActions = 1;
break;
case "Two Actions":
Object.Actions = Object.MaxActions = 2;
break;
case "Three Actions":
Object.Actions = Object.MaxActions = 3;
break;
case "Reaction":
Object.IsReaction = true;
break;
case "Free Action":
Object.IsFreeAction = false;
break;
case "Single Action to Three Actions":
case "Single Action or more Actions":
Object.Actions = 1;
Object.MaxActions = 3;
break;
case "Single Action or Two Actions":
case "Single Action to Two Actions":
Object.Actions = 1;
Object.MaxActions = 2;
break;
case "Reaction or One Action":
Object.IsReaction = true;
Object.Actions = Object.MaxActions = 1;
break;
case "Free Action or One Action":
Object.IsFreeAction = false;
Object.Actions = Object.MaxActions = 1;
break;
default:
Object.IsPassive = true;
break;
}
Object.Extra = new JObject()
{
{ "school", Input.GetOptional<JToken>("school") },
}.ToString();
Context.Actions.Add(Object);
} }
protected override string GetDescription()
=> base.GetDescription() + AddedDescription([
"cost_markdown",
"trait_markdown",
"source_markdown",
"search_markdown",
"requirement_markdown",
"trigger_markdown",
"summary_markdown",
]);
} }
@@ -3,7 +3,7 @@ using Pf2eDataScrapper.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
[AonprdProcessor("trait", [])] [AonprdProcessor("trait", new string[] {})]
internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input) internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input)
{ {
public override EntityType Type => EntityType.Trait; public override EntityType Type => EntityType.Trait;
@@ -24,4 +24,9 @@ internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input)
// Во втором проходе // Во втором проходе
} }
protected override string GetDescription()
=> base.GetDescription() + AddedDescription([
"summary_markdown",
"search_markdown"
]);
} }
@@ -15,9 +15,9 @@ internal class ActionProcessor(JObject input) : AbstractProcessor(input)
base.Process(); base.Process();
Object.Type = EnumRequired<ActionType>("system.actionType.value"); Object.Type = EnumRequired<ActionType>("system.actionType.value");
Object.Category = EnumOptional<ActionCategory>("system.category", ActionCategory.Unknown); // Object.Category = EnumOptional<ActionCategory>("system.category", ActionCategory.Unknown);
Object.Actions = GetOptional<int>("system.actions.value"); Object.Actions = GetOptional<int>("system.actions.value");
Object.DeathNote = GetOptional<bool>("system.deathNote"); // Object.DeathNote = GetOptional<bool>("system.deathNote");
JObject extra = new() JObject extra = new()
{ {
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,35 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Pf2eDataScrapper.Migrations;
/// <inheritdoc />
public partial class DateOnly : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateOnly>(
name: "release_date",
table: "sources",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "release_date",
table: "sources",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true);
}
}
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -57,5 +57,5 @@ public class Entity
public virtual ICollection<EntitySource> Sources { get; set; } = []; public virtual ICollection<EntitySource> Sources { get; set; } = [];
public virtual ICollection<EntityExternal> Extrnals { get; set; } = []; public virtual ICollection<EntityExternal> Externals { get; set; } = [];
} }
+18 -8
View File
@@ -1,20 +1,30 @@
using NpgsqlTypes; using NpgsqlTypes;
using Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
namespace Pf2eDataScrapper.Model.Enum; namespace Pf2eDataScrapper.Model.Enum;
public enum ActionType public enum ActionType
{ {
[PgName("action")] [PgName("none")]
Action, None,
[PgName("free")] [AonprdEnum(["Single Action", "Reaction or One Action", "Free Action or One Action"])]
Free, [PgName("1_action")]
SingleAction,
[PgName("reaction")] [AonprdEnum("Two Actions")]
Reaction, [PgName("2_actions")]
TwoActions,
[PgName("passive")] [AonprdEnum("Three Actions")]
Passive, [PgName("3_actions")]
ThreeActions,
[AonprdEnum(["Single Action to Three Actions", "Single Action or more Actions"])]
[PgName("1-3_actions")]
SingleToThreeActions,
[AonprdEnum(["Single Action or Two Actions", "Single Action to Two Actions"])]
[PgName("1-2_actions")]
SingleToTwoActions,
} }
+62 -2
View File
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using LinqToDB.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Pf2eDataScrapper.Model.Base; using Pf2eDataScrapper.Model.Base;
using Pf2eDataScrapper.Model.Base.Keywords; using Pf2eDataScrapper.Model.Base.Keywords;
@@ -28,6 +29,7 @@ public partial class Pf2eDbContext
DefineBase(modelBuilder); DefineBase(modelBuilder);
DefineCommon(modelBuilder); DefineCommon(modelBuilder);
DefineStructure(modelBuilder); DefineStructure(modelBuilder);
DefineFunctions();
} }
private void DefineEnums(ModelBuilder modelBuilder) private void DefineEnums(ModelBuilder modelBuilder)
@@ -76,7 +78,7 @@ public partial class Pf2eDbContext
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
// EntityExternal // EntityExternal
entity.HasMany(e => e.Extrnals).WithOne(e => e.Entity) entity.HasMany(e => e.Externals).WithOne(e => e.Entity)
.HasForeignKey(e => e.EntityId) .HasForeignKey(e => e.EntityId)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
}); });
@@ -324,4 +326,62 @@ public partial class Pf2eDbContext
BindEntity(entity); BindEntity(entity);
}); });
} }
private void DefineFunctions()
{
Database.ExecuteSql($"""
CREATE OR REPLACE FUNCTION f_truncate_tables()
RETURNS void
LANGUAGE plpgsql AS
$func$
BEGIN
EXECUTE (
SELECT 'TRUNCATE TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE;'
FROM pg_tables
WHERE schemaname = 'public'
AND tablename != '__EFMigrationsHistory'
);
END
$func$;
""");
Database.ExecuteSql($"""
CREATE OR REPLACE FUNCTION f_drop_tables()
RETURNS void
LANGUAGE plpgsql AS
$func$
BEGIN
EXECUTE (
SELECT 'DROP TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE;'
FROM pg_tables
WHERE schemaname = 'public'
);
END
$func$;
""");
Database.ExecuteSql($"""
CREATE OR REPLACE FUNCTION f_permission_tables(_username text)
RETURNS void
LANGUAGE plpgsql AS
$func$
DECLARE
_tbl text;
_sch text;
BEGIN
FOR _sch, _tbl IN
SELECT schemaname, tablename
FROM pg_tables
WHERE schemaname = 'public'
LOOP
EXECUTE format('ALTER TABLE %I.%I OWNER TO %I', _sch, _tbl, _username);
END LOOP;
END
$func$;
""");
}
} }
+9 -3
View File
@@ -15,13 +15,19 @@ public partial class Action : IEntity
public ActionType Type { get; set; } public ActionType Type { get; set; }
[Column(Order = 3)] [Column(Order = 3)]
public ActionCategory Category { get; set; } public int? Actions { get; set; } = null;
[Column(Order = 4)] [Column(Order = 4)]
public int? Actions { get; set; } public int? MaxActions { get; set; } = null;
[Column(Order = 5)] [Column(Order = 5)]
public bool? DeathNote { get; set; } public bool IsReaction { get; set; } = false;
[Column(Order = 6)]
public bool IsFreeAction { get; set; } = false;
[Column(Order = 6)]
public bool IsPassive { get; set; } = false;
[Column(Order = 6)] [Column(Order = 6)]
public string? Extra { get; set; } public string? Extra { get; set; }