private RecipeTemplate GetRCRecipeTempate(double chargeCurrent, double idleTime, double curr, RecipeTemplateServiceClass recipeTemplateService, StepTemplateServiceClass stepTemplateService) { try { List <RecipeTemplate> recTemplates = recipeTemplateService.Items.ToList(); //using (var dbContext = new AppDbContext()) //{ // rectemplist = dbContext.RecipeTemplates // .Include(recipeTemplate => recipeTemplate.Steps) // .ThenInclude(step => step.StepTemplate) // .ToList(); //} foreach (var rec in recTemplates) { rec.Steps = new ObservableCollection <Step>(rec.Steps.OrderBy(o => o.Order)); } var rectemp = recTemplates.SingleOrDefault(o => o.Steps.Count == 4 && o.Steps[0].StepTemplate.CurrentInput == chargeCurrent && o.Steps[0].StepTemplate.CurrentUnit == CurrentUnitEnum.C && o.Steps[0].StepTemplate.CutOffConditionValue == 1 && o.Steps[0].StepTemplate.CutOffConditionType == CutOffConditionTypeEnum.CRate && o.Steps[0].LoopLabel == null && o.Steps[1].StepTemplate.CurrentInput == 0 && //o.Steps[1].StepTemplate.CurrentUnit == CurrentUnitEnum.C && o.Steps[1].StepTemplate.CutOffConditionValue == idleTime && o.Steps[1].StepTemplate.CutOffConditionType == CutOffConditionTypeEnum.Time_s && o.Steps[1].LoopLabel == null && o.Steps[2].StepTemplate.CurrentInput == curr && o.Steps[2].StepTemplate.CurrentUnit == CurrentUnitEnum.mA && o.Steps[2].StepTemplate.CutOffConditionValue == 0 && //o.Steps[2].StepTemplate.CutOffConditionType == CutOffConditionTypeEnum.CRate o.Steps[2].LoopLabel == null && o.Steps[3].StepTemplate.CurrentInput == curr && o.Steps[3].StepTemplate.CurrentUnit == CurrentUnitEnum.mA && o.Steps[3].StepTemplate.CutOffConditionValue == 0 && //o.Steps[2].StepTemplate.CutOffConditionType == CutOffConditionTypeEnum.CRate o.Steps[3].LoopLabel == null ); if (rectemp != null) { return(rectemp); } //没找到,需要创建这个recipe template rectemp = CreateRCRecipeTemplate(chargeCurrent, idleTime, curr, recipeTemplateService, stepTemplateService); return(rectemp); } catch (Exception e) { MessageBox.Show(e.Message, "Get RC RecipeTempate Error!"); return(null); } }
//internal void FixTemplates(Program prog) //{ // using (var uow = new UnitOfWork(new AppDbContext())) // { // foreach (var rec in prog.Recipes) // { // rec.RecipeTemplate = uow.RecipeTemplates.GetAll("StepV2s").Last(o => o.Name == rec.Name); // } // uow.Commit(); // } //} private List <RecipeTemplate> GetRCRecipeTemplatesByCurrents(double chargeRate, double idleTime, List <double> currents, RecipeTemplateServiceClass recipeTemplateService, StepTemplateServiceClass stepTemplateService) { var output = new List <RecipeTemplate>(); foreach (var curr in currents) { var rectemp = GetRCRecipeTempate(chargeRate, idleTime, curr, recipeTemplateService, stepTemplateService); output.Add(rectemp); } return(output); }
private StepTemplate CreateRCStepTemplate(double currentInput, CurrentUnitEnum currentUnit, double cutOffConditionValue, CutOffConditionTypeEnum cutOffConditionType, StepTemplateServiceClass stepTemplateService) { var output = new StepTemplate() { CurrentInput = currentInput, CurrentUnit = currentUnit, CutOffConditionValue = cutOffConditionValue, CutOffConditionType = cutOffConditionType }; stepTemplateService.SuperAdd(output); return(output); }
public void RCSuperAdd(Program item, double chargeRate, double idleTime, List <double> currents, List <double> temperatures, RecipeTemplateServiceClass recipeTemplateService, StepTemplateServiceClass stepTemplateService) { var rectemplist = GetRCRecipeTemplatesByCurrents(chargeRate, idleTime, currents, recipeTemplateService, stepTemplateService); foreach (var temp in temperatures) { foreach (var rectemp in rectemplist) { var recRuntime = new Recipe(rectemp, item.Project.BatteryType); recRuntime.Temperature = temp; item.Recipes.Add(recRuntime); } } //item.Type = RC //To be implemented DomainAdd(item); DatabaseAdd(item); }
private RecipeTemplate CreateRCRecipeTemplate(double chargeCurrent, double idleTime, double curr, RecipeTemplateServiceClass recipeTemplateService, StepTemplateServiceClass stepTemplateService) { try { //using (var uow = new UnitOfWork(new AppDbContext())) //{ List <StepTemplate> stepTemplates = stepTemplateService.Items.ToList(); var chargesteptemp = stepTemplates.SingleOrDefault(o => o.CurrentInput == chargeCurrent && o.CurrentUnit == CurrentUnitEnum.C && o.CutOffConditionValue == 1 && o.CutOffConditionType == CutOffConditionTypeEnum.CRate); if (chargesteptemp == null) { chargesteptemp = CreateRCStepTemplate(chargeCurrent, CurrentUnitEnum.C, 1, CutOffConditionTypeEnum.CRate, stepTemplateService); //new StepTemplate() { CurrentInput = chargeCurrent, CurrentUnit = CurrentUnitEnum.C, CutOffConditionValue = 1, CutOffConditionType = CutOffConditionTypeEnum.CRate }; } var idlesteptemp = stepTemplates.SingleOrDefault(o => o.CurrentInput == 0 && o.CutOffConditionValue == idleTime && o.CutOffConditionType == CutOffConditionTypeEnum.Time_s); if (idlesteptemp == null) { idlesteptemp = CreateRCStepTemplate(0, CurrentUnitEnum.mA, idleTime, CutOffConditionTypeEnum.Time_s, stepTemplateService); //new StepTemplate() { CurrentInput = 0, CurrentUnit = CurrentUnitEnum.mA, CutOffConditionValue = idleTime, CutOffConditionType = CutOffConditionTypeEnum.Time_s }; } var dsgsteptemp = stepTemplates.SingleOrDefault(o => o.CurrentInput == curr && o.CutOffConditionValue == 0); if (dsgsteptemp == null) { dsgsteptemp = CreateRCStepTemplate(curr, CurrentUnitEnum.mA, 0, CutOffConditionTypeEnum.CRate, stepTemplateService); //new StepTemplate() { CurrentInput = curr, CurrentUnit = CurrentUnitEnum.mA, CutOffConditionValue = 0, CutOffConditionType = CutOffConditionTypeEnum.CRate }; } RecipeTemplate output; output = new RecipeTemplate() { Name = $"{curr / -1000}A" }; var step = new Step(chargesteptemp); output.Steps.Add(step); step = new Step(idlesteptemp); output.Steps.Add(step); step = new Step(dsgsteptemp); output.Steps.Add(step); step = new Step(idlesteptemp); output.Steps.Add(step); recipeTemplateService.SuperAdd(output); return(output); } catch (Exception e) { MessageBox.Show(e.Message, "Create RC RecipeTemplate Error!"); return(null); } }