Add BacktestCount

This commit is contained in:
2025-10-01 13:01:03 +07:00
parent 3e680ab815
commit 06850b57c4
14 changed files with 1571 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Managing.Infrastructure.Databases.Migrations
{
/// <inheritdoc />
public partial class AddBacktestCountToAgentSummary : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "BacktestCount",
table: "AgentSummaries",
type: "integer",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "BacktestCount",
table: "AgentSummaries");
}
}
}

View File

@@ -86,6 +86,9 @@ namespace Managing.Infrastructure.Databases.Migrations
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<int>("BacktestCount")
.HasColumnType("integer");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");

View File

@@ -251,7 +251,8 @@ public class AgentSummaryRepository : IAgentSummaryRepository
ActiveStrategiesCount = domain.ActiveStrategiesCount,
TotalVolume = domain.TotalVolume,
TotalBalance = domain.TotalBalance,
TotalFees = domain.TotalFees
TotalFees = domain.TotalFees,
BacktestCount = domain.BacktestCount
};
}
@@ -269,6 +270,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
entity.TotalVolume = domain.TotalVolume;
entity.TotalBalance = domain.TotalBalance;
entity.TotalFees = domain.TotalFees;
entity.BacktestCount = domain.BacktestCount;
}
private static AgentSummary MapToDomain(AgentSummaryEntity entity)
@@ -290,6 +292,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
TotalVolume = entity.TotalVolume,
TotalBalance = entity.TotalBalance,
TotalFees = entity.TotalFees,
BacktestCount = entity.BacktestCount,
User = PostgreSqlMappers.Map(entity.User)
};
}
@@ -329,4 +332,26 @@ public class AgentSummaryRepository : IAgentSummaryRepository
{
return await _context.AgentSummaries.CountAsync();
}
public async Task IncrementBacktestCountAsync(int userId)
{
var entity = await _context.AgentSummaries
.FirstOrDefaultAsync(a => a.UserId == userId);
if (entity != null)
{
entity.BacktestCount++;
entity.UpdatedAt = DateTime.UtcNow;
await _context.SaveChangesAsync();
_logger.LogInformation("Backtest count incremented for user {UserId} to {BacktestCount}",
userId, entity.BacktestCount);
}
else
{
_logger.LogWarning("No AgentSummary found for user {UserId} when trying to increment backtest count",
userId);
}
}
}

View File

@@ -17,6 +17,7 @@ public class AgentSummaryEntity
public decimal TotalBalance { get; set; }
public decimal TotalFees { get; set; }
public decimal NetPnL { get; set; }
public int BacktestCount { get; set; }
// Navigation property
public UserEntity User { get; set; }

View File

@@ -548,6 +548,7 @@ public class ManagingDbContext : DbContext
entity.Property(e => e.ActiveStrategiesCount).IsRequired();
entity.Property(e => e.TotalVolume).HasPrecision(18, 8);
entity.Property(e => e.TotalBalance).HasPrecision(18, 8);
entity.Property(e => e.BacktestCount).IsRequired();
// Create indexes for common queries
entity.HasIndex(e => e.UserId).IsUnique();