Merge branch 'develop' of https://github.com/CHU-TDAP/E-learning-Server-v2 into develop
Conflicts: htdocs/api/v2/index.php
This commit is contained in:
commit
a7b8ab964b
@ -89,7 +89,7 @@ class DBRecommand extends Database
|
|||||||
/**
|
/**
|
||||||
* 以目前的學習點編號查詢下一個學習點的資訊
|
* 以目前的學習點編號查詢下一個學習點的資訊
|
||||||
* @param string $currentPoint 目前的學習點編號
|
* @param string $currentPoint 目前的學習點編號
|
||||||
* @return array 查詢結果
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function queryEdgeByID($currentPoint)
|
public function queryEdgeByID($currentPoint)
|
||||||
{
|
{
|
||||||
|
@ -266,7 +266,7 @@ class DBStudy extends Database {
|
|||||||
* @param string $study_id 此記錄編號
|
* @param string $study_id 此記錄編號
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function toOutTaeget($study_id)
|
public function toOutTarget($study_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
// 寫入
|
// 寫入
|
||||||
@ -285,7 +285,7 @@ class DBStudy extends Database {
|
|||||||
* @param string $activity_id 活動編號
|
* @param string $activity_id 活動編號
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function allToOutTaeget($activity_id)
|
public function alltoOutTarget($activity_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
// 寫入
|
// 寫入
|
||||||
|
@ -51,17 +51,17 @@ class DBTarget extends Database {
|
|||||||
foreach($queryResultAll as $key => $thisResult) {
|
foreach($queryResultAll as $key => $thisResult) {
|
||||||
|
|
||||||
array_push($result,
|
array_push($result,
|
||||||
array( 'target_id' => $thisResult['TID'],
|
array( 'target_id' => (int)$thisResult['TID'],
|
||||||
'area_id' => $thisResult['AID'],
|
'area_id' => (int)$thisResult['AID'],
|
||||||
'hall_id' => $thisResult['HID'],
|
'hall_id' => (int)$thisResult['HID'],
|
||||||
'target_number' => $thisResult['TNum'],
|
'target_number' => (int)$thisResult['TNum'],
|
||||||
'name' => $thisResult['TName'],
|
'name' => $thisResult['TName'],
|
||||||
'map_url' => $thisResult['TMapID'],
|
'map_url' => $thisResult['TMapID'],
|
||||||
'learn_time' => $thisResult['TLearnTime'],
|
'learn_time' => (int)$thisResult['TLearnTime'],
|
||||||
'PLj' => $thisResult['PLj'],
|
'PLj' => (int)$thisResult['PLj'],
|
||||||
'Mj' => $thisResult['Mj'],
|
'Mj' => (int)$thisResult['Mj'],
|
||||||
'S' => $thisResult['S'],
|
'S' => (int)$thisResult['S'],
|
||||||
'Fj' => $thisResult['Fj']
|
'Fj' => (int)$thisResult['Fj']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* RecommandPoint.php
|
||||||
|
*/
|
||||||
|
|
||||||
namespace UElearning\Recommand;
|
namespace UElearning\Recommand;
|
||||||
|
|
||||||
@ -14,13 +17,17 @@ use UElearning\Database;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 推薦學習點
|
* 推薦學習點
|
||||||
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* $recommand = new RecommandPoint();
|
* $recommand = new RecommandPoint();
|
||||||
|
*
|
||||||
|
* @version 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Study
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RecommandPoint
|
class RecommandPoint
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 正規化參數
|
* 正規化參數
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
@ -37,6 +44,8 @@ class RecommandPoint
|
|||||||
const ALPHA=0.5;
|
const ALPHA=0.5;
|
||||||
|
|
||||||
private $recommand;
|
private $recommand;
|
||||||
|
private $theme;
|
||||||
|
private $activity;
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@ -52,18 +61,17 @@ class RecommandPoint
|
|||||||
private function computeNormalizationParameter($theme_number)
|
private function computeNormalizationParameter($theme_number)
|
||||||
{
|
{
|
||||||
$normal = 0; //正規化之後的GAMMA值
|
$normal = 0; //正規化之後的GAMMA值
|
||||||
$EntitySum = 0; //實體學習點分別算銓重之後的值
|
$EntitySum = 0; //實體學習點分別算權重之後的值
|
||||||
$VirtualSum = 0; //虛擬學習點分別算銓重之後的值
|
$VirtualSum = 0; //虛擬學習點分別算權重之後的值
|
||||||
|
|
||||||
$edge = $this->recommand->queryEdgeByID('0');
|
$edge = $this->recommand->queryEdgeByID('0');
|
||||||
$theme = new Study\Theme($theme_number);
|
|
||||||
|
|
||||||
for($i=0;$i<count($edge);$i++)
|
for($i=0;$i<count($edge);$i++)
|
||||||
{
|
{
|
||||||
$next_point = $edge[$i]["next_point"];
|
$next_point = $edge[$i]["next_point"];
|
||||||
$move_time = $edge[$i]["move_time"];
|
$move_time = $edge[$i]["move_time"];
|
||||||
$next_target = new Target\Target($next_point);
|
$next_target = new Target\Target($next_point);
|
||||||
$belong = $this->recommand->queryBelongByID($next_point,$theme->getId());
|
$belong = $this->recommand->queryBelongByID($next_point,$theme_number);
|
||||||
$weight = $belong["weight"];
|
$weight = $belong["weight"];
|
||||||
|
|
||||||
$VirtualSum += $weight / $next_target->getLearnTime();
|
$VirtualSum += $weight / $next_target->getLearnTime();
|
||||||
@ -76,12 +84,91 @@ class RecommandPoint
|
|||||||
return $EntitySum/$VirtualSum;
|
return $EntitySum/$VirtualSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否為可以學習的標的
|
||||||
|
* @param $target_id 標的編號
|
||||||
|
* @return bool enable or not
|
||||||
|
*/
|
||||||
|
private function isEnableTargetId($activityObj,$target_id)
|
||||||
|
{
|
||||||
|
$target = new Target\Target($target_id);
|
||||||
|
if(!$activityObj->isTargetLearned($target_id)) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 過濾非法的標的
|
||||||
|
*
|
||||||
|
* @param array $point_list 全部的標的清單
|
||||||
|
* @param StudyActivity $activityObj 學習活動物件
|
||||||
|
* @return array 合法的學習點
|
||||||
|
*/
|
||||||
|
private function excludeIrregularTarget($point_list,$activityObj)
|
||||||
|
{
|
||||||
|
$regularTarget = array();
|
||||||
|
for($i=0;$i<count($point_list);$i++)
|
||||||
|
{
|
||||||
|
$nextPoint = $point_list[$i]['next_point'];
|
||||||
|
if($this->isEnableTargetId($activityObj,$nextPoint)) {
|
||||||
|
array_push($regularTarget,$point_list[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $regularTarget;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推薦學習點
|
* 推薦學習點
|
||||||
|
* @param int $current_point 目前的標的編號
|
||||||
|
* @param int $theme_number 主題編號
|
||||||
|
* @param int activity_number 學習活動編號
|
||||||
* @return array 學習點清單
|
* @return array 學習點清單
|
||||||
*/
|
*/
|
||||||
public function recommand($current_point,$theme_number,$activity_number)
|
public function recommand($current_point,$activity_number)
|
||||||
{
|
{
|
||||||
|
$this->activity = new Study\StudyActivity($activity_number);
|
||||||
|
$themeID = $this->activity->getThemeId();
|
||||||
|
$this->theme = new Study\Theme($themeID);
|
||||||
|
$this->gamma = $this->computeNormalizationParameter($themeID);
|
||||||
|
$pointList = $this->recommand->queryEdgeByID($current_point);
|
||||||
|
$targetList = $this->excludeIrregularTarget($pointList,$this->activity);
|
||||||
|
|
||||||
|
//計算路徑的權重值
|
||||||
|
$pathCost = 0;
|
||||||
|
$VirtualPathCost = 0;
|
||||||
|
$recommand = array();
|
||||||
|
$isEntity = true;
|
||||||
|
for($i=0;$i<count($targetList);$i++)
|
||||||
|
{
|
||||||
|
$next_point = $targetList[$i]["next_point"];
|
||||||
|
$moveTime = $targetList[$i]["move_time"];
|
||||||
|
$nextPoint = new Target\Target($next_point);
|
||||||
|
$weight = $this->theme->getWeightByNextTarget($next_point);
|
||||||
|
if($nextPoint->isFullPeople())
|
||||||
|
{
|
||||||
|
$pastCost = 0;
|
||||||
|
$virtualCost = RecommandPoint::ALPHA * $this->gamma * ($wright/$nextPoint->getLearnTime());
|
||||||
|
$isEntity=false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if($nextPoint->isNumberOfPeopleZero()) $Rj = 0;
|
||||||
|
else $Rj = $nextPoint->getMj()/$nextPoint->getPLj();
|
||||||
|
$pathCost = RecommandPoint::ALPHA * $this->gamma * ($weight * ($nextPoint->getS()-$Rj+1)/($moveTime + $nextPoint->getLearnTime()));
|
||||||
|
$virtualCost = RecommandPoint::ALPHA * $this->gamma * ($weight/$nextPoint->getLearnTime());
|
||||||
|
}
|
||||||
|
array_push($recommand,array("nextPoint"=>$next_point,
|
||||||
|
"isEntity" => $isEntity,
|
||||||
|
"PathCost"=>$pathCost,
|
||||||
|
"VirtualCost"=>$virtualCost));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($recommand as $key=>$value)
|
||||||
|
{
|
||||||
|
$tmp[$key] = $value["PathCost"];
|
||||||
|
}
|
||||||
|
array_multisort($tmp,SORT_DESC,$recommand,SORT_DESC);
|
||||||
|
|
||||||
|
return $recommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ namespace UElearning\Study;
|
|||||||
|
|
||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
||||||
use UElearning\Database;
|
use UElearning\Database;
|
||||||
|
use UElearning\Target;
|
||||||
use UElearning\Exception;
|
use UElearning\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,7 +175,15 @@ class Study {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function toOut() {
|
public function toOut() {
|
||||||
|
|
||||||
|
// 將資料庫內容標示已離開
|
||||||
$db = new Database\DBStudy();
|
$db = new Database\DBStudy();
|
||||||
$db->toOutTaeget($this->id);
|
$db->toOutTarget($this->id);
|
||||||
|
|
||||||
|
// 將標的目前人數-1
|
||||||
|
if($this->isEntity()) {
|
||||||
|
$target = new Target\Target($this->getTargetId);
|
||||||
|
$target->addMj(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,6 +438,20 @@ class StudyActivity {
|
|||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前已進入的學習點
|
||||||
|
*
|
||||||
|
* @return int 標的編號,若無則null
|
||||||
|
*/
|
||||||
|
public function getCurrentInTarget() {
|
||||||
|
|
||||||
|
// 活動編號
|
||||||
|
$saId = $this->id;
|
||||||
|
|
||||||
|
$sct = new StudyManager();
|
||||||
|
return $sct->getCurrentInTargetId($saId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此標的是否已學習過
|
* 此標的是否已學習過
|
||||||
*
|
*
|
||||||
|
@ -7,7 +7,10 @@ namespace UElearning\Study;
|
|||||||
|
|
||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Target/Exception.php';
|
||||||
use UElearning\Database;
|
use UElearning\Database;
|
||||||
|
use UElearning\Target;
|
||||||
use UElearning\Exception;
|
use UElearning\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,14 +71,24 @@ class StudyManager {
|
|||||||
* @param int $activity_id 活動編號
|
* @param int $activity_id 活動編號
|
||||||
* @param int $target_id 標的編號
|
* @param int $target_id 標的編號
|
||||||
* @param bool $is_entity 是否為現場學習
|
* @param bool $is_entity 是否為現場學習
|
||||||
|
* @throw UElearning\Exception\TargetNoFoundException
|
||||||
* return int 進出紀錄編號
|
* return int 進出紀錄編號
|
||||||
*/
|
*/
|
||||||
public function toInTarget($activity_id, $target_id, $is_entity) {
|
public function toInTarget($activity_id, $target_id, $is_entity) {
|
||||||
|
|
||||||
// 若沒有任一個點正在學習中
|
// 若沒有任一個點正在學習中
|
||||||
if($this->getCurrentInTargetId($activity_id) == null) {
|
if($this->getCurrentInTargetId($activity_id) == null) {
|
||||||
|
// 紀錄進資料庫
|
||||||
$db = new Database\DBStudy();
|
$db = new Database\DBStudy();
|
||||||
return $db->toInTaeget($activity_id, $target_id, $is_entity);
|
$id = $db->toInTaeget($activity_id, $target_id, $is_entity);
|
||||||
|
|
||||||
|
// 將標的目前人數+1
|
||||||
|
if($is_entity) {
|
||||||
|
$target = new Target\Target($target_id);
|
||||||
|
$target->addMj(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Exception\InLearningException();
|
throw new Exception\InLearningException();
|
||||||
@ -93,12 +106,22 @@ class StudyManager {
|
|||||||
// 從資料庫取得此活動此標的學習中資料
|
// 從資料庫取得此活動此標的學習中資料
|
||||||
$db = new Database\DBStudy();
|
$db = new Database\DBStudy();
|
||||||
$learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id);
|
$learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id);
|
||||||
|
$target = new Target\Target($target_id);
|
||||||
|
|
||||||
|
// 找到正在學習中的資料
|
||||||
if(isset($learning_array)) {
|
if(isset($learning_array)) {
|
||||||
|
|
||||||
|
// 將所有此標的的進入紀錄全部標示
|
||||||
foreach($learning_array as $thisArray) {
|
foreach($learning_array as $thisArray) {
|
||||||
|
|
||||||
$db->toOutTaeget($thisArray['study_id']);
|
// 將此紀錄標示為已離開
|
||||||
|
$db->toOutTarget($thisArray['study_id']);
|
||||||
|
|
||||||
|
// 將標的目前人數-1
|
||||||
|
if($thisArray['is_entity'] = true) {
|
||||||
|
$target = new Target\Target($target_id);
|
||||||
|
$target->addMj(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
namespace UElearning\Study;
|
namespace UElearning\Study;
|
||||||
|
|
||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Database/DBRecommand.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
use UElearning\Database;
|
use UElearning\Database;
|
||||||
use UElearning\Exception;
|
use UElearning\Exception;
|
||||||
@ -176,4 +177,16 @@ class Theme {
|
|||||||
return $this->queryResultArray['modify_time'];
|
return $this->queryResultArray['modify_time'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得下一個標的所屬主題的權重
|
||||||
|
* @param string $next_point
|
||||||
|
* @return int weight 權重
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getWeightByNextTarget($next_point){
|
||||||
|
$belong = new Database\DBRecommand();
|
||||||
|
$weight = $belong->queryBelongByID($next_point,$this->id);
|
||||||
|
return $weight['weight'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ class Target {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct($inputTID){
|
public function __construct($inputTID){
|
||||||
$this->tId = $inputTID;
|
$this->tId = (int)$inputTID;
|
||||||
$this->getQuery();
|
$this->getQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user