Add progression and new method of selection/mutation/crossover

This commit is contained in:
2025-07-11 23:38:22 +07:00
parent b21b0a342c
commit cebbeff887
13 changed files with 444 additions and 69 deletions

View File

@@ -176,6 +176,19 @@ public class MessengerService : IMessengerService
}
}
public async Task SendGeneticAlgorithmNotification(GeneticRequest request, double bestFitness, object? bestChromosome)
{
try
{
var message = BuildGeneticAlgorithmMessage(request, bestFitness, bestChromosome);
await _webhookService.SendMessage(message, "2775292276");
}
catch (Exception e)
{
Console.WriteLine($"Failed to send genetic algorithm notification: {e.Message}");
}
}
private string BuildBacktestConfigMessage(Backtest backtest)
{
var config = backtest.Config;
@@ -263,4 +276,42 @@ public class MessengerService : IMessengerService
return message;
}
private string BuildGeneticAlgorithmMessage(GeneticRequest request, double bestFitness, object? bestChromosome)
{
var duration = request.CompletedAt.HasValue
? request.CompletedAt.Value - request.CreatedAt
: TimeSpan.Zero;
var indicators = request.EligibleIndicators.Any()
? string.Join(", ", request.EligibleIndicators.Select(i => i.ToString()))
: "N/A";
if (request.EligibleIndicators.Count > 5)
{
indicators += $" (+{request.EligibleIndicators.Count - 5} more)";
}
var message = $"🧬 Genetic Algorithm Completed! 🧬\n\n" +
$"🔹 Symbol: {request.Ticker}\n" +
$"⏱️ Timeframe: {request.Timeframe}\n" +
$"👥 Population: {request.PopulationSize}\n" +
$"🔄 Generations: {request.Generations}\n" +
$"🎯 Selection: {request.SelectionMethod}\n" +
$"🔀 Crossover: {request.CrossoverMethod}\n" +
$"🧬 Mutation: {request.MutationMethod}\n" +
$"🧩 Indicators: {indicators}\n" +
$"📅 Period: {request.StartDate:yyyy-MM-dd} to {request.EndDate:yyyy-MM-dd}\n" +
$"📈 Results:\n" +
$"⭐ Best Fitness: {bestFitness:F4}\n" +
$"⏱️ Duration: {duration.TotalMinutes:F1} minutes\n" +
$"🆔 Request ID: {request.RequestId[..8]}...";
if (request.BestFitnessSoFar.HasValue && request.BestFitnessSoFar.Value > 0)
{
message += $"\n🏆 Best Fitness So Far: {request.BestFitnessSoFar.Value:F4}";
}
return message;
}
}