• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/ml/model/dealscoring.php
  • Класс: Bitrix\Crm\Ml\Model\DealScoring
  • Вызов: DealScoring::getTrainingSetSize
public function getTrainingSetSize()
{
	static $cache = [];

	if (isset($cache[$this->name]))
	{
		return $cache[$this->name];
	}

	$categoryId = static::getModelCategory($this->name);
	$cursor = DealTable::getList([
		"select" => [
			"STAGE_SEMANTIC_ID",
			"CNT" => Query::expr()->count("ID")
		],
		"filter" => [
			"=STAGE_SEMANTIC_ID" => ["S", "F"],
			"=CATEGORY_ID" => $categoryId,
			"HAS_ACT" => 1
		],
		"group" => ["STAGE_SEMANTIC_ID"],
		"runtime" => [
			new ExpressionField(
				"HAS_ACT",
				"CASE WHEN EXISTS(SELECT 'x' FROM b_crm_act_bind WHERE OWNER_TYPE_ID = " . CCrmOwnerType::Deal . " and OWNER_ID = %s) THEN 1 ELSE 0 END",
				["ID"]
			),
		],
	]);

	$rows = [];
	while ($row = $cursor->fetch())
	{
		$rows[$row["STAGE_SEMANTIC_ID"]] = (int)$row["CNT"];
	}

	$cache[$this->name] = [$rows["S"] ?? 0, $rows["F"] ?? 0];

	return $cache[$this->name];
}