Browse Source

优化各场管实施实时进馆人数增加拥挤度

master
wanghongjun 3 years ago
parent
commit
e0d3be6bc4
  1. 10
      source/application/api/controller/pass/Passcc.php
  2. 26
      source/application/common/model/Pass.php

10
source/application/api/controller/pass/Passcc.php

@ -5,6 +5,7 @@ namespace app\api\controller\pass;
use app\api\controller\Controller;
use app\common\dm\Dm;
use app\common\model\Pass;
use think\Db;
class Passcc extends Controller
@ -184,16 +185,19 @@ class Passcc extends Controller
$list = $dm->select('bt_passenger_flow_real');
$data = [];
$sumAllEnter = 0;
$configRes = $dm->find("bt_config",' "key" = ' . "'threshold'");
$threshold = $configRes['threshold'] ?: 0;
foreach ($list as $value) {
if (!isset($data[$value['groupId']]['allEnter'])) $data[$value['groupId']]['allEnter'] = 0;
$data[$value['groupId']]['allEnter'] += $value['allEnter'];
$sumAllEnter += $value['allEnter'];
}
$returnData = [];
foreach ($data as $groupId => $val) {
$val['proportion'] = $val['allEnter'] > 0 ? (round($val['allEnter']/$sumAllEnter,2) * 100) ."%" : '0%';
$proportion = $val['allEnter'] > 0 ? round($val['allEnter']/$threshold,2) : 0;
$val['proportion'] = ($proportion * 100) . "%";
$val['congestion'] = Pass::getPassType($proportion);
$val['groupId'] = $groupId;
$returnData[] = $val;
}

26
source/application/common/model/Pass.php

@ -5,4 +5,30 @@ namespace app\common\model;
class Pass extends BaseModel
{
public static $unit = [1 => '>', 2 => '<', 3 => '=', 4 => '≥', 5 => '<=', 6 => '!='];
/**
* 馆舍客流情况-拥挤程度
* @param $proportion // 比例
* @return string
*/
public static function getPassType($proportion)
{
# 舒适:阈值<80%
if ($proportion < 0.8) {
return '舒适';
}
# 饱和:80%<阈值<100%
if (0.8 < $proportion || $proportion < 1) {
return '饱和';
}
# 拥挤:阈值=100%
if ($proportion == 1) {
return '拥挤';
}
# 拥挤:阈值=100%
if ($proportion >= 1.2) {
return '爆满';
}
return '';
}
}
Loading…
Cancel
Save