summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2016-09-20 08:04:50 +0200
committerEike Rathke <erack@redhat.com>2016-10-14 18:08:29 +0000
commitf617d9466632f656811474cd49311e13ab950753 (patch)
tree08eb5ea88f7a4b774d83f2443667346a1920556e
parent24998064599e3371208ad8ae4b149d754828d35b (diff)
tdf#94635 follow up; correct handling of double x-values in case of
month intervals. Change-Id: I310d8d127d6b9ca571200ba8974a980430d69eb7 Reviewed-on: https://gerrit.libreoffice.org/29076 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> (cherry picked from commit ad707a3dafd020949cfd94098dc51c69466dafb8) Reviewed-on: https://gerrit.libreoffice.org/29886
-rw-r--r--sc/source/core/tool/interpr8.cxx37
1 files changed, 13 insertions, 24 deletions
diff --git a/sc/source/core/tool/interpr8.cxx b/sc/source/core/tool/interpr8.cxx
index 972b125267c0..7a02955df4ea 100644
--- a/sc/source/core/tool/interpr8.cxx
+++ b/sc/source/core/tool/interpr8.cxx
@@ -221,16 +221,14 @@ bool ScETSForecastCalculation::PreprocessDataRange( const ScMatrixRef& rMatX, co
mfStepSize = ::std::numeric_limits<double>::max();
if ( mnMonthDay )
{
- aDate = aNullDate + static_cast< long >( maRange[ 0 ].X );
- maRange[ 0 ].X = aDate.GetYear() * 12 + aDate.GetMonth();
- }
- for ( SCSIZE i = 1; i < mnCount; i++ )
- {
- if ( mnMonthDay )
+ for ( SCSIZE i = 0; i < mnCount; i++ )
{
aDate = aNullDate + static_cast< long >( maRange[ i ].X );
maRange[ i ].X = aDate.GetYear() * 12 + aDate.GetMonth();
}
+ }
+ for ( SCSIZE i = 1; i < mnCount; i++ )
+ {
double fStep = maRange[ i ].X - maRange[ i - 1 ].X;
if ( fStep == 0.0 )
{
@@ -245,15 +243,20 @@ bool ScETSForecastCalculation::PreprocessDataRange( const ScMatrixRef& rMatX, co
switch ( nAggregation )
{
case 1 : // AVERAGE (default)
+ while ( maRange[ i ].X == maRange[ i - 1 ].X && i < mnCount )
+ {
+ maRange.erase( maRange.begin() + i );
+ --mnCount;
+ }
+ break;
case 7 : // SUM
while ( maRange[ i ].X == maRange[ i - 1 ].X && i < mnCount )
{
fTmp += maRange[ i ].Y;
- nCounter++;
maRange.erase( maRange.begin() + i );
--mnCount;
}
- maRange[ i - 1 ].Y = ( nAggregation == 1 ? fTmp / nCounter : fTmp );
+ maRange[ i - 1 ].Y = fTmp;
break;
case 2 : // COUNT
@@ -310,22 +313,11 @@ bool ScETSForecastCalculation::PreprocessDataRange( const ScMatrixRef& rMatX, co
break;
}
if ( i < mnCount - 1 )
- {
- i++;
- if ( mnMonthDay )
- {
- Date aDate1 = aNullDate + static_cast< long >( maRange[ i ].X );
- fStep = 12 * ( aDate1.GetYear() - aDate.GetYear() ) +
- ( aDate1.GetMonth() - aDate.GetMonth() );
- aDate = aDate1;
- }
- else
- fStep = maRange[ i ].X - maRange[ i - 1 ].X;
- }
+ fStep = maRange[ i ].X - maRange[ i - 1 ].X;
else
fStep = mfStepSize;
}
- if ( fStep < mfStepSize )
+ if ( fStep > 0 && fStep < mfStepSize )
mfStepSize = fStep;
}
@@ -972,9 +964,6 @@ bool ScETSForecastCalculation::GetStatisticValue( const ScMatrixRef& rTypeMat, c
bool ScETSForecastCalculation::GetSamplesInPeriod( double& rVal )
{
- if ( !initCalc() )
- return false;
-
rVal = mnSmplInPrd;
return true;
}