sc/source/core/tool/interpr8.cxx |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

New commits:
commit aaa38fd34faab3108245f8fa8c13642919ff0c95
Author: Winfried Donkers <winfrieddonk...@libreoffice.org>
Date:   Thu Sep 15 13:39:35 2016 +0200

    tdf#94635 follow up; handle linear data properly when samples in period
    
    are to be calculated by function.
    
    Applies to all FORECAST.ETS functions with argument period_length having
    value 1.
    
    Reviewed-on: https://gerrit.libreoffice.org/28923
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Eike Rathke <er...@redhat.com>
    (cherry picked from commit fb790880eb11552b2e7d1dcf6c09d2663712290f)
    
    Minus the modification to the function test case that does not exist in 5-2.
    
    Change-Id: Icb5a0288670321caf0dd5b70bee4b8811b9ba4a9
    Reviewed-on: https://gerrit.libreoffice.org/29891
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins <c...@libreoffice.org>

diff --git a/sc/source/core/tool/interpr8.cxx b/sc/source/core/tool/interpr8.cxx
index 7a02955..a31b061 100644
--- a/sc/source/core/tool/interpr8.cxx
+++ b/sc/source/core/tool/interpr8.cxx
@@ -195,11 +195,6 @@ bool ScETSForecastCalculation::PreprocessDataRange( const 
ScMatrixRef& rMatX, co
         }
     }
 
-    if ( rSmplInPrd != 1 )
-        mnSmplInPrd = rSmplInPrd;
-    else
-        mnSmplInPrd = CalcPeriodLen();
-
     // Month intervals don't have exact stepsize, so first
     // detect if month interval is used.
     // Method: assume there is an month interval and verify.
@@ -378,6 +373,16 @@ bool ScETSForecastCalculation::PreprocessDataRange( const 
ScMatrixRef& rMatX, co
             }
         }
     }
+
+    if ( rSmplInPrd != 1 )
+        mnSmplInPrd = rSmplInPrd;
+    else
+    {
+         mnSmplInPrd = CalcPeriodLen();
+        if ( mnSmplInPrd == 1 )
+            bEDS = true; // period length 1 means no periodic data: EDS 
suffices
+    }
+
     if ( !initData() )
         return false;  // note: mnErrorValue is set in called function(s)
 
@@ -536,7 +541,7 @@ SCSIZE ScETSForecastCalculation::CalcPeriodLen()
     SCSIZE nBestVal = mnCount;
     double fBestME = ::std::numeric_limits<double>::max();
 
-    for ( SCSIZE nPeriodLen = mnCount / 2; nPeriodLen > 1; nPeriodLen-- )
+    for ( SCSIZE nPeriodLen = mnCount / 2; nPeriodLen >= 1; nPeriodLen-- )
     {
         double fMeanError = 0.0;
         SCSIZE nPeriods = mnCount / nPeriodLen;
@@ -548,7 +553,7 @@ SCSIZE ScETSForecastCalculation::CalcPeriodLen()
         }
         fMeanError /= static_cast< double >( ( nPeriods - 1 ) * nPeriodLen - 1 
);
 
-        if ( fMeanError < fBestME || fMeanError == 0.0 )
+        if ( fMeanError <= fBestME || fMeanError == 0.0 )
         {
             nBestVal = nPeriodLen;
             fBestME = fMeanError;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to