Exemplo n.º 1
0
        public static List <ValidationMessage> RemoveGoal(
            ValidatableParameter <Guid> goalId
            )
        {
            List <ValidationMessage> errors = new List <ValidationMessage>();

            if (goalId.Value == Guid.Empty)
            {
                errors.Add(new ValidationMessage {
                    MessageText = "Goal must be supplied", Source = goalId.Source
                });
            }

            //perform add if no errors
            if (errors.Count == 0)
            {
                AllGoals items     = new AllGoals();
                Goal     existItem = items.Where(i => i.GoalId == goalId.Value).Single();

                if (existItem != null)
                {
                    items.Remove(existItem);
                }

                items.Save();
            }

            return(errors);
        }
        /// <summary>
        /// Deletes the selected goal.
        /// </summary>
        public void DeleteGoal()
        {
            GoalViewModel selectedGoalVM = AllGoals.FirstOrDefault(g => g.IsSelected == true);

            if (selectedGoalVM != null && WPFMessageBox.Show(Properties.Resources.Delete_Confirm, Properties.Resources.Goals_Delete_Confirm, WPFMessageBoxButtons.YesNo, WPFMessageBoxImage.Question) == WPFMessageBoxResult.Yes)
            {
                _goalData.DeleteGoal(_goalData.GetGoalByGoalId(selectedGoalVM.GoalId), _projectData, _taskData);
                selectedGoalVM.Dispose();
            }
        }
        /// <summary>
        /// Launches the edit goal window.
        /// </summary>
        public void EditGoal()
        {
            GoalView window = new GoalView();

            GoalViewModel selectedGoalVM = AllGoals.FirstOrDefault(g => g.IsSelected == true);

            using (var viewModel = new GoalViewModel(_goalData.GetGoalByGoalId(selectedGoalVM.GoalId), _goalData, _projectData, _taskData))
            {
                this.ShowWorkspaceAsDialog(window, viewModel);
            }
        }
Exemplo n.º 4
0
 public static List <Goal> GetAllGoals(bool completeOnly)
 {
     if (completeOnly)
     {
         return(AllGoals.GetAllComplete());
     }
     else
     {
         return(AllGoals.GetAllIncomplete());
     }
 }
Exemplo n.º 5
0
        public static List <ReportingGoalSummary> GetReportingGoals(DateTime startDate, DateTime endDate, IEnumerable <string> fileNames)
        {
            //get all users for efficiency (rather than looking each one up from file each time)
            List <User> users = OperationsReadOnly.GetAllUsers();

            List <ReportingGoalSummary> results = new List <ReportingGoalSummary>();

            foreach (string currFile in fileNames)
            {
                List <Goal> entries = AllGoals.GetAllCompleteBetween(currFile, startDate, endDate);

                foreach (Goal currEntry in entries)
                {
                    ReportingGoalSummary item = new ReportingGoalSummary();

                    item.ActualCompletionDate = currEntry.ActualCompletionDate;
                    item.Completed            = currEntry.Completed;
                    item.Description          = currEntry.Description;
                    item.GoalId                 = currEntry.GoalId;
                    item.Improvements           = currEntry.Improvements;
                    item.Positives              = currEntry.Positives;
                    item.ResultMeasure          = currEntry.ResultMeasure;
                    item.ResultMeasureRating    = currEntry.ResultMeasureRating;
                    item.ResultTimelinessRating = currEntry.ResultTimelinessRating;
                    item.TargetCompletionDate   = currEntry.TargetCompletionDate;
                    item.TargetMeasure          = currEntry.TargetMeasure;
                    User usr = users.Where(i => i.UserId == currEntry.UserId).FirstOrDefault();
                    item.UserDisplayName = usr == null ? string.Empty : usr.DisplayName;
                    item.UserId          = currEntry.UserId;

                    results.Add(item);
                }
            }

            return(results);
        }
 bool CanDeleteGoal()
 {
     return(AllGoals.Count(g => g.IsSelected == true) == 1);
 }
        public AllGoalsViewModel(GoalData goalData, ProjectData projectData, TaskData taskData)
        {
            if (goalData == null)
            {
                throw new ArgumentNullException("goalData");
            }

            if (projectData == null)
            {
                throw new ArgumentNullException("projectData");
            }

            if (taskData == null)
            {
                throw new ArgumentNullException("taskData");
            }

            base.DisplayName  = Properties.Resources.Goals_DisplayName;
            base.DisplayImage = "pack://application:,,,/TaskConqueror;Component/Assets/Images/goal.png";

            _goalData    = goalData;
            _projectData = projectData;
            _taskData    = taskData;

            // Subscribe for notifications of when a new goal is saved.
            _goalData.GoalAdded   += this.OnGoalAdded;
            _goalData.GoalUpdated += this.OnGoalUpdated;
            _goalData.GoalDeleted += this.OnGoalDeleted;

            // Populate the AllGoals collection with GoalViewModels.
            this.AllGoals = new ObservableCollection <GoalViewModel>();
            this.AllGoals.CollectionChanged += this.OnCollectionChanged;

            this.PageFirst();

            SortColumns.Add(new SortableProperty()
            {
                Description = "Title", Name = "Title"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Status", Name = "StatusId"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Category", Name = "CategoryId"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Date Created", Name = "CreatedDate"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Date Completed", Name = "CompletedDate"
            });

            SelectedSortColumn = SortColumns.FirstOrDefault();

            // select the first goal
            GoalViewModel firstGoal = AllGoals.FirstOrDefault();

            if (firstGoal != null)
            {
                firstGoal.IsSelected = true;
            }
        }
Exemplo n.º 8
0
    private bool UpdateSensorsSystemsNGoalPriorities()
    {
        int startIndex = currentSensorRefreshIndex;

        for (int i = 0; i < brain.sensorUpdatePerFrame;)
        {
            float deltaTimeSinceLastWorkedTime = Time.time - pollingSensors[currentSensorRefreshIndex].LastWorkedUpdateTime;
            if (deltaTimeSinceLastWorkedTime > pollingSensors[currentSensorRefreshIndex].updateInterval)
            {
                pollingSensors[currentSensorRefreshIndex].DeltaTimeSinceLastWork = deltaTimeSinceLastWorkedTime;

#if UNITY_EDITOR
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
#endif
                if (pollingSensors[currentSensorRefreshIndex].OnUpdate(this))
                {
                    pollingSensors[currentSensorRefreshIndex].LastWorkedUpdateTime = Time.time;
                    i++;
                }
#if UNITY_EDITOR
                if (brain.sensorDebug)
                {
                    sw.Stop();
                    brain.ShowDebugMessage("Updated Sensor " + pollingSensors[currentSensorRefreshIndex] + "MS:" + sw.ElapsedMilliseconds);
                }
#endif
            }

            currentSensorRefreshIndex++;
            currentSensorRefreshIndex = currentSensorRefreshIndex % pollingSensors.Count;

            if (currentSensorRefreshIndex == startIndex)
            {
                break;
            }
        }

        Memory.Update();

        bool needToReplanBySystems          = false;
        bool needToReevaluateGoalsBySystems = false;
        for (int i = 0; i < allSystems.Count; i++)
        {
            float deltaTime = Time.time - allSystems[i].LastUpdateTime;
            if (deltaTime > allSystems[i].updateInterval)
            {
#if UNITY_EDITOR
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
#endif
                allSystems[i].DeltaTime = deltaTime;
                bool ntReplan = false; bool ntReevaluateGoals = false;                 //safety
                allSystems[i].OnUpdate(ref ntReplan, ref ntReevaluateGoals, this);
                allSystems[i].LastUpdateTime = Time.time;
                if (needToReplanBySystems == false)
                {
                    needToReplanBySystems = ntReplan;                                                 //safety
                }
                if (needToReevaluateGoalsBySystems == false)
                {
                    needToReevaluateGoalsBySystems = ntReevaluateGoals;                                                          //safety
                }
#if UNITY_EDITOR
                sw.Stop();
                if (brain.systemDebug)
                {
                    brain.ShowDebugMessage("Updated System " + allSystems[i] + "MS:" + sw.ElapsedTicks);
                }
#endif
            }
        }
        bool needToReEvaluteGoals = needToReevaluateGoalsBySystems || _tempForceToReEvaluateGoalsTime < 0;

        //强制重新评估Goals 倒计时
        _tempForceToReEvaluateGoalsTime -= Time.deltaTime;

        if (needToReEvaluteGoals)
        {
            //TODO: 这里我有一个疑问 如果重新评估了Goals 之前执行的Action怎么办?
            _tempForceToReEvaluateGoalsTime = brain.forceToCheckGoalPrioritiesInterval;

            //拷贝一个旧列表
            List <AIGoal> oldList = new List <AIGoal>(AllGoals);
            foreach (AIGoal goal in AllGoals)
            {
                goal.CalculatePriority(this);                //重新计算优先级
            }


            // Order goals by priority, if order is changed replan to satisfy the most important goal
            // 按优先级排序目标,如果排序变更,重新策划最重要的目标
            AllGoals = AllGoals.OrderBy(x => x.priority).ToList();

            //检测比当前优先级 还 优先的 目标 是否可用
            bool goalsBeforeApplicapable = false;
            int  index = AllGoals.FindIndex(x => x == currentGoal);
            for (int i = index - 1; i >= 0; i--)
            {
                if (AllGoals[i].IsApplicapable(this))
                {
                    goalsBeforeApplicapable = true;
                    break;
                }
            }

            for (int i = 0; i < AllGoals.Count; i++)
            {
                //如果优先级发生改变或出现了更优先且可用的
                if (AllGoals[i] != oldList[i] || goalsBeforeApplicapable)                 // priority changed or current goal is not the most important
                {
                    needToReplanBySystems = true;
                    planPending           = true;
                    break;
                }
            }
        }
        bool retVal = needToReplanBySystems;

        return(retVal);
    }
Exemplo n.º 9
0
    public void OnAwake()
    {
        MakeFakeStartWorld();
        stateSystemAnimator = GetStateSystem <AIStateSystemAnimator>();

        allSensors = allSensors.Distinct().ToList();
        foreach (var sensor in allSensors)
        {
            sensor.OnStart(this);
        }
        foreach (var sensor in pollingSensors)
        {
            sensor.LastWorkedUpdateTime = -sensor.updateInterval;
        }

        allActions = allActions.Distinct().ToList();
        foreach (var action in allActions)
        {
            action.LastUsedAt = -Mathf.Infinity;
            action.OnStart(this);
        }

        allSystems = allSystems.Distinct().ToList();
        foreach (var system in allSystems)
        {
            system.LastUpdateTime = -system.updateInterval;
            system.OnStart(this);
        }

        AllGoals = AllGoals.Distinct().ToList();
        foreach (var goal in AllGoals)
        {
            goal.lastUsedAt = -Mathf.Infinity;

            //goal.priority 确保这个数值位于 priorityRange的 x与y 之间 这部分代码可以优化掉 OnStart 内部已经调用了 Mathf.Clamp
            //goal.priority = (goal.priority > goal.priorityRange.y || goal.priority < goal.priorityRange.x) ?
            //	goal.priorityRange.y : goal.priority;
            goal.OnStart(this);
        }

        allStateSystems = allStateSystems.Distinct().ToList();
        foreach (var ss in allStateSystems)
        {
            ss.OnStart(this);
        }
        currentState = allStates.Find(x => x.StateType == ET.StateType.Idle);

        foreach (AIAction action in allActions)
        {
            if (!action.NeededStatesExists(allStateSystems) || !action.NeededSensorsExists(allSensors))
            {
                action.DisabledCompletely = true;
#if UNITY_EDITOR
                Debug.Log(action.ToString() + "disabled, needed sensor or statesystem couldn't be found");
#endif
            }
            else
            {
                action.DisabledCompletely = false;
            }
        }
        allActions.RemoveAll(x => x.DisabledCompletely);

        //初始化一个策划
        planner = new Planner(allActions, AllGoals);

        if (stateSystemAnimator == null)
        {
            brain.stopPlanning = true;
#if UNITY_EDITOR
            Debug.Log("Stopped Planning.");
            Debug.Log("No animation system found.");
#endif
        }
    }
Exemplo n.º 10
0
        public static List <ValidationMessage> SaveGoal(
            ValidatableParameter <Guid> goalId,
            ValidatableParameter <Guid> userId,
            ValidatableParameter <string> description,
            ValidatableParameter <string> targetMeasure,
            ValidatableParameter <DateTime> targetCompletionDate,
            ValidatableParameter <bool> isCompleted,
            ValidatableParameter <string> resultMeasure,
            ValidatableParameter <int> resultMeasureRating,
            ValidatableParameter <DateTime> resultCompletionDate,
            ValidatableParameter <int> resultCompletionDateRating,
            ValidatableParameter <string> positives,
            ValidatableParameter <string> improvements
            )
        {
            List <ValidationMessage> errors = new List <ValidationMessage>();

            if (description == null || string.IsNullOrEmpty(description.Value) || description.Value.Trim().Length == 0)
            {
                errors.Add(new ValidationMessage {
                    MessageText = "Description must be supplied", Source = description.Source
                });
            }

            if (errors.Count == 0)
            {
                AllGoals items     = new AllGoals();
                Goal     existItem = new Goal();

                existItem.ActualCompletionDate = resultCompletionDate.Value;
                existItem.Completed            = isCompleted.Value;
                existItem.Description          = description.Value;
                existItem.GoalId                 = goalId.Value;
                existItem.Improvements           = improvements.Value;
                existItem.Positives              = positives.Value;
                existItem.ResultMeasure          = resultMeasure.Value;
                existItem.ResultMeasureRating    = resultMeasureRating.Value;
                existItem.ResultTimelinessRating = resultCompletionDateRating.Value;
                existItem.TargetCompletionDate   = targetCompletionDate.Value;
                existItem.TargetMeasure          = targetMeasure.Value;
                existItem.UserId                 = userId.Value;

                if (existItem.GoalId == Guid.Empty)
                {
                    existItem.GoalId = Guid.NewGuid();
                    items.Add(existItem);
                }
                else
                {
                    Goal updItem = items.Where(i => i.GoalId == goalId.Value).Single();
                    if (updItem == null)
                    {
                        throw new ApplicationException(string.Format("Goal with id '{0}' not found", goalId.Value.ToString()));
                    }
                    else
                    {
                        //save it
                        items.Remove(updItem);
                        items.Add(existItem);
                    }
                }

                items.Save();
            }

            return(errors);
        }