feat(sentiment): add persistent sentiment entities, summaries, SentimentDbService and MQTT RPC refactoring
This commit is contained in:
@@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Design;
|
||||
namespace FinlyticSentiment.Database;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for managing FinlyticSentiment settings in PostgreSQL.
|
||||
/// EF Core DbContext for managing FinlyticSentiment persistent entities and dynamic settings.
|
||||
/// </summary>
|
||||
public class SentimentDbContext : DbContext, ISettingsDbContext
|
||||
{
|
||||
@@ -16,24 +16,50 @@ public class SentimentDbContext : DbContext, ISettingsDbContext
|
||||
}
|
||||
|
||||
public DbSet<SettingEntity> DynamicSettings => Set<SettingEntity>();
|
||||
public DbSet<SentimentSettingsEntity> Settings => Set<SentimentSettingsEntity>();
|
||||
public DbSet<ArticleSentimentEntity> ArticleSentiments => Set<ArticleSentimentEntity>();
|
||||
public DbSet<CompanySentimentSummaryEntity> CompanySentiments => Set<CompanySentimentSummaryEntity>();
|
||||
public DbSet<SectorSentimentSummaryEntity> SectorSentiments => Set<SectorSentimentSummaryEntity>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// Dynamic Settings
|
||||
modelBuilder.Entity<SettingEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.HasIndex(e => e.Key).IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<SentimentSettingsEntity>(entity =>
|
||||
// Individual Article Sentiments
|
||||
modelBuilder.Entity<ArticleSentimentEntity>(entity =>
|
||||
{
|
||||
entity.ToTable("sentiment_settings");
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.GermanWebhookUrl).HasMaxLength(500);
|
||||
entity.Property(e => e.EnglishWebhookUrl).HasMaxLength(500);
|
||||
|
||||
// Prevent duplicate analysis of the same article for the same asset
|
||||
entity.HasIndex(e => new { e.ArticleId, e.Isin }).IsUnique();
|
||||
|
||||
// High-performance time-series index for timeline charts & time-decay scans
|
||||
entity.HasIndex(e => new { e.Isin, e.PublishedAtUtc });
|
||||
|
||||
entity.HasIndex(e => e.AnalyzedAtUtc);
|
||||
entity.HasIndex(e => e.Sector);
|
||||
});
|
||||
|
||||
// Pre-Aggregated Company Sentiment Summaries
|
||||
modelBuilder.Entity<CompanySentimentSummaryEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Isin);
|
||||
entity.HasIndex(e => e.Sector);
|
||||
entity.HasIndex(e => e.WeightedScore);
|
||||
entity.HasIndex(e => e.LastUpdatedUtc);
|
||||
});
|
||||
|
||||
// Pre-Aggregated Sector Sentiment Summaries
|
||||
modelBuilder.Entity<SectorSentimentSummaryEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Sector);
|
||||
entity.HasIndex(e => e.LastUpdatedUtc);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user