完成DBRecommand和修正Theme、Target並在RecommandPoint新增計算正規化參數的方法
This commit is contained in:
parent
a38d3a717e
commit
c414cdcae0
@ -21,9 +21,10 @@ class DBRecommand extends Database
|
|||||||
* @param string $where SQL WHERE子句
|
* @param string $where SQL WHERE子句
|
||||||
* @return array 查詢結果
|
* @return array 查詢結果
|
||||||
*/
|
*/
|
||||||
protected function queryEdgeByWhere($where)
|
|
||||||
{
|
protected function queryEdgeByWhere($where)
|
||||||
$sqlString = "SELECT DISTINCT ".$this->table('Edge').".Ti, ".$this->table('Edge').".Tj, ".$this->table('Edge').".MoveTime".
|
{
|
||||||
|
$sqlString = "SELECT DISTINCT ".$this->table('Edge').".Ti, ".$this->table('Edge').".Tj, ".$this->table('Edge').".MoveTime".
|
||||||
" FROM ".$this->table('Edge')." WHERE ".$where;
|
" FROM ".$this->table('Edge')." WHERE ".$where;
|
||||||
$query = $this->connDB->prepare($sqlString);
|
$query = $this->connDB->prepare($sqlString);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
@ -44,11 +45,16 @@ class DBRecommand extends Database
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 內部查詢用
|
||||||
|
* @param string $where SQL WHERE子句
|
||||||
|
* @return array 查詢結果
|
||||||
|
*/
|
||||||
protected function queryBelongByWhere($where)
|
protected function queryBelongByWhere($where)
|
||||||
{
|
{
|
||||||
$sqlString = "SELECT ".$this->table('tbelong').".Weights FROM ".$this->table('tbelong')." WHERE ".$where;
|
$sqlString = "SELECT ".$this->table('TBelong').".Weights FROM ".$this->table('TBelong')." WHERE ".$where;
|
||||||
$query = $this->connDB->prepare($sqlString);
|
$query = $this->connDB->prepare($sqlString);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
@ -66,19 +72,29 @@ class DBRecommand extends Database
|
|||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下一個學習點和主題編號查詢屬於的權重資料
|
||||||
|
* @param string $next_point 下一個學習點編號
|
||||||
|
* @return array 查詢結果
|
||||||
|
*/
|
||||||
public function queryBelongByID($next_point,$theme_number)
|
public function queryBelongByID($next_point,$theme_number)
|
||||||
{
|
{
|
||||||
$whereClause = $this->table('tbelong').".thID = ".$this->connDB->quote($theme_number)." AND ".$this->table('tbelong').".TID = ".$this->connDB->quote($next_point);
|
$whereClause = $this->table('TBelong').".ThID = ".$this->connDB->quote($theme_number)." AND ".$this->table('TBelong').".TID = ".$this->connDB->quote($next_point);
|
||||||
$AllOfResult = $this->queryBelongByWhere($whereClause);
|
$AllOfResult = $this->queryBelongByWhere($whereClause);
|
||||||
|
|
||||||
if(count($AllOfResult) != 0) return $AllOfResult;
|
if(count($AllOfResult) != 0) return $AllOfResult;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以目前的學習點編號查詢下一個學習點的資訊
|
||||||
|
* @param string $currentPoint 目前的學習點編號
|
||||||
|
* @return array 查詢結果
|
||||||
|
*/
|
||||||
public function queryEdgeByID($currentPoint)
|
public function queryEdgeByID($currentPoint)
|
||||||
{
|
{
|
||||||
$AllOfResult = $this->queryBelongByWhere("Ti = ".$this->connDB->quote($currentPoint));
|
//echo "EEEEEEEEE";
|
||||||
|
$AllOfResult = $this->queryEdgeByWhere($this->table('Edge').".Ti = ".$this->connDB->quote($currentPoint));
|
||||||
if(count($AllOfResult) != 0) return $AllOfResult;
|
if(count($AllOfResult) != 0) return $AllOfResult;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,85 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__.'/../config.php';
|
namespace UElearning\Recommand;
|
||||||
|
|
||||||
|
require_once UELEARNING_ROOT.'/config.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Database/DBRecommand.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Study/Theme.php';
|
||||||
use UElearning\Target;
|
use UElearning\Target;
|
||||||
use UElearning\Exception;
|
use UElearning\Study;
|
||||||
|
use UElearning\Database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推薦學習點
|
* 推薦學習點
|
||||||
* Usage:
|
* Usage:
|
||||||
* $recommand = new RecommandPoint();
|
* $recommand = new RecommandPoint();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RecommandPoint
|
class RecommandPoint
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 正規化參數
|
* 正規化參數
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @type double
|
* @type double
|
||||||
*/
|
*/
|
||||||
private $gamma;
|
private $gamma;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 調和參數(常數)
|
* 調和參數(常數)
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @type double
|
* @type double
|
||||||
*/
|
*/
|
||||||
private const $ALPHA = 0.5;
|
const ALPHA=0.5;
|
||||||
|
|
||||||
private
|
private $recommand;
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$gamma = 0;
|
||||||
}
|
$this->recommand = new Database\DBRecommand();
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 計算正規化參數
|
/**
|
||||||
* @return double 正規化參數
|
* 計算正規化參數
|
||||||
*/
|
* @return double 正規化參數
|
||||||
private function computeNormalizationParameter()
|
*/
|
||||||
{
|
private function computeNormalizationParameter($theme_number)
|
||||||
$
|
{
|
||||||
}
|
$normal = 0; //正規化之後的GAMMA值
|
||||||
|
$EntitySum = 0; //實體學習點分別算銓重之後的值
|
||||||
/**
|
$VirtualSum = 0; //虛擬學習點分別算銓重之後的值
|
||||||
* 推薦學習點
|
|
||||||
* @return array 學習點清單
|
$edge = $this->recommand->queryEdgeByID('0');
|
||||||
*/
|
$theme = new Study\Theme($theme_number);
|
||||||
public function recommand($ )
|
|
||||||
{
|
for($i=0;$i<count($edge);$i++)
|
||||||
|
{
|
||||||
}
|
$next_point = $edge[$i]["next_point"];
|
||||||
}
|
$move_time = $edge[$i]["move_time"];
|
||||||
|
$next_target = new Target\Target($next_point);
|
||||||
|
$belong = $this->recommand->queryBelongByID($next_point,$theme->getId());
|
||||||
|
$weight = $belong[0]["weight"];
|
||||||
|
|
||||||
|
$VirtualSum += $weight / $next_target->getLearnTime();
|
||||||
|
|
||||||
|
if($next_target->isNumberOfPeopleZero()) $Rj = 0;
|
||||||
|
else $Rj = $next_target->getMj() / $next_target->getPLj();
|
||||||
|
|
||||||
|
$EntitySum += $weight * ($next_target->getS() - $Rj + 1) / ($move_time + $next_target->getLearnTime());
|
||||||
|
}
|
||||||
|
return $EntitySum/$VirtualSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推薦學習點
|
||||||
|
* @return array 學習點清單
|
||||||
|
*/
|
||||||
|
public function recommand($current_point,$theme_number,$activity_number)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -96,7 +96,7 @@ class Theme {
|
|||||||
/**
|
/**
|
||||||
* 建構子
|
* 建構子
|
||||||
*
|
*
|
||||||
* @param int $inputTID 主題ID
|
* @param int $inputID 主題ID
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct($inputID){
|
public function __construct($inputID){
|
||||||
|
@ -293,6 +293,17 @@ class Target {
|
|||||||
return $this->getMj();
|
return $this->getMj();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判斷目前標的人數是否為零
|
||||||
|
*
|
||||||
|
* @return bool true/此標的目前人數是空的,false/此標的目前人數不是空的
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function isNumberOfPeopleZero(){
|
||||||
|
if($this->getCurrentPeople() == 0) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加學習標的目前人數
|
* 增加學習標的目前人數
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user