private static ActionPlan CreateWeightActionPlan(Guid objectiveId) { var plan = new ActionPlan(); var objective = new Objective { Id = objectiveId, Name = ObjectiveName, Description = "Manage your weight better by measuring daily. ", State = "Active", OutcomeName = "Better control over your weight", OutcomeType = "Other" }; // Use this if you want to create the task with the plan in one call. // You can also create tasks in a separate call after the action plan is created. var task = CreateDailyWeightMeasurementActionPlanTask(objective.Id); plan.Name = PlanName; plan.Description = "Daily weight tracking can help you be more conscious of what you eat. "; plan.ImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RW680a?ver=b227"; plan.ThumbnailImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RW6fN6?ver=6479"; plan.Category = "Health"; plan.Objectives = new Collection <Objective> { objective }; plan.AssociatedTasks = new Collection <ActionPlanTask> { task }; return(plan); }
private static void AddActionPlansAndDecisions(Sprint sprint, DataRow item, int memberId, string planName, SprintComment sprintComment) { //Add Action Plan if (!string.IsNullOrEmpty(planName)) { var actionPlan = new ActionPlan { FollwingUpByMemberId = memberId, SprintCommentId = sprint.Id }; var actionPlanDecisions = new List <ActionPlanDecision>(); //ActionPlanDecisions for (int k = 12; k < 18; k++) { var decision = item.ItemArray[k].ToString(); if (!string.IsNullOrEmpty(decision)) { var actionPlanDecision = new ActionPlanDecision { ActionPlanId = actionPlan.Id, Decision = decision }; actionPlanDecisions.Add(actionPlanDecision); } } actionPlan.ActionPlanDecisions = actionPlanDecisions; sprintComment.ActionPlans.Add(actionPlan); } }
public dynamic UpsertResourcesActionPlans(dynamic resourceObject) { ActionPlan actionPlans = new ActionPlan(); List <TopicTag> topicTags = new List <TopicTag>(); List <Location> locations = new List <Location>(); List <Conditions> conditions = new List <Conditions>(); dynamic references = GetReferences(resourceObject); topicTags = references[0]; locations = references[1]; conditions = references[2]; actionPlans = new ActionPlan() { ResourceId = resourceObject.id == "" ? Guid.NewGuid() : resourceObject.id, Name = resourceObject.name, ResourceCategory = resourceObject.resourceCategory, Description = resourceObject.description, ResourceType = resourceObject.resourceType, Url = resourceObject.url, TopicTags = topicTags, OrganizationalUnit = resourceObject.organizationalUnit, Location = locations, Conditions = conditions, CreatedBy = resourceObject.createdBy, ModifiedBy = resourceObject.modifiedBy }; actionPlans.Validate(); return(actionPlans); }
public static ActionPlan CreateWeightActionPlan() { var objective = new Objective { Id = Guid.NewGuid(), Name = "Manage your weight", Description = "Manage your weight better by measuring daily. ", State = ActionPlanObjectiveStatus.Active.ToString(), OutcomeName = "Better control over your weight", OutcomeType = ActionPlanOutcomeType.Other.ToString() }; // Use this if you want to create the task with the plan in one call. // You can also create tasks in a separate call after the action plan is created. var task = CreateDailyWeightMeasurementActionPlanTask(objective.Id); var plan = new ActionPlan { Name = "Track your weight", Description = "Daily weight tracking can help you be more conscious of what you eat. ", ImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RW680a?ver=b227", ThumbnailImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RW6fN6?ver=6479", Category = ActionPlanCategory.Health.ToString(), Objectives = new Collection <Objective> { objective }, AssociatedTasks = new Collection <ActionPlanTask> { task } }; return(plan); }
public void Given_Submitted_Checklist_When_Any_of_the_Action_is_Assigned_then_CanBeReverted_Returns_false() { var actionPlan = new ActionPlan() { Id = 1, Title = "My Action Plan", Deleted = false, }; var action = new Action() { Id = 1, ActionPlanId = actionPlan.Id, ActionPlan = actionPlan, AssignedTo = new Employee() }; var actionTasks = new List<ActionTask>(); actionTasks.Add(new ActionTask() { Action = action} ); action.ActionTasks = actionTasks; var actions = new List<Action>(); actions.Add(action); actions.Add(new Action() { Id = 2, ActionPlanId = actionPlan.Id, ActionPlan = actionPlan, }); actions.Add(new Action() { Id = 3, ActionPlanId = actionPlan.Id, ActionPlan = actionPlan, }); actionPlan.Actions = actions; var checklist = new Checklist { Id = Guid.NewGuid(), ActionPlan = actionPlan, Status = "Submitted" }; var target = checklist.CanBeReverted(); Assert.IsFalse(target); }
/// <summary> /// Creates a sample action plan object. /// </summary> public static ActionPlan CreateSleepActionPlan() { var objective = CreateSleepObjective(); // Use this if you want to create the task with the plan in one call. // You can also create tasks in a separate call after the action plan is created. var scheduledTask = CreateSleepScheduledActionPlanTask(objective.Id); var frequencyTask = CreateSleepFrequencyActionPlanTask(objective.Id); var plan = new ActionPlan { Name = "Sleep better", Description = "Improve the quantity and quality of your sleep.", ImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE10omP?ver=59cf", ThumbnailImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE10omP?ver=59cf", Category = ActionPlanCategory.Sleep.ToString(), Objectives = new Collection <Objective> { objective }, AssociatedTasks = new Collection <ActionPlanTask> { scheduledTask, frequencyTask } }; return(plan); }
/// <summary> /// 生成可以测试的动作计划集:从动作记忆中找到的行动计划,加上新补充的一些 /// </summary> /// <param name="plans">从动作记忆中找到的行动计划</param> /// <param name="time"></param> /// <returns></returns> private List <ActionPlan> checkActionPlansFull(List <ActionPlan> plans, int time) { if (plans == null) { plans = new List <ActionPlan>(); } List <List <double> > actionSets = CreateTestActionSet(Session.instinctActionHandler(net, time)); ActionPlan[] r = new ActionPlan[actionSets.Count]; for (int i = 0; i < actionSets.Count; i++) { ActionPlan plan = plans.FirstOrDefault(p => p.Equals(actionSets[i])); if (plan == null) { String judgeType = ActionPlan.JUDGE_INFERENCE; if (i == 0) { judgeType = ActionPlan.JUDGE_INSTINCT; } else if (actionSets[i][0] == 0.5) { judgeType = ActionPlan.JUDGE_MAINTAIN; } plan = ActionPlan.CreateActionPlan(net, actionSets[i], time, judgeType, "", 0); } r[i] = plan; } return(r.ToList()); }
/// <summary> /// 生成可以测试的动作计划集:从动作记忆中找到的行动计划,加上新补充的一些 /// </summary> /// <param name="plans">从动作记忆中找到的行动计划</param> /// <param name="time"></param> /// <returns></returns> private List <ActionPlan> checkActionPlansFull(List <ObservationHistory.ActionRecord> actionRecords, int time) { List <List <double> > actionSets = CreateTestActionSet(Session.instinctActionHandler(net, time)); ActionPlan[] r = new ActionPlan[actionSets.Count]; for (int i = 0; i < actionSets.Count; i++) { ActionPlan plan = null; String judgeType = ActionPlan.JUDGE_INFERENCE; if (i == 0) { judgeType = ActionPlan.JUDGE_INSTINCT; } else if (actionSets[i][0] == 0.5) { judgeType = ActionPlan.JUDGE_MAINTAIN; } ObservationHistory.ActionRecord record = actionRecords.FirstOrDefault(p => p.actions[0] == actionSets[i][0]); if (record == null) { plan = ActionPlan.CreateActionPlan(net, actionSets[i], time, judgeType, ""); } else { plan = ActionPlan.CreateActionPlan(net, record.actions, time, judgeType, ""); plan.evaulation = record.evaluation; } r[i] = plan; } return(r.ToList()); }
static void Main(string[] args) { var actionPlanEntity = new ActionPlan(); var baseEntity = new BaseEntity(); Mapper.Initialize(cfg => { cfg.CreateMap <ActionPlan, ActionPlanDto>() .IncludeBase <BaseEntity, BaseEntityDto>() .ForMember(dest => dest.DateStartedAt, opts => opts .MapFrom(x => (x.DateStartedAt + x.TimeStartedAt).ToLocalDateTime() .InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull(x.TimeZone)).Date)) .ForMember(dest => dest.TimeStartedAt, opts => opts .MapFrom(x => (x.DateStartedAt + x.TimeStartedAt).ToLocalDateTime() .InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull(x.TimeZone)).LocalDateTime.TimeOfDay)) .ForMember(dest => dest.StartedAtUtc, opts => opts .MapFrom(x => x.StartedAt.ToInstant().InZone(DateTimeZoneProviders.Tzdb.GetZoneOrNull(x.TimeZone)).ToInstant())) .ForMember(dest => dest.StartedAt, opts => opts .MapFrom(x => x.StartedAt.ToInstant().InZone(DateTimeZoneProviders.Tzdb.GetZoneOrNull(x.TimeZone)))); cfg.CreateMap <BaseEntity, BaseEntityDto>() .ForMember(dest => dest.CreatedAt, opts => opts .MapFrom(x => x.CreatedAt.ToInstant().InUtc())); }); var baseDto = Mapper.Map <BaseEntity, BaseEntityDto>(baseEntity); baseDto.Dump(); var actionPlanDto = Mapper.Map <ActionPlan, ActionPlanDto>(actionPlanEntity); actionPlanDto.Dump(); }
/// <summary> /// Creates a sample action plan object. /// </summary> private ActionPlan CreateDefaultActionPlan() { var plan = new ActionPlan(); var objective = CreateDefaultActionPlanObjective(); // Use this if you want to create the task with the plan in one call. // You can also create tasks in a separate call after the action plan is created. var scheduledTask = CreateDefaultScheduledActionPlanTask(objective.Id); var frequencyTask = CreateDefaultFrequencyActionPlanTask(objective.Id); plan.Name = "Sleep better"; plan.Description = "Improve the quantity and quality of your sleep."; plan.ImageUrl = new Uri("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE10omP?ver=59cf"); plan.ThumbnailImageUrl = new Uri("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE10omP?ver=59cf"); plan.OrganizationId = "CONTOSO"; plan.OrganizationName = "Contoso"; plan.OrganizationLogoUrl = new Uri("https://www.example.com"); plan.OrganizationLongFormImageUrl = new Uri("https://www.example.com"); plan.Category = ActionPlanCategory.Sleep; plan.Objectives = new Collection <Objective> { objective }; plan.AssociatedTasks = new Collection <ActionPlanTask> { scheduledTask, frequencyTask }; return(plan); }
public async Task <ActionPlanDto> GetActionPlanAsync(Guid id, CancellationToken ct) { ActionPlan ActionPlanEntity = await _uow.ActionPlan.GetActionPlanAsync(id, ct); ActionPlanDto ActionPlanDto = _mapper.Mapper.Map <ActionPlanDto>(ActionPlanEntity); return(ActionPlanDto); }
public ActionPlan Create(CreateActionPlanCommand command) { var actionPlan = new ActionPlan(command.Objective, command.CoachingProcess, command.Description); actionPlan.Validate(); _repository.Create(actionPlan); if (Commit()) return actionPlan; return null; }
/// <summary> /// Call the HV REST API to add the action plan to a user's HealthVault record. /// Assigns an action plan to a user who is not signed in ("offline" scenario) if both personId and recordId are provided. /// Otherwise, this assigns the action plan to the user who is actively signed into the application ("online" scenario). /// See Getting Started doc for more information on offline scenarios. /// </summary> private HealthServiceRestResponseData CreatePlan(ActionPlan plan, Guid?personId, Guid?recordId) { return(HealthServiceRestHelper.CallHeathServiceRest( personId, recordId, User.PersonInfo(), HttpMethod.Post.ToString(), _basePlanRestUrl, null, JsonConvert.SerializeObject(plan))); }
public void given_no_tasks_when_get_status_from_tasks_then_return_none() { // Given var plan = new ActionPlan(); // When var result = plan.GetStatusFromActions(); // Then Assert.That(result, Is.EqualTo(DerivedTaskStatusForDisplay.None)); }
/// <summary> /// 一 处理上一个行动链 /// 1.若当前行动链为空,则执行二 /// 2.若当前行动链没有得到reward,且行动次数小于阈值, /// 将动作修订为维持,继续执行,否则执行3 /// 3.将行动链条和奖励置入环境记忆空间,执行二制定新的行动计划 /// 二 制订行动计划 /// 1.获得所有与环境匹配的推理场景,若没有则执行2,否则5 /// 2.当前环境下本能动作在场景记忆中没有,创建本能动作链,结束,否则3 /// 3.当前环境下本能动作在场景记忆评估为正值,创建本能动作链,结束,否则4 /// 4.如果当前奖励为负,则创建反向随机动作链,否则创建高斯高斯随机动作链, /// 反复创建直到创建的动作结合场景要么在记忆中没有,要么记忆评估为正,结束 /// 5.创建测试动作集,其中第一个是本能动作,其次都是按照与当前动作相近排序 /// 6.对动作集中的每一个动作,执行前向推理,得到预测场景 /// 7.若预测场景+维持动作在场景记忆中有,则记录评估值,否则回到6 /// 8.若探索优先,则在未评估动作中选择构造新的行动计划,优先选择本能 /// 9.否则在正评估行动中选择构建新的行动计划 /// </summary> /// <param name="time"></param> /// <param name="session"></param> /// <returns></returns> public override ActionPlan execute(int time, Session session) { //1.1 第一次规划,随机动作 if (net.actionPlanChain.Length <= 0) { return(net.actionPlanChain.Reset(ActionPlan.CreateInstinctPlan(net, time, "初始动作"))); } //1.2 仍在随机动作阶段 if (time < 100) { net.actionMemory.Merge(net, net.actionPlanChain.Last); return(net.actionPlanChain.Reset(ActionPlan.CreateRandomPlan(net, time, "随机漫游"))); } //1.3 随机漫游结束 if (time == 100) { net.actionMemory.Merge(net, net.actionPlanChain.Last); return(net.actionPlanChain.Reset(makeNewActionPlan(time, session))); } //1.4 规划行动是否完成了(奖励负) if (policyConfig.PlanRewardRange.In(net.reward)) { net.actionMemory.Merge(net, net.actionPlanChain); return(net.actionPlanChain.Reset(makeNewActionPlan(time, session))); } //1.5 规划行动是否完成了(完成计划步长) if (net.actionPlanChain.Length >= net.actionPlanChain.Root.planSteps && net.actionPlanChain.Root.planSteps > 0) { net.actionMemory.Merge(net, net.actionPlanChain.Last); return(net.actionPlanChain.Reset(makeNewActionPlan(time, session))); } //1.6 再探索若干步后,预测本次规划行动的结果是否会是负值 /*if(net.actionPlanChain.Length >= net.actionPlanChain.Root.planSteps/4) * { * double expect = forcastActionPlan(); * if (expect < 0) * { * net.actionMemory.Merge(net, net.actionPlanChain); * return net.actionPlanChain.Reset(makeNewActionPlan(time, session)); * } * }*/ //1.7 继续本次行动计划 return(net.actionPlanChain.PutNext(ActionPlan.createMaintainPlan(net, time, "", net.actionPlanChain.Last.expect, net.actionPlanChain.Last.planSteps - 1))); }
public ActionPlanDto Map(ActionPlan entity) { ActionPlanDto dto = new ActionPlanDto() { Id = entity.Id, CompanyId = entity.CompanyId, Title = entity.Title, DateOfVisit = entity.DateOfVisit, VisitBy = entity.VisitBy, SubmittedOn = entity.SubmittedOn, AreasVisited = entity.AreasVisited, AreasNotVisited = entity.AreasNotVisited, ExecutiveSummaryDocumentLibraryId = entity.ExecutiveSummaryDocumentLibraryId, NoLongerRequired = entity.NoLongerRequired }; if(_withSites) { if (entity.Site != null) { dto.Site = new SiteDtoMapper().Map(entity.Site); } } if (_withActions) { if (entity.Actions != null) { if (_actionTasks) { dto.Actions = new ActionDtoMapper().WithTasks().WithStatus().Map(entity.Actions); } else { dto.Actions = new ActionDtoMapper().Map(entity.Actions); } } } if (_withStatus) { if (entity.Actions != null) { dto.Status = entity.GetStatusFromActions(); } } return dto; }
public ActionPlan Create(CreateActionPlanCommand command) { var actionPlan = new ActionPlan(command.Objective, command.CoachingProcess, command.Description); actionPlan.Validate(); _repository.Create(actionPlan); if (Commit()) { return(actionPlan); } return(null); }
private ActionPlan <L, V> CalculateActionPlan() { diagnosticData = new PlannerDiagnosticData <L, V>(); var goals = new List <IAIGoal <L, V> >(agent.Goals.GetGoals()); goals.Sort((x, y) => y.Priority.CompareTo(x.Priority)); if (goals.Count == 0) { agent.LogKeyInfo(this, "no goals found to plan for."); throw new NoActionPlanFoundException(); } foreach (var goal in goals) { diagnosticData.BeginGoalInfo(goal); if (IsAlreadyAchieved(goal) || !IsGoalAchieveableByActions(goal)) { diagnosticData.EndGoalInfo(false, new ActionPlan <L, V>()); continue; } goal.SetupGoal(); if (aStar.FindActionPlan(agent, goal)) { var actionPlan = aStar.GetActionPlan(); agent.LogKeyInfo(this, "action plan found for " + goal); if (isDiagnosticsEnabled) { diagnosticData.AddGoalMessage("Action plan found"); } var plan = new ActionPlan <L, V> { Goal = goal, Actions = actionPlan }; diagnosticData.EndGoalInfo(true, plan); return(plan); } agent.LogInfo(this, "failed to find action plan for " + goal); if (isDiagnosticsEnabled) { diagnosticData.AddGoalMessage("Unable to find action plan from available actions."); } diagnosticData.EndGoalInfo(false, new ActionPlan <L, V>()); } throw new NoActionPlanFoundException(); }
public async Task <int?> CreateActionPlanAsync(CreateActionPlanDto CreateActionPlanDto, CancellationToken ct) { ActionPlan ActionPlanEntity = _mapper.Mapper.Map <ActionPlan>(CreateActionPlanDto); _uow.ActionPlan.CreateActionPlan(ActionPlanEntity); if (await _uow.SaveChangesAsync(ct) > 0) { return(ActionPlanEntity.Id);// personsEntity.Id; } else { return(null); } }
public bool Approve(ActionPlan entity) { try { var item = _dbContext.ActionPlans.Find(entity.ID); item.ApprovedBy = entity.ApprovedBy; item.ApprovedStatus = entity.ApprovedStatus; _dbContext.SaveChanges(); return(true); } catch (Exception ex) { var message = ex.Message; return(false); } }
public HttpResponseMessage Put(int id, [FromBody] ActionPlan value) { var index = plans.FindIndex(x => x.Id == id); if (index < 0) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } else { value.Id = id; plans[index] = value; return(Request.CreateResponse(HttpStatusCode.OK)); } }
public void OnAgentPlanCalculated(Queue <IAIAction <L, V> > actions, IAIGoal <L, V> goal) { DisplayDiagnosticsInfo(aiAgent.GetDiagnostics()); if (actionPlan.IsValid) { previousPlans.Add(actionPlan); } actionPlan = new ActionPlan <L, V> { Goal = goal, Actions = new Queue <IAIAction <L, V> >(actions), }; DisplayActionInfo(); }
public void Given_Submitted_Checklist_When_No_Action_then_CanBeReverted_Returns_true() { var actionPlan = new ActionPlan() { Id = 1, Title = "My Action Plan", Deleted = false, }; var actions = new List<Action>(); actionPlan.Actions = actions; var checklist = new Checklist { Id = Guid.NewGuid(), ActionPlan = actionPlan, Status = "Submitted" }; var target = checklist.CanBeReverted(); Assert.IsTrue(target); }
public bool Update(ActionPlan entity) { try { var item = _dbContext.ActionPlans.Find(entity.ID); item.Title = entity.Title; item.Description = entity.Description; item.Tag = entity.Tag; item.Deadline = entity.Deadline; _dbContext.SaveChanges(); return(true); } catch (Exception ex) { var message = ex.Message; return(false); } }
/// <summary> /// 进行推理,返回推理后得到的动作 /// </summary> /// <returns></returns> public ActionPlan doImagination(int time, Session session) { //传播奖励 processReward(time); if (time < 50) { //net.actionMemory.Merge(net, net.actionPlanChain.Last,false); return(net.actionPlanChain.Reset(ActionPlan.CreateRandomPlan(net, time, "随机动作阶段"))); } //得到实际环境 (List <Vector> curObs, List <double> curActions) = net.GetSplitReceptorValues(); //得到近似场景 List <ActionPlan> plans = net.actionMemory.FindMatchActionPlans(); //如果行动计划不是全部,补齐全部可能的行动计划,且按照与本能行动一致的顺序排序 plans = checkActionPlansFull(plans, time); //遍历每个行动计划 for (int a = 0; a < plans.Count; a++) { if (!double.IsNaN(plans[a].evaulation) || plans[a].evaulation < 0) { continue; } List <double> actions = plans[a].actions; //执行直到无法执行,得到评估值 (double evulation, List <Vector> initObs, List <(InferenceRecord, double)> infRecords) = doActionImagination(plans[a], time, session); plans[a].evaulation = evulation; plans[a].inferenceRecords = infRecords; net.actionMemory.Merge(net, plans[a], false); } //制订行动计划 return(doActionPlan(plans, time)); }
public void given_outstanding_tasks_when_get_status_from_tasks_then_return_outstanding() { // Given var action = new Action() { ActionTasks = new List<ActionTask> { new ActionTask() { Deleted = false, TaskStatus = TaskStatus.Completed, TaskCompletionDueDate = DateTime.Now.AddDays(1) }, new ActionTask() { Deleted = false, TaskStatus = TaskStatus.Completed, TaskCompletionDueDate = DateTime.Now }, new ActionTask() { Deleted = false, TaskStatus = TaskStatus.Outstanding, TaskCompletionDueDate = DateTime.Now.AddDays(1) } } }; var actionPlan = new ActionPlan {Actions = new List<Action> {action}}; // When var result = actionPlan.GetStatusFromActions(); // Then Assert.That(result, Is.EqualTo(DerivedTaskStatusForDisplay.Outstanding)); }
/// <summary> /// 卸、取、拿 /// </summary> /// <param name="exchanges"></param> /// <param name="boxes"></param> /// <param name="priority"></param> /// <param name="isUnload">卸载</param> internal void LocateCheckOut(ref Exchange[] exchanges, List <BoxDevice> boxes, LocatePriority priority = LocatePriority.CabinetFirst, bool isUnload = false) { InitSchedule(exchanges); foreach (var exchange in exchanges) { // 取药按照过期时间、存储时间升序排序 var options = boxes.Where(b => b.Fills.Any(f => CanCheckOut(f, exchange.GoodsId, exchange.BatchNumber, exchange.ExpiredDate, isUnload))) .Select(b => new { Box = b, Node = b.Fills.First(f => f.GoodsId == exchange.GoodsId), }).OrderBy(o => o.Node.ExpiredDate).ThenBy(o => o.Node.StorageTime).ToList(); switch (priority) { case LocatePriority.CabinetFirst: options = options.Where(o => o.Box.BoxMode != BoxMode.VirtualBox).Concat(options.Where(o => o.Box.BoxMode == BoxMode.VirtualBox)).ToList(); break; case LocatePriority.VirtualFirst: options = options.Where(o => o.Box.BoxMode == BoxMode.VirtualBox).Concat(options.Where(o => o.Box.BoxMode != BoxMode.VirtualBox)).ToList(); break; } foreach (var option in options) { var box = JsonConvert.DeserializeObject <BoxDevice>(JsonConvert.SerializeObject(option.Box)); if (exchange is Prescription pre && pre.IsWhole) { // 医嘱,出院带药 var exists = (int)(option.Node.QtyExisted / exchange.Goods.Conversion); var expect = (int)((exchange.Qty - exchange.Plans.Sum(p => p.Qty)) / exchange.Goods.Conversion); if (exists > 0 && expect > 0) { var plan = new ActionPlan { Box = box, Mode = ExchangeMode.CheckOut, Qty = Math.Min(exists, expect) * exchange.Goods.Conversion, IsExecuted = false, }; exchange.Plans.Add(plan); option.Node.QtyExisted -= plan.Qty; } }
public void given_only_deleted_tasks_when_get_status_from_tasks_then_return_none() { // Given var plan = new ActionPlan(); plan.Actions = new List<Action>(); var actionTask = new ActionTask() { Deleted = true, TaskStatus = TaskStatus.Outstanding, TaskCompletionDueDate = DateTime.Now }; plan.Actions.Add(new Action{ActionTasks = new List<ActionTask>{actionTask}}); // When var result = plan.GetStatusFromActions(); // Then Assert.That(result, Is.EqualTo(DerivedTaskStatusForDisplay.None)); }
public void Given_Submitted_Checklist_is_reverted_then_Action_Plan_is_Removed() { var actionPlan = new ActionPlan() { Id = 1, Title = "My Action Plan" }; var actions = new List<Action>(); actionPlan.Actions = actions; var user = new UserForAuditing(); var checklist = new Checklist { Id = Guid.NewGuid(), Status = "Submitted", ActionPlan = actionPlan }; checklist.Revert(user,"Test User"); Assert.That(checklist.ActionPlan, Is.EqualTo(null)); }
public async Task <JsonResult> Update(ActionPlan item) { return(Json(await new ActionPlanDAO().Update(item), JsonRequestBehavior.AllowGet)); }
/// <summary> /// 存、退、还 /// </summary> /// <param name="exchanges"></param> /// <param name="boxes"></param> /// <param name="priority"></param> /// <param name="extension">扩展未占位药盒</param> /// <param name="cross">跨抽屉或跨柜子</param> internal void LocateCheckIn(ref Exchange[] exchanges, List <BoxDevice> boxes, bool extension, bool cross, LocatePriority priority = LocatePriority.CabinetFirst) { InitSchedule(exchanges); foreach (var exchange in exchanges) { List <(BoxDevice Box, NodeGoodsInfo Node)> options; if (extension) { // 组合 // 1. 相同物品[GoodsId]且无现存量,2. 未占位且同类药盒,3. 不同物品[GoodsId]且无现存量(保留一个占位),4. 相同物品[GoodsId 批号 有效期]且有现存量 var box2 = new List <BoxDevice>(); var box3 = new List <BoxDevice>(); var box1 = boxes.Where(b => b.Fills.Any(f => f.GoodsId == exchange.GoodsId && f.QtyExisted == 0)).ToList(); var box4 = boxes.Where(b => b.Fills.Any(f => f.QtyExisted > 0 && CanCheckIn(f, exchange.GoodsId, exchange.BatchNumber, exchange.ExpiredDate))).ToList(); var goodsbox = box1.Concat(box4).FirstOrDefault(); box2 = boxes.Where(b => b.Fills.Count() == 0 && IsSimilarBox(goodsbox, b, cross)).Select(b => { b.Fills = goodsbox?.Fills.Select(f => new NodeGoodsInfo { GoodsId = f.GoodsId, Goods = f.Goods, Barcodes = f.Barcodes, BatchNumber = f.BatchNumber, ExpiredDate = f.ExpiredDate, QtyExisted = 0, QtyMax = f.QtyMax, StorageTime = f.StorageTime }).ToList(); return(b); }).ToList(); var different = boxes.Where(b => b.Fills.All(f => f.QtyExisted == 0 && f.GoodsId != exchange.GoodsId) && IsSimilarBox(goodsbox, b, cross)).ToList(); var exist = boxes.Where(b => b.Fills.Any(f => f.QtyExisted > 0) && IsSimilarBox(goodsbox, b, cross)).ToList(); var newdifferent = new List <BoxDevice>(); foreach (var item in different) { if (!newdifferent.Where(n => n.Fills.Select(f => new { f.GoodsId, f.BatchNumber, f.ExpiredDate }).OrderBy(o => o.GoodsId).SequenceEqual(item.Fills.Select(f => new { f.GoodsId, f.BatchNumber, f.ExpiredDate }).OrderBy(o => o.GoodsId))).Any()) { newdifferent.Add(item); } } foreach (var item in newdifferent) { if (!exist.Where(b => b.Fills.Select(f => new { f.GoodsId, f.BatchNumber, f.ExpiredDate }).OrderBy(o => o.GoodsId).SequenceEqual(item.Fills.Select(f => new { f.GoodsId, f.BatchNumber, f.ExpiredDate }).OrderBy(o => o.GoodsId))).Any()) { different.Remove(item); } } box3 = different.Select(b => { b.Fills = goodsbox?.Fills.Select(f => new NodeGoodsInfo { GoodsId = f.GoodsId, Goods = f.Goods, Barcodes = f.Barcodes, BatchNumber = f.BatchNumber, ExpiredDate = f.ExpiredDate, QtyExisted = 0, QtyMax = f.QtyMax, StorageTime = f.StorageTime }).ToList(); return(b); }).ToList(); options = box1.Concat(box2).Concat(box3).Concat(box4).Select(b => (b, b.Fills.First(f => f.GoodsId == exchange.GoodsId))).ToList(); } else { // 优先填充取量少的 options = boxes.Where(b => b.Fills.Any(f => CanCheckIn(f, exchange.GoodsId, exchange.BatchNumber, exchange.ExpiredDate))) .Select(b => (Box: b, Node: b.Fills.First(f => f.GoodsId == exchange.GoodsId))).OrderBy(o => o.Node.QtyMax - o.Node.QtyExisted).ToList(); } switch (priority) { case LocatePriority.CabinetFirst: options = options.Where(o => o.Box.BoxMode != BoxMode.VirtualBox).Concat(options.Where(o => o.Box.BoxMode == BoxMode.VirtualBox)).ToList(); break; case LocatePriority.VirtualFirst: options = options.Where(o => o.Box.BoxMode == BoxMode.VirtualBox).Concat(options.Where(o => o.Box.BoxMode != BoxMode.VirtualBox)).ToList(); break; } foreach (var option in options) { var qty = exchange.Qty - exchange.Plans.Sum(p => p.Qty); if (qty > 0) { var plan = new ActionPlan { Box = option.Box, Mode = ExchangeMode.CheckIn, Qty = Math.Min(qty, option.Node.QtyMax - option.Node.QtyExisted), IsExecuted = false, }; exchange.Plans.Add(plan); option.Node.QtyExisted += plan.Qty; } } } }
public void Given_Submitted_Checklist_is_reverted_then_properties_are_set() { var actionPlan = new ActionPlan() { Id = 1, Title = "My Action Plan" }; var actions = new List<Action>(); actionPlan.Actions = actions; var user = new UserForAuditing(); var checklist = new Checklist { Id = Guid.NewGuid(), Status = "Submitted", ActionPlan = actionPlan }; checklist.Revert(user,"Test User"); Assert.That(checklist.Status,Is.EqualTo("Assigned")); Assert.That(checklist.ExecutiveSummaryDocumentLibraryId, Is.Null); Assert.That(checklist.ChecklistSubmittedBy, Is.Null); Assert.That(checklist.ChecklistSubmittedOn, Is.Null); Assert.That(checklist.LastModifiedBy, Is.EqualTo(user)); }
private ActionPlan doActionPlan(List <ActionPlan> plans, int time) { //找到本能行动计划 List <double> instictAction = Session.instinctActionHandler(net, time); ActionPlan instinctPlan = plans.FirstOrDefault(p => p.actions[0] == instictAction[0]); //找到当前行动计划 ActionPlan maintainPlan = plans.FirstOrDefault(p => p.actions[0] == 0.5); //记录各个方向的评估 List <(List <double>, double)> actionEvaulationRecords = plans.ConvertAll(p => (p.actions, p.evaulation)); if (this.net.reward < 0) { if (instinctPlan != maintainPlan && (double.IsNaN(instinctPlan.evaulation) || instinctPlan.evaulation >= 0)) { instinctPlan.judgeTime = time; instinctPlan.judgeType = ActionPlan.JUDGE_INSTINCT; instinctPlan.reason = "行动受挫,选择本能"; instinctPlan.actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(instinctPlan)); } for (int i = 1; i < plans.Count; i++) { if (plans[i] == maintainPlan) { continue; } if (double.IsNaN(plans[i].evaulation) || plans[i].evaulation >= 0) { plans[i].judgeTime = time; plans[i].judgeType = ActionPlan.JUDGE_INFERENCE; plans[i].reason = "行动受挫,顺序选择"; plans[i].actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(plans[i])); } } //选择评估值最大的 List <double> fevas = plans.ConvertAll(p => p.evaulation); List <int> fevaIndex = fevas.argsort(); fevaIndex.Reverse(); for (int i = 0; i < 3; i++) { if (plans[fevaIndex[i]] == maintainPlan) { continue; } plans[fevaIndex[i]].judgeTime = time; plans[fevaIndex[i]].judgeType = ActionPlan.JUDGE_RANDOM; plans[fevaIndex[i]].reason = "行动受挫,择优选择"; plans[fevaIndex[i]].actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(plans[fevaIndex[i]])); } int index = Network.rng.Next(0, plans.Count); while (plans[index] == maintainPlan) { index = Network.rng.Next(0, plans.Count); } plans[index].judgeTime = time; plans[index].judgeType = ActionPlan.JUDGE_RANDOM; plans[index].reason = "行动受挫,随机选择"; plans[index].actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(plans[index])); } if (net.actionPlanChain.GetMaintainCount() < 20) { maintainPlan.judgeTime = time; maintainPlan.judgeType = (instinctPlan == maintainPlan) ? ActionPlan.JUDGE_INSTINCT : ActionPlan.JUDGE_MAINTAIN; maintainPlan.reason = "动作维持"; maintainPlan.actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(maintainPlan)); } if ((double.IsNaN(instinctPlan.evaulation) || instinctPlan.evaulation >= 0)) { instinctPlan.judgeTime = time; instinctPlan.judgeType = ActionPlan.JUDGE_INSTINCT; instinctPlan.reason = "选择本能"; instinctPlan.actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(instinctPlan)); } for (int i = 1; i < plans.Count; i++) { if (plans[i] == maintainPlan) { continue; } if (double.IsNaN(plans[i].evaulation) || plans[i].evaulation >= 0) { plans[i].judgeTime = time; plans[i].judgeType = ActionPlan.JUDGE_INFERENCE; plans[i].reason = "选择本能相似行动"; plans[i].actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(plans[i])); } } //选择评估值最大的 List <double> evas = plans.ConvertAll(p => p.evaulation); int evaIndex = evas.argmax(); plans[evaIndex].judgeTime = time; plans[evaIndex].judgeType = ActionPlan.JUDGE_RANDOM; plans[evaIndex].reason = "择优选择"; plans[evaIndex].actionEvaulationRecords = actionEvaulationRecords; return(net.actionPlanChain.PutNext(plans[evaIndex])); }
public void ActionPlanPropertiesNotNullTest() { var plan = new ActionPlan(); Assert.IsNotNull(plan.Name); Assert.IsNotNull(plan.Description); Assert.IsNotNull(plan.Properties); Assert.IsNotNull(plan.Actions); }
public void Create(ActionPlan ActionPlan) { _context.ActionPlan.Add(ActionPlan); }
/// <summary> /// 1.处理reward /// 1.1 将当前环境场景放入 /// 2.生成测试行动集 /// 3.对每一个行动,计算评估值 /// 4.选择评估值最大行动 /// </summary> /// <param name="time"></param> /// <param name="session"></param> /// <returns></returns> public override ActionPlan execute(int time, Session session) { //1.1 处理reward processReward(time); //1.2 仍在随机动作阶段 if (time < 1) { return(net.actionPlanChain.PutNext(ActionPlan.CreateRandomPlan(net, time, "随机漫游"))); } if (net.reward > 0 && net.actionPlanChain.Length > 0 && net.actionPlanChain.Root.planSteps > net.actionPlanChain.Length) { return(net.actionPlanChain.PutNext(ActionPlan.createMaintainPlan(net, time, "maintain", 0, net.actionPlanChain.Last.planSteps - 1))); } //1.3 创建测试动作集 List <double> instinctAction = Session.instinctActionHandler(net, time); List <double> maintainAction = ActionPlan.MaintainAction; List <List <double> > testActionSet = this.CreateTestActionSet(instinctAction); //如果碰撞了,将维持动作删除去 if (net.reward <= 0) { int mindex = testActionSet.IndexOf(a => a[0] == 0.5); if (mindex >= 0) { testActionSet.RemoveAt(mindex); } } //1.4 寻找每个测试动作的匹配记录,计算所有匹配记录的均值 double[] evaluations = new double[testActionSet.Count]; List <InferenceRecord>[] rs = new List <InferenceRecord> [testActionSet.Count]; for (int i = 0; i < evaluations.Length; i++) { evaluations[i] = double.NaN; } List <Vector> envValues = net.GetReceptorSceneValues(); for (int i = 0; i < testActionSet.Count; i++) { List <InferenceRecord> records = net.GetMatchInfRecords(envValues, testActionSet[i], time); rs[i] = new List <InferenceRecord>(records); List <InferenceRecord> evaluatedRecords = records.FindAll(r => !double.IsNaN(r.evulation)); if (evaluatedRecords != null && evaluatedRecords.Count > 0) { evaluations[i] = evaluatedRecords.ConvertAll(r => r.evulation).Average(); } } for (int i = 0; i < testActionSet.Count; i++) { if (this.net.reward < -1.0 && testActionSet[i][0] == 0.5) { evaluations[i] = double.MinValue; } if (testActionSet[i][0] == 0.0 && net.actionPlanChain.Length >= 2 && net.actionPlanChain.ToList()[net.actionPlanChain.Length - 1].actions[0] == 0 && net.actionPlanChain.ToList()[net.actionPlanChain.Length - 2].actions[0] == 0) { evaluations[i] = double.MinValue; } } ActionPlan plan = null; //寻找是否有为评估的,优先评估它 int index = -1; for (int i = 0; i < evaluations.Length; i++) { if (double.IsNaN(evaluations[i])) { index = i; break; } } if (index >= 0) { plan = net.actionPlanChain.PutNext(ActionPlan.CreateActionPlan(net, testActionSet[index], time, ActionPlan.JUDGE_INFERENCE, "未知评估")); if (rs[index] != null && rs[index].Count > 0) { plan.inferenceRecords = rs[index].ConvertAll(r => (r, 0.0)); } plan.evaulation = evaluations[index]; if (plan.actions[0] == instinctAction[0]) { plan.planSteps = 0; } else { plan.planSteps = 0; } return(plan); } index = evaluations.ToList().IndexOf(evaluations.Max()); plan = net.actionPlanChain.PutNext(ActionPlan.CreateActionPlan(net, testActionSet[index], time, ActionPlan.JUDGE_INFERENCE, "最大评估")); if (rs[index] != null && rs[index].Count > 0) { plan.inferenceRecords = rs[index].ConvertAll(r => (r, 0.0)); } plan.evaulation = evaluations[index]; if (plan.actions[0] == instinctAction[0]) { plan.planSteps = 0; } else { plan.planSteps = 0; } return(plan); }
public async Task <IActionResult> Update([FromBody] ActionPlan item) { return(Ok(await _actionPlanService.Update(item))); }
public static bool CreateActionPlanScopeIsValid(this ActionPlan actionPlan) { return(AssertionConcern.IsSatisfiedBy( AssertionConcern.AssertArgumentNotNull(actionPlan.Description, Errors.InvalidDescription) )); }
public void Post([FromBody] ActionPlan actionPlan) { _repository.Insert(actionPlan); }
private (double, List <Vector>, List <(InferenceRecord, double)>) doActionImagination(ActionPlan plan, int time, Session session) { //取得感知环境值,动作感知替换为预想动作 List <Vector> observations = net.GetReceoptorValues(); net.ReplaceWithAction(observations, plan.actions); (List <Vector> orginEnvValues, List <double> orginAction) = net.GetSplitReceptorValues(); List <Vector> initObs = new List <Vector>(); foreach (Vector v in orginEnvValues) { initObs.Add(v.clone()); } //推理下一个环境变化 ////虚拟初始化 net.thinkReset(); ////对网络进行虚拟激活,得到新的观察值 int maxsteps = 5, step = 0; double evluation = double.NaN; List <(InferenceRecord, double)> infRecords = new List <(InferenceRecord, double)>(); while (true) { //初始化感知节点 for (int i = 0; i < net.Receptors.Count; i++) { net.Receptors[i].think(net, time, observations[i]); } //激活处理节点 List <Handler> handlers = this.getCanThinkHandlers(net, time); while (handlers != null && !handlers.All(n => n.IsThinkCompleted(time))) { net.Handlers.ForEach(n => n.think(net, time, null)); } //取得有效推理节点 List <Inference> infs = getCanThinkInferences(net, time); if (infs == null || infs.Count <= 0) { break; } //将观察值情况,后面要存放下一次观察 for (int i = 0; i < observations.Count; i++) { observations[i] = null; } //遍历所有推理节点 double[] distances = new double[observations.Count]; double eva = 0; foreach (Inference inte in infs) { //得到推理节点后置变量 List <int> varIds = inte.getGene().getVariableIds(); List <int> receptorIndexs = varIds.ConvertAll(id => net.Receptors.IndexOf((Receptor)net[id])); //得到条件值 List <Vector> condValues = inte.getGene().getConditionIds().ConvertAll(id => net[id]).ConvertAll(node => node.getThinkValues(time)); //匹配推理场景 var postvar = inte.forward_inference(condValues); if (postvar.postValues == null) { continue; } if (step == 0 && !infRecords.ConvertAll(t => t.Item1).Contains(postvar.record) && postvar.record != null) { infRecords.Add((postvar.record, postvar.distance)); } //更新观察 for (int i = 0; i < postvar.postValues.Count; i++) { if (receptorIndexs[i] == -1) { continue; } if (distances[i] == 0 || distances[i] > postvar.distance) { observations[receptorIndexs[i]] = postvar.postValues[i].clone(); } } //更新评估值 eva += postvar.record.evulation * (postvar.distance < 1 ? 1 - postvar.distance : 0.001); } step += 1; //检查是否所有感知都已经被观察 if (observations.Count(v => v == null) != plan.actions.Count || step >= maxsteps) { if (eva != 0) { evluation = eva; } break; } //动作改成0.5,即维持不变 net.ReplaceMaintainAction(observations); } return(evluation, initObs, infRecords); }
public void Delete(ActionPlan ActionPlan) { _context.ActionPlan.Remove(ActionPlan); }
public void When_Search_Then_map_returned_entities_with_actions_to_dtos() { //given var actionPlan = new ActionPlan() { Id = 1234L, CompanyId = 1L, Title = "Action Plan1", Site = new Site { SiteId = 1L }, DateOfVisit = DateTime.Now, VisitBy = "Consultant1", SubmittedOn = DateTime.Now.AddDays(-1), }; var action = new Action() { Id = 123123, Title = "test title", AreaOfNonCompliance = "area not compliant", ActionRequired = "action required test", TargetTimescale = "do this now", AssignedTo = new Employee(){Id = Guid.NewGuid(), Forename = "Fred", Surname = "Flintstone"}, DueDate = DateTime.Now.AddDays(10), Reference = "The Reference", Category = ActionCategory.Action }; actionPlan.Actions = new List<Action>() {action}; var target = GetTarget(); _actionPlanRepository.Setup( x => x.Search(It.IsAny<IList<long>>(),It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<long?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<ActionPlanOrderByColumn>(), It.IsAny<bool>())).Returns(new List<ActionPlan>() {actionPlan}); //when var result = target.Search(new SearchActionPlanRequest()); //then Assert.That(result.First().Actions.Count(), Is.GreaterThan(0)); Assert.That(result.First().Actions.First().Id, Is.EqualTo(action.Id)); Assert.That(result.First().Actions.First().Title, Is.EqualTo(action.Title)); Assert.That(result.First().Actions.First().AreaOfNonCompliance, Is.EqualTo(action.AreaOfNonCompliance)); Assert.That(result.First().Actions.First().ActionRequired, Is.EqualTo(action.ActionRequired)); Assert.That(result.First().Actions.First().TargetTimescale, Is.EqualTo(action.TargetTimescale)); Assert.That(result.First().Actions.First().AssignedTo, Is.EqualTo(action.AssignedTo.Id)); Assert.That(result.First().Actions.First().DueDate, Is.EqualTo(action.DueDate)); Assert.That(result.First().Actions.First().Reference, Is.EqualTo(action.Reference)); Assert.That(result.First().Actions.First().Category, Is.EqualTo(action.Category)); }
public AddCommentVM Add(ActionPlan entity, string subject) { var user = _dbContext.Users; var itemActionPlanDetail = new ActionPlanDetail(); var listEmail = new List <string[]>(); var listUserID = new List <int>(); var listFullNameTag = new List <string>(); var listTags = new List <Tag>(); var itemTag = _dbContext.Tags; try { if (entity.Description.IndexOf(";") == -1) { entity.Description = entity.Description; } else { var des = string.Empty; entity.Description.Split(';').ToList().ForEach(line => { des += line + " "; }); entity.Description = des; } _dbContext.ActionPlans.Add(entity); _dbContext.SaveChanges(); if (!entity.Tag.IsNullOrEmpty()) { string[] arrayString = new string[5]; if (entity.Tag.IndexOf(",") == -1) { var userItem = user.FirstOrDefault(x => x.Username == entity.Tag); if (userItem != null) { var tag = new Tag(); tag.ActionPlanID = entity.ID; tag.UserID = (int?)userItem.ID ?? 0; _dbContext.Tags.Add(tag); _dbContext.SaveChanges(); arrayString[0] = user.FirstOrDefault(x => x.ID == entity.UserID).FullName; arrayString[1] = userItem.Email; arrayString[2] = entity.Link; arrayString[3] = entity.Title; arrayString[4] = entity.Description; listFullNameTag.Add(userItem.FullName); listEmail.Add(arrayString); } } else { var list = entity.Tag.Split(','); var listUsers = _dbContext.Users.Where(x => list.Contains(x.Username)).ToList(); foreach (var item in listUsers) { var tag = new Tag(); tag.ActionPlanID = entity.ID; tag.UserID = item.ID; listTags.Add(tag); arrayString[0] = user.FirstOrDefault(x => x.ID == entity.UserID).FullName; arrayString[1] = item.Email; arrayString[2] = entity.Link; arrayString[3] = entity.Title; arrayString[4] = entity.Description; listFullNameTag.Add(item.FullName); listEmail.Add(arrayString); } _dbContext.Tags.AddRange(listTags); _dbContext.SaveChanges(); } } //Add vao Notification var notify = new Notification(); notify.ActionplanID = entity.ID; notify.Content = entity.Description; notify.UserID = entity.UserID; notify.Title = entity.Title; notify.Link = entity.Link; notify.Tag = string.Join(",", listFullNameTag); notify.Title = subject; new NotificationDAO().Add(notify); return(new AddCommentVM { Status = true, ListEmails = listEmail }); } catch (Exception ex) { var message = ex.Message; return(new AddCommentVM { Status = true, ListEmails = listEmail }); } }
public void Update(ActionPlan ActionPlan) { _context.Entry<ActionPlan>(ActionPlan).State = EntityState.Modified; }