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-13 18:55:08 +0000
commitad707a3dafd020949cfd94098dc51c69466dafb8 (patch)
tree5656f56c58a6ec47cfbbac2e8d10b9d6059a82dd
parent22b0c09f8463b9c6cceb9e2c3addcab79d42aa0b (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>
-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 894c62351375..5f98f269bbe1 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;
}