Пример #1
0
 /**
  * 格式化指标的输出
  * @param string $fieldKey 指标key键值
  * @param string $fieldValue 指标中被选中的option
  * @param string $aRowData 本行的数据
  * @return string 该指标的最后输出的值
  */
 public function ALYSmetricFormat($fieldKey, $fieldValue, $aRowData = array())
 {
     $sRe = "";
     switch ($fieldKey) {
         case 'nc2pv':
         case 'bounceRate':
         case 'visiteBack':
             //百分比模式
             $sRe = \YcheukfReport\Lib\ALYS\ALYSFormat::percent($fieldValue);
             break;
         case 'avgTimeLength':
             //日期,时间模式
             $sRe = \YcheukfReport\Lib\ALYS\ALYSFormat::second4Time($fieldValue);
             break;
         case 'avgDepth':
             //保留小数点后两位
             $sRe = \YcheukfReport\Lib\ALYS\ALYSFormat::round($fieldValue);
             break;
         case 'pvbyvisitor':
             //保留小数点后两位
             $sRe = $aRowData['pvbyvisitor'] . "[" . $aRowData['visitor'] . ']';
             break;
         default:
             $sRe = $fieldValue;
     }
     return $sRe;
 }
Пример #2
0
 /**
  * 准备多指标的Flash数据
  * #edit by Paul 2012.5.11
  */
 public function bubbleFunction()
 {
     //bubble动态配置读取
     $iXLines = 6;
     //x轴线条数 默认
     $iXLines = empty($this->aChartStyles['xlabelScales']) ? $iXLines : (int) $this->aChartStyles['xlabelScales'];
     unset($this->aChartStyles['xlabelScales']);
     $identityNode = '';
     //需要标识的结点
     $sCount = 0;
     $categories = $datasets = '';
     $toolText_split = '{br}';
     //异常处理
     if (count($this->aMainTable['showField']) != 3) {
         throw new \YcheukfReport\Lib\ALYS\ALYSException('ALYSEXPT_INPUT_METRIC_NUM_WRONG', '有且只能为3个');
     }
     //取得标蓝的ID
     $sBoldID = @$this->aInput['input']['flash']['boldID'];
     if (is_array($sBoldID)) {
         $aBoldIDs = $sBoldID;
     } else {
         $aBoldIDs = array($sBoldID);
     }
     //x y z 对应的key
     $sXkey = $this->aMainTable['showField'][0];
     $sYkey = $this->aMainTable['showField'][1];
     $sZkey = $this->aMainTable['showField'][2];
     $sXkeyLang = \YcheukfReport\Lib\ALYS\ALYSLang::_($sXkey);
     $sYkeyLang = \YcheukfReport\Lib\ALYS\ALYSLang::_($sYkey);
     $sZkeyLang = \YcheukfReport\Lib\ALYS\ALYSLang::_($sZkey);
     //x 的最大值
     $iX = $iY = 0;
     $aX = $aY = $aZ = array();
     if (is_array($this->aDatas)) {
         foreach ($this->aDatas as $key => $v) {
             if (!empty($v[$sXkey])) {
                 if ($v[$sXkey] > $iX) {
                     $iX = $v[$sXkey];
                 }
                 $aX[] = $v[$sXkey];
             }
             if (!empty($v[$sYkey])) {
                 if ($v[$sYkey] > $iY) {
                     $iY = $v[$sYkey];
                 }
                 $aY[] = $v[$sYkey];
             }
             if (!empty($v[$sZkey])) {
                 $aZ[] = $v[$sZkey];
             }
         }
     }
     //确定每条线增量
     $iXPlus = ceil($iX / $iXLines);
     //chart样式设置最大值最小值
     $this->aChartStyles['xAxisMaxValue'] = $iX > 0 ? (int) ($iX + $iXPlus) : 10;
     $this->aChartStyles['yAxisMaxValue'] = $iY > 0 ? (int) ($iY + ceil($iY / 4)) : 10;
     //设置成偶数
     if ($this->aChartStyles['yAxisMaxValue'] % 2 != 0) {
         $this->aChartStyles['yAxisMaxValue']++;
     }
     $_labelSuffix = $this->aChartStyles['xlabelSuffix'] ? $this->aChartStyles['xlabelSuffix'] : '';
     unset($this->aChartStyles['xlabelSuffix']);
     //dataset数据
     $datasets .= "<dataset showValues='0' showLable='0' plotBorderThickness='1' plotBorderColor='ffffff' plotBorderAlpha='50' plotFillAlpha='90' >";
     $oDict = \YcheukfReport\Lib\ALYS\ALYSFunction::loadDictionary('Metric');
     if (!empty($this->aDatas) && is_array($this->aDatas)) {
         $aIDs = array();
         $sDimen = $this->aDimen[0];
         foreach ($this->aDatas as $key => $value) {
             $aIDs[$sDimen][] = $key;
         }
         $oId2Label = \YcheukfReport\Lib\ALYS\ALYSFunction::loadDictionary('Id2label');
         $aLabel = $oId2Label->ALYSchgId2Label($this->dimenkey2selected, $aIDs);
         foreach ($this->aDatas as $key => $value) {
             $sXdisplay = $sXkeyLang . ':' . $oDict->ALYSmetricFormat($sXkey, $value[$sXkey]);
             $sYdisplay = $sYkeyLang . ':' . $oDict->ALYSmetricFormat($sYkey, $value[$sYkey]);
             $sZdisplay = $sZkeyLang . ':' . $oDict->ALYSmetricFormat($sZkey, $value[$sZkey]);
             $datasets .= "<set x='" . $value[$sXkey] . "' y='" . $value[$sYkey] . "' z='" . $value[$sZkey] . "' toolText='" . \YcheukfReport\Lib\ALYS\ALYSFunction::_htmlspecialchars($aLabel[$sDimen][$key]) . "{br}" . $sXdisplay . $toolText_split . $sYdisplay . $toolText_split . $sZdisplay . "' color='" . (in_array($key, $aBoldIDs) ? '1874cd' : '008b00') . "'/>";
             $sCount++;
         }
         //categories数据
         for ($i = 0; $i <= $iXLines; $i++) {
             $categories .= "<category  label='" . ($i > 0 ? \YcheukfReport\Lib\ALYS\ALYSFormat::formatNumber($i * $iXPlus) . $_labelSuffix : '') . "' x='" . $i * $iXPlus . "' showVerticalLine='1' />";
         }
         //设置最后一条 无刻度
         $categories .= "<category  label=' ' x='" . ($i + 1) * $iXPlus . "' showVerticalLine='0' />";
     } else {
         $datasets .= "<set />";
     }
     //trend line(平均线 还有平均线上的点) 添加到dataset数据后边
     $fYAvg = $fXAvg = $fZAvg = 0;
     if (($iYcnt = count($aY)) > 0) {
         $fYAvg = round(array_sum($aY) / $iYcnt, 2);
         $sTrendline = "<trendlines><line startValue='" . $fYAvg . "' isTrendZone='0' displayValue='" . $oDict->ALYSmetricFormat($sYkey, $fYAvg) . "' color='FF0000' dashed='1' dashGap='5' /></trendlines>";
     }
     if (($iXcnt = count($aX)) > 0) {
         $fXAvg = round(array_sum($aX) / $iXcnt, 2);
         $sTrendline .= "<vTrendlines><line startValue='" . $fXAvg . "' isTrendZone='0'  endValue='" . $fXAvg . "' color='FF0000' dashed='1' dashGap='5' /></vTrendlines>";
     }
     if (($iZcnt = count($aZ)) > 0) {
         $fZAvg = round(array_sum($aZ) / $iZcnt, 2);
     }
     if ($fYAvg > 0 && $fXAvg > 0) {
         $sAvgXdisplay = $sXkeyLang . ':' . $oDict->ALYSmetricFormat($sXkey, $fXAvg);
         $sAvgYdisplay = $sYkeyLang . ':' . $oDict->ALYSmetricFormat($sYkey, $fYAvg);
         $sAvgZdisplay = $sZkeyLang . ':' . $oDict->ALYSmetricFormat($sZkey, $fZAvg);
         $datasets .= "<set x='" . $fXAvg . "' y='" . $fYAvg . "' z='" . $fZAvg . "' toolText='" . \YcheukfReport\Lib\ALYS\ALYSLang::_('Bubble_Average') . "{br}" . $sAvgXdisplay . $toolText_split . $sAvgYdisplay . $toolText_split . $sAvgZdisplay . "' color='FF0000'/>";
     }
     $datasets .= '</dataset>';
     $datasets .= $sTrendline;
     return array($categories, $datasets, $sCount);
 }