Browse Source

阈值计算

master
wanghongjun 3 years ago
parent
commit
27c819a440
  1. 35
      source/application/common/logic/PassFlow.php

35
source/application/common/logic/PassFlow.php

@ -8,6 +8,14 @@ class PassFlow
{ {
protected static $groupType = [1,2];# 1 = 体育 2 = 文化 protected static $groupType = [1,2];# 1 = 体育 2 = 文化
protected static $granularity = ['daily','monthly','yearly'];# 1 = 体育 2 = 文化 protected static $granularity = ['daily','monthly','yearly'];# 1 = 体育 2 = 文化
protected static $groupThreshold = [
'baz001' => 10000,# 图书馆
'BAF055' => 1000,# 文化馆
'110' => 10000,# 体育场
'210' => 10000,# 体育馆
'310' => 1000,# 游泳馆
'510' => 1000 # 博物馆
];
protected static function getGroupIds($dm,$type = 1) protected static function getGroupIds($dm,$type = 1)
{ {
@ -304,7 +312,10 @@ class PassFlow
$returnData['day']['noRepeatInNum'] += isset($mData['today_incount']) ? $mData['today_incount'] : 0; $returnData['day']['noRepeatInNum'] += isset($mData['today_incount']) ? $mData['today_incount'] : 0;
$returnData['month']['noRepeatInNum'] += isset($mData['month_incount']) ? $mData['month_incount'] : 0; $returnData['month']['noRepeatInNum'] += isset($mData['month_incount']) ? $mData['month_incount'] : 0;
$returnData['year']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; $returnData['year']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0;
$returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; // $returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0;
# 文化总年度
$libraryData = $dm->find('bt_library_data',['group_id' => 'lib001','date' => 'year'],'SUM("incount") as NUM');
$returnData['sumYear']['noRepeatInNum'] += isset($libraryData['NUM']) ? $libraryData['NUM'] : 0;
$week_start = date("Y-m-d 00:00:00",strtotime('this week')); $week_start = date("Y-m-d 00:00:00",strtotime('this week'));
$week_end = date("Y-m-d 23:59:59",strtotime("-".(date("w") - 7) . "day")); $week_end = date("Y-m-d 23:59:59",strtotime("-".(date("w") - 7) . "day"));
$weekDateWhere = ' "group_id" =' . "'lib001'" . ' and "create_time" >= ' . "'{$week_start}'" . ' and "create_time" <= ' . "'{$week_end}'"; $weekDateWhere = ' "group_id" =' . "'lib001'" . ' and "create_time" >= ' . "'{$week_start}'" . ' and "create_time" <= ' . "'{$week_end}'";
@ -332,17 +343,18 @@ class PassFlow
$list = $dm->select('bt_passenger_flow_real'); $list = $dm->select('bt_passenger_flow_real');
$data = []; $data = [];
$configRes = $dm->find("bt_config",' "key" = ' . "'threshold'"); // $configRes = $dm->find("bt_config",' "key" = ' . "'threshold'");
$threshold = $configRes['value'] ?: 0; // $threshold = $configRes['value'] ?: 0;
foreach ($list as $value) { foreach ($list as $value) {
if (!isset($data[$value['groupId']]['allEnter'])) $data[$value['groupId']]['allEnter'] = 0; if (!isset($data[$value['groupId']]['allEnter'])) $data[$value['groupId']]['allEnter'] = 0;
$data[$value['groupId']]['allEnter'] += $value['allEnter']; $data[$value['groupId']]['allEnter'] += $value['allEnter'];
} }
$groupThreshold = self::$groupThreshold;
$returnData = []; $returnData = [];
foreach ($data as $groupId => $val) { foreach ($data as $groupId => $val) {
$proportion = $val['allEnter'] > 0 ? round($val['allEnter']/$threshold,4) : 0; $proportion = $val['holdValue'] > 0 ? round($val['holdValue']/$groupThreshold[$val['groupId']],4) : 0;
$val['proportion'] = ($proportion * 100) . "%"; $val['proportion'] = ($proportion * 100) . "%";
$val['congestion'] = self::getPassType($proportion); $val['congestion'] = self::getPassType($proportion);
$val['groupId'] = $groupId; $val['groupId'] = $groupId;
@ -354,7 +366,8 @@ class PassFlow
} }
$libData = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); $libData = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]);
foreach ($libData as $libRow) { foreach ($libData as $libRow) {
$libProportion = $libRow['today_incount'] > 0 ? round($libRow['today_incount']/$threshold,4) : 0; $holdValue = $libRow['today_incount'] - $libRow['today_outcount'];
$libProportion = $holdValue > 0 ? round($holdValue/$groupThreshold[$libRow['group_id']],4) : 0;
// 文化馆排 4# 图书馆 2# // 文化馆排 4# 图书馆 2#
$isort = $libRow['group_id']=='baz001'?2:4; $isort = $libRow['group_id']=='baz001'?2:4;
$returnData[] = [ $returnData[] = [
@ -379,19 +392,19 @@ class PassFlow
protected static function getPassType($proportion) protected static function getPassType($proportion)
{ {
# 舒适:阈值<80% # 舒适:阈值<80%
if ($proportion < 0.8) { if ($proportion <= 0.5) {
return '舒适'; return '舒适';
} }
# 饱和:80%<阈值<100% # 饱和:80%<阈值<100%
if (0.8 < $proportion || $proportion < 1) { // if (0.8 < $proportion || $proportion < 1) {
return '饱和'; // return '饱和';
} // }
# 拥挤:阈值=100% # 拥挤:阈值=100%
if ($proportion == 1) { if ($proportion > 0.5 && $proportion <= 1) {
return '拥挤'; return '拥挤';
} }
# 拥挤:阈值=100% # 拥挤:阈值=100%
if ($proportion >= 1.2) { if ($proportion > 1) {
return '爆满'; return '爆满';
} }
return ''; return '';

Loading…
Cancel
Save