1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "MovingAverageRegressionCurveCalculator.hxx"
21 #include "RegressionCalculationHelper.hxx"
23 #include "Strings.hrc"
26 #include <rtl/math.hxx>
27 #include <rtl/ustrbuf.hxx>
29 using namespace ::com::sun::star
;
34 MovingAverageRegressionCurveCalculator::MovingAverageRegressionCurveCalculator()
37 MovingAverageRegressionCurveCalculator::~MovingAverageRegressionCurveCalculator()
40 // ____ XRegressionCurveCalculator ____
41 void SAL_CALL
MovingAverageRegressionCurveCalculator::recalculateRegression(
42 const uno::Sequence
< double >& aXValues
,
43 const uno::Sequence
< double >& aYValues
)
44 throw (uno::RuntimeException
, std::exception
)
46 ::rtl::math::setNan( & m_fCorrelationCoeffitient
);
48 RegressionCalculationHelper::tDoubleVectorPair
aValues(
49 RegressionCalculationHelper::cleanup(
51 RegressionCalculationHelper::isValid()));
53 const size_t aSize
= aValues
.first
.size();
58 for( size_t i
= mPeriod
- 1; i
< aSize
; ++i
)
63 for (sal_Int32 j
= 0; j
< mPeriod
; j
++)
65 yAvg
+= aValues
.second
[i
- j
];
69 double x
= aValues
.first
[i
];
70 aYList
.push_back(yAvg
);
75 double SAL_CALL
MovingAverageRegressionCurveCalculator::getCurveValue( double /*x*/ )
76 throw (lang::IllegalArgumentException
,
77 uno::RuntimeException
, std::exception
)
80 rtl::math::setNan(&fResult
);
84 uno::Sequence
< geometry::RealPoint2D
> SAL_CALL
MovingAverageRegressionCurveCalculator::getCurveValues(
85 double /*min*/, double /*max*/, sal_Int32
/*nPointCount*/,
86 const uno::Reference
< chart2::XScaling
>& /*xScalingX*/,
87 const uno::Reference
< chart2::XScaling
>& /*xScalingY*/,
88 sal_Bool
/*bMaySkipPointsInCalculation*/ )
89 throw (lang::IllegalArgumentException
,
90 uno::RuntimeException
, std::exception
)
92 uno::Sequence
< geometry::RealPoint2D
> aResult( aYList
.size() );
94 for( size_t i
= 0; i
< aYList
.size(); ++i
)
96 aResult
[i
].X
= aXList
[i
];
97 aResult
[i
].Y
= aYList
[i
];
102 OUString
MovingAverageRegressionCurveCalculator::ImplGetRepresentation(
103 const uno::Reference
< util::XNumberFormatter
>& /*xNumFormatter*/,
104 ::sal_Int32
/*nNumberFormatKey*/ ) const
106 OUStringBuffer
aBuf( "f(x) = N/A");
108 aBuf
= SCH_RESSTR( STR_OBJECT_MOVING_AVERAGE_WITH_PARAMETERS
);
110 return aBuf
.makeStringAndClear();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */