Add Genetic workers
This commit is contained in:
82
src/Managing.Application/GeneticService.cs
Normal file
82
src/Managing.Application/GeneticService.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Domain.Users;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application;
|
||||
|
||||
/// <summary>
|
||||
/// Service implementation for managing genetic algorithm requests
|
||||
/// </summary>
|
||||
public class GeneticService : IGeneticService
|
||||
{
|
||||
private readonly IGeneticRepository _geneticRepository;
|
||||
|
||||
public GeneticService(IGeneticRepository geneticRepository)
|
||||
{
|
||||
_geneticRepository = geneticRepository;
|
||||
}
|
||||
|
||||
public GeneticRequest CreateGeneticRequest(
|
||||
User user,
|
||||
Ticker ticker,
|
||||
Timeframe timeframe,
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
decimal balance,
|
||||
int populationSize,
|
||||
int generations,
|
||||
double mutationRate,
|
||||
string selectionMethod,
|
||||
int elitismPercentage,
|
||||
double maxTakeProfit,
|
||||
List<IndicatorType> eligibleIndicators)
|
||||
{
|
||||
var id = Guid.NewGuid().ToString(); // Generate unique GUID
|
||||
var geneticRequest = new GeneticRequest(id)
|
||||
{
|
||||
Ticker = ticker,
|
||||
Timeframe = timeframe,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
Balance = balance,
|
||||
PopulationSize = populationSize,
|
||||
Generations = generations,
|
||||
MutationRate = mutationRate,
|
||||
SelectionMethod = selectionMethod,
|
||||
ElitismPercentage = elitismPercentage,
|
||||
MaxTakeProfit = maxTakeProfit,
|
||||
EligibleIndicators = eligibleIndicators,
|
||||
Status = GeneticRequestStatus.Pending
|
||||
};
|
||||
|
||||
_geneticRepository.InsertGeneticRequestForUser(user, geneticRequest);
|
||||
return geneticRequest;
|
||||
}
|
||||
|
||||
public IEnumerable<GeneticRequest> GetGeneticRequestsByUser(User user)
|
||||
{
|
||||
return _geneticRepository.GetGeneticRequestsByUser(user);
|
||||
}
|
||||
|
||||
public GeneticRequest GetGeneticRequestByIdForUser(User user, string id)
|
||||
{
|
||||
return _geneticRepository.GetGeneticRequestByIdForUser(user, id);
|
||||
}
|
||||
|
||||
public void UpdateGeneticRequest(GeneticRequest geneticRequest)
|
||||
{
|
||||
_geneticRepository.UpdateGeneticRequest(geneticRequest);
|
||||
}
|
||||
|
||||
public void DeleteGeneticRequestByIdForUser(User user, string id)
|
||||
{
|
||||
_geneticRepository.DeleteGeneticRequestByIdForUser(user, id);
|
||||
}
|
||||
|
||||
public IEnumerable<GeneticRequest> GetPendingGeneticRequests()
|
||||
{
|
||||
return _geneticRepository.GetPendingGeneticRequests();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user