• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/scrum/utility/storypoints.php
  • Класс: BitrixTasksScrumUtilityStoryPoints
  • Вызов: StoryPoints::calculateAverageNumberCompletedStoryPoints
public function calculateAverageNumberCompletedStoryPoints(int $groupId): float
{
	$cacheService = new CacheService($groupId, CacheService::STATS);

	if ($cacheService->init())
	{
		$stats = $cacheService->getData();

		if (isset($stats['averageNumberCompletedStoryPoints']))
		{
			return $stats['averageNumberCompletedStoryPoints'];
		}
	}

	$averageNumberStoryPoints = 0;

	$nav = new PageNavigation('completed-sprints');
	$nav->setCurrentPage(1);
	$nav->setPageSize(5);

	$sprintService = new SprintService();
	$kanbanService = new KanbanService();
	$itemService = new ItemService();

	$listSumStoryPoints = [];

	$sprints = $sprintService->getCompletedSprints($groupId, $nav);
	foreach ($sprints as $sprint)
	{
		$completedTaskIds = $kanbanService->getFinishedTaskIdsInSprint($sprint->getId());

		$listStoryPoints = $itemService->getItemsStoryPointsBySourceId($completedTaskIds);

		$listSumStoryPoints[$sprint->getId()] = $this->calculateSumStoryPoints($listStoryPoints);
	}

	if ($listSumStoryPoints)
	{
		$averageNumberStoryPoints = round(
			array_sum(array_values($listSumStoryPoints)) / count($listSumStoryPoints),
			1
		);
	}

	$cacheService->start();
	$cacheService->end(['averageNumberCompletedStoryPoints' => $averageNumberStoryPoints]);

	return $averageNumberStoryPoints;
}