3 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/linearBestFitClass.php';
4 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
5 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/exponentialBestFitClass.php';
6 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/powerBestFitClass.php';
7 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/polynomialBestFitClass.php';
25 self::TREND_LOGARITHMIC,
26 self::TREND_EXPONENTIAL,
30 self::TREND_POLYNOMIAL_3,
31 self::TREND_POLYNOMIAL_4,
32 self::TREND_POLYNOMIAL_5,
33 self::TREND_POLYNOMIAL_6
39 public static function calculate($trendType=self::TREND_BEST_FIT, $yValues, $xValues=array(), $const=True) {
41 $nY = count($yValues);
42 $nX = count($xValues);
46 $xValues = range(1,$nY);
48 } elseif ($nY != $nX) {
50 trigger_error(
"trend(): Number of elements in coordinate arrays do not match.", E_USER_ERROR);
53 $key = md5($trendType.$const.serialize($yValues).serialize($xValues));
57 case self::TREND_LINEAR :
58 case self::TREND_LOGARITHMIC :
59 case self::TREND_EXPONENTIAL :
60 case self::TREND_POWER :
61 if (!isset(self::$_trendCache[$key])) {
62 $className =
'PHPExcel_'.$trendType.
'_Best_Fit';
63 self::$_trendCache[$key] =
new $className($yValues,$xValues,$const);
65 return self::$_trendCache[$key];
67 case self::TREND_POLYNOMIAL_2 :
68 case self::TREND_POLYNOMIAL_3 :
69 case self::TREND_POLYNOMIAL_4 :
70 case self::TREND_POLYNOMIAL_5 :
71 case self::TREND_POLYNOMIAL_6 :
72 if (!isset(self::$_trendCache[$key])) {
73 $order = substr($trendType,-1);
76 return self::$_trendCache[$key];
78 case self::TREND_BEST_FIT :
79 case self::TREND_BEST_FIT_NO_POLY :
82 foreach(self::$_trendTypes as $trendMethod) {
83 $className =
'PHPExcel_'.$trendMethod.
'BestFit';
84 $bestFit[$trendMethod] =
new $className($yValues,$xValues,$const);
85 $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
87 if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
88 foreach(self::$_trendTypePolyOrders as $trendMethod) {
89 $order = substr($trendMethod,-1);
91 if ($bestFit[$trendMethod]->getError()) {
92 unset($bestFit[$trendMethod]);
94 $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
99 arsort($bestFitValue);
100 $bestFitType = key($bestFitValue);
101 return $bestFit[$bestFitType];