public IActionResult OnPost(int id) { TaskStat = taskData.GetStatByTaskId(id); TaskStat = taskData.UpdateWorkTime(TaskStat, DateTime.Now); return(RedirectToPage("./Statistics")); }
public TaskStatistics AddNewLine(TaskStatistics newLine, string startTime, string endTime) { newLine.Id = taskStatistics.Max(s => s.Id) + 1; newLine.StartTime = startTime; newLine.EndTime = endTime; newLine.WorkTime = (DateTime.Parse(newLine.EndTime) - DateTime.Parse(newLine.StartTime)).TotalMinutes; taskStatistics.Add(newLine); return(newLine); }
public TaskStatistics AddNewLine(TaskStatistics newLine, string startTime, string endTime) { newLine.StartTime = startTime; newLine.EndTime = endTime; newLine.WorkTime = (DateTime.Parse(newLine.EndTime) - DateTime.Parse(newLine.StartTime)).TotalMinutes; context.TaskStatistics.Add(newLine); context.SaveChanges(); return(newLine); }
public ExecutionContext( IExecutionTaskContext taskContext, ObjectPool <ResolverTask> resolverTaskPool) { _taskContext = taskContext; _taskStatistics = new TaskStatistics(); _taskBacklog = new TaskBacklog(_taskStatistics, resolverTaskPool); TaskPool = resolverTaskPool; TaskStats.StateChanged += TaskStatisticsEventHandler; TaskStats.AllTasksCompleted += OnCompleted; }
/// <summary> /// 获取任务完成统计 /// </summary> /// <returns></returns> public ActionResult GetAlTaskStatisticsInfo() { try { DateTime startTime = Convert.ToDateTime(Request["startTime"]); //任务主键ID DateTime endTime = Convert.ToDateTime(Request["endTime"]); //任务主键ID return(Json(TaskStatistics.GetStatisticsInfo(startTime, endTime), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Content(ex.Message)); } }
public TaskStatistics UpdateWorkTime(TaskStatistics workingTask, DateTime endTimeUpdated) { var updateWT = taskStatistics.SingleOrDefault(s => s.Id == workingTask.Id); if (updateWT != null) { updateWT.StartTime = workingTask.StartTime; updateWT.EndTime = endTimeUpdated.ToString(); updateWT.WorkTime = (DateTime.Parse(updateWT.EndTime) - DateTime.Parse(updateWT.StartTime)).TotalMinutes; updateWT.TaskId = workingTask.TaskId; } return(updateWT); }
public IActionResult OnGet(int taskId) { MyTask = taskData.GetById(taskId); if (MyTask == null) { return(RedirectToPage("./NotFound")); } TaskStat = taskData.AddNewLine(TaskStat, DateTime.Now.ToString(), DateTime.Now.ToString()); //TaskStat.StartTime = DateTime.Now.ToString(); return(Page()); }
public TaskStatistics GetTaskStatistics() { var stat = new TaskStatistics(); stat.TaskCountByStatusList = _db.Tasks.GroupBy(x => x.Status).Select(x => new TaskCountByStatus { Status = x.Key, TaskCount = x.Count() }).ToList(); var doneTaskCount = stat.TaskCountByStatusList.FirstOrDefault(x => x.Status == Constants.TaskStatusEnum.Done)?.TaskCount; var erroredTaskCount = stat.TaskCountByStatusList.FirstOrDefault(x => x.Status == Constants.TaskStatusEnum.Error)?.TaskCount; if (doneTaskCount.HasValue && erroredTaskCount.HasValue) { var totalExecutionTime = _db.Tasks.Where(x => x.ModificationTime != null).AsEnumerable().Sum(x => (x.ModificationTime.Value - x.CreationTime).TotalMilliseconds); stat.AvgTaskExecutionTimeInMilisecond = totalExecutionTime / doneTaskCount.Value; stat.PercentOfErrors = erroredTaskCount.Value / (double)doneTaskCount.Value * 100; } return(stat); }
/// <summary> /// Determines the best tasks for the game state based on the provided statistics and creates a <see cref="SabberStoneAction"/> from them. /// </summary> /// <param name="state">The game state to create the best action for.</param> /// <returns><see cref="SabberStoneAction"/> created from the best individual tasks available in the provided state.</returns> public SabberStoneAction DetermineBestTasks(SabberStoneState state) { // Clone game so that we can process the selected tasks and get an updated options list. var clonedGame = state.Game.Clone(); // We have to determine which tasks are the best to execute in this state, based on the provided values of the MCTS search. // So we'll check the statistics table for the highest value among tasks that are currently available in the state. // This continues until the end-turn task is selected. var action = new SabberStoneAction(); while (!action.IsComplete() && clonedGame.State != State.COMPLETE) { // Get the available options in this state and find which tasks we have statistics on, but ignore the END-TURN task for now var availableTasks = clonedGame.CurrentPlayer.Options().Where(i => i.PlayerTaskType != PlayerTaskType.END_TURN).Select(i => ((SabberStonePlayerTask)i).GetHashCode()); var stats = TaskStatistics.Where(i => availableTasks.Contains(i.Key)).ToList(); var bestTask = stats.OrderByDescending(i => i.Value.AverageValue()).FirstOrDefault(); // If we can't find any task, stop. if (bestTask.IsDefault()) { // End the turn action.AddTask((SabberStonePlayerTask)EndTurnTask.Any(clonedGame.CurrentPlayer)); break; } // Handle the possibility of tasks with tied average value. var bestValue = bestTask.Value.AverageValue(); var tiedTasks = stats.Where(i => Math.Abs(i.Value.AverageValue() - bestValue) < Constants.DOUBLE_EQUALITY_TOLERANCE); var orderedTies = tiedTasks.OrderByDescending(i => i.Value.Visits); bestTask = orderedTies.First(); // If we found a task, add it to the Action and process it to progress the game. var task = bestTask.Value.Task; action.AddTask(task); clonedGame.Process(task.Task); } // Return the created action consisting of the best action available at each point. return(action); }
//private async Task<bool> GetPermissionOnPrivateNotification(ResolveFieldContext<object> context) //{ // int notificationId = context.GetArgument<int>("notificationId"); // try // { // ApplicationUser user = await _userManager.GetUserAsync((ClaimsPrincipal)context.UserContext); // var notification = await _unitOfWork.PrivateNotification.FindById(notificationId); // return notification.AuthorId.Equals(user.Id); // } // catch (Exception ex) // { // Debug.WriteLine(ex.Message); // return false; // } //} #endregion #region Statistics block private async Task <TaskStatistics> GetTasksStatistics(ResolveFieldContext <object> context) { int companyId = context.GetArgument <int>("companyId"); var statistics = new TaskStatistics(); try { ApplicationUser user = await _userManager.GetUserAsync((ClaimsPrincipal)context.UserContext); statistics.CountTasksAsAuthor = await _unitOfWork.Task.GetAllTasksAsAuthorCount(companyId, user.Id); statistics.CountTasksAsCoExecutor = await _unitOfWork.Task.GetAllTasksAsCoExecutorCount(companyId, user.Id); statistics.CountTasksAsObserver = await _unitOfWork.Task.GetAllTasksAsObserverCount(companyId, user.Id); statistics.CountTasksAsResponsible = await _unitOfWork.Task.GetAllTasksAsResponsibleCount(companyId, user.Id); statistics.CountCompletedTasks = (await _unitOfWork.Task.GetAllCompletedTasks(companyId, user.Id)).Count; statistics.CountOverdueTasks = (await _unitOfWork.Task.GetAllOverdueTasks(companyId, user.Id)).Count; statistics.CountIssuedTasksPerMonth = await _unitOfWork.Task.GetCountIssuedTasksPerMonth(companyId); statistics.CountTasksCompletedPerMonth = await _unitOfWork.Task.GetCountTasksCompletedPerMonth(companyId); statistics.CountAllTasksCompletedPerMonth = await _unitOfWork.Task.GetCountAllTasksCompletedPerMonth(companyId); statistics.CountTasksOutstandingPerMonth = await _unitOfWork.Task.GetCountTasksOutstandingPerMonth(companyId); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(statistics); }
/// <summary> /// Runs a single search. /// Note: this method is called by the <see cref="EnsembleStrategySabberStone"/>. /// </summary> /// <param name="context">The context of the search.</param> /// <returns>SabberStoneAction that is the solution to the search.</returns> public SabberStoneAction Search(SearchContext <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction> context) { var timer = System.Diagnostics.Stopwatch.StartNew(); if (_debug) { Console.WriteLine(); } // Execute the search context.Execute(); // Check if the search was successful if (context.Status != SearchContext <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction> .SearchStatus.Success) { throw new SearchException($"Search did not conclude correctly. Current Status {context.Status}"); } var solution = context.Solution; // Check if the search has a MASTPlayoutBot as PlayoutStrategy so that those task-values can be used var playoutStrategyProperty = context.Search.GetType().GetProperty("PlayoutStrategy"); if (playoutStrategyProperty != null) { var playoutStrategy = playoutStrategyProperty.GetMethod.Invoke(context.Search, null); if (playoutStrategy is PlayoutStrategySabberStone playout) { if (playout.Bots.ContainsKey(context.Source.CurrentPlayer())) { var contextBot = playout.Bots[context.Source.CurrentPlayer()]; if (contextBot is MASTPlayoutBot playoutBot) { // Use the MAST statistics as a baseline TaskStatistics = new Dictionary <int, PlayerTaskStatistics>(playoutBot.MASTTable); } } } } // Check if the search has a SolutionStrategy so that task-values can be saved if (context.Search is TreeSearch <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction> search) { // Retrieve the task values from the solution strategy and process them into our property var solutionStrategy = (SolutionStrategySabberStone)search.SolutionStrategy; foreach (var tuple in solutionStrategy.TaskValues) { var taskHash = tuple.Item1.GetHashCode(); if (!TaskStatistics.ContainsKey(taskHash)) { TaskStatistics.Add(taskHash, new PlayerTaskStatistics(tuple.Item1, tuple.Item2)); } else { TaskStatistics[taskHash].AddValue(tuple.Item2); } } // Record the search's maximum depth CurrentMaxDepth = search.MaxDepth; // Make sure to clear the values for the next search solutionStrategy.ClearTaskValues(); } if (_debug) { Console.WriteLine($"Searcher returned with solution: {solution}"); } if (_debug) { Console.WriteLine($"Calculation time was: {timer.ElapsedMilliseconds} ms."); } if (_debug) { Console.WriteLine(); } return(solution); }