public async Task CreateForecastingTaskMLModel(string entityName, LearningAlgorithm algorithm, bool isValidationNeeded = true) { entityName = entityName?.Trim(); if (isValidationNeeded) { if (!await DoesForecastingTaskEntityExist(entityName)) { throw new DomainErrorException($"Forecasting task with name {entityName} doesn't exist!"); } } try { var taskEntity = await _forecastingTasksRepository.GetForecastingTaskEntity(entityName); if (taskEntity.Records.Count == 0) { throw new DomainErrorException("There are no data in the database!"); } var nonInformationFields = taskEntity.FieldsDeclaration.Where(x => x.Type != FieldType.InformationField).ToList(); var entity = new ClassBuilder(entityName, GetFieldsType(nonInformationFields)); var dataList = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(entity.Type)); foreach (var fieldsValue in taskEntity.Records) { var myClassInstance = entity.CreateObject(); foreach (var fieldDeclaration in nonInformationFields) { var value = fieldsValue.FieldsValue.Single(x => x.FieldId == fieldDeclaration.Id).Value; entity.SetPropertyValue(myClassInstance, fieldDeclaration.Name, float.Parse(value)); } dataList.Add(myClassInstance); } var factors = nonInformationFields.Where(x => x.Type == FieldType.Factor).Select(x => x.Name); var predictedValue = nonInformationFields.Single(x => x.Type == FieldType.PredictionField).Name; ForecastingTaskModelBuilder.CreateModel(dataList, entityName, factors, predictedValue, algorithm); } catch (Exception) { throw; } }
public async Task <string> GenerateCsvString(string entityName) { entityName = entityName?.Trim(); if (!await DoesForecastingTaskEntityExist(entityName)) { throw new DomainErrorException($"Forecasting task with name {entityName} doesn't exist!"); } try { var taskEntity = await _forecastingTasksRepository.GetForecastingTaskEntity(entityName); var result = new StringBuilder(string.Join(',', taskEntity.FieldsDeclaration.Select(x => x.Name))); foreach (var fieldsValue in taskEntity.Records) { var tempStr = "\r\n"; foreach (var factorDeclaration in taskEntity.FieldsDeclaration) { var value = fieldsValue.FieldsValue.Single(x => x.FieldId == factorDeclaration.Id).Value; tempStr += value + ','; } result.Append(tempStr[0..^ 1]);