LCOV - code coverage report
Current view: top level - chart2/source/tools - MovingAverageRegressionCurveCalculator.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 26 33 78.8 %
Date: 2014-11-03 Functions: 5 7 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "MovingAverageRegressionCurveCalculator.hxx"
      21             : #include "RegressionCalculationHelper.hxx"
      22             : #include "ResId.hxx"
      23             : #include "Strings.hrc"
      24             : #include "macros.hxx"
      25             : 
      26             : #include <rtl/math.hxx>
      27             : #include <rtl/ustrbuf.hxx>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : namespace chart
      32             : {
      33             : 
      34          14 : MovingAverageRegressionCurveCalculator::MovingAverageRegressionCurveCalculator()
      35          14 : {}
      36             : 
      37          28 : MovingAverageRegressionCurveCalculator::~MovingAverageRegressionCurveCalculator()
      38          28 : {}
      39             : 
      40             : // ____ XRegressionCurveCalculator ____
      41          14 : void SAL_CALL MovingAverageRegressionCurveCalculator::recalculateRegression(
      42             :     const uno::Sequence< double >& aXValues,
      43             :     const uno::Sequence< double >& aYValues )
      44             :     throw (uno::RuntimeException, std::exception)
      45             : {
      46          14 :     ::rtl::math::setNan( & m_fCorrelationCoeffitient );
      47             : 
      48             :     RegressionCalculationHelper::tDoubleVectorPair aValues(
      49             :         RegressionCalculationHelper::cleanup(
      50             :             aXValues, aYValues,
      51          14 :             RegressionCalculationHelper::isValid()));
      52             : 
      53          14 :     const size_t aSize = aValues.first.size();
      54             : 
      55          14 :     aYList.clear();
      56          14 :     aXList.clear();
      57             : 
      58          84 :     for( size_t i = mPeriod - 1; i < aSize; ++i )
      59             :     {
      60             :         double yAvg;
      61          70 :         yAvg = 0.0;
      62             : 
      63         280 :         for (sal_Int32 j = 0; j < mPeriod; j++)
      64             :         {
      65         210 :             yAvg += aValues.second[i - j];
      66             :         }
      67          70 :         yAvg /= mPeriod;
      68             : 
      69          70 :         double x = aValues.first[i];
      70          70 :         aYList.push_back(yAvg);
      71          70 :         aXList.push_back(x);
      72          14 :     }
      73          14 : }
      74             : 
      75           0 : double SAL_CALL MovingAverageRegressionCurveCalculator::getCurveValue( double /*x*/ )
      76             :     throw (lang::IllegalArgumentException,
      77             :            uno::RuntimeException, std::exception)
      78             : {
      79             :     double fResult;
      80           0 :     rtl::math::setNan(&fResult);
      81           0 :     return fResult;
      82             : }
      83             : 
      84          14 : 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)
      91             : {
      92          14 :     uno::Sequence< geometry::RealPoint2D > aResult( aYList.size() );
      93             : 
      94          84 :     for( size_t i = 0; i < aYList.size(); ++i )
      95             :     {
      96          70 :         aResult[i].X = aXList[i];
      97          70 :         aResult[i].Y = aYList[i];
      98             :     }
      99          14 :     return aResult;
     100             : }
     101             : 
     102           0 : OUString MovingAverageRegressionCurveCalculator::ImplGetRepresentation(
     103             :     const uno::Reference< util::XNumberFormatter >& /*xNumFormatter*/,
     104             :     ::sal_Int32 /*nNumberFormatKey*/ ) const
     105             : {
     106           0 :     OUStringBuffer aBuf( "f(x) = N/A");
     107             : 
     108           0 :     aBuf = SCH_RESSTR( STR_OBJECT_MOVING_AVERAGE_WITH_PARAMETERS );
     109             : 
     110           0 :     return aBuf.makeStringAndClear();
     111             : }
     112             : 
     113             : } //  namespace chart
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10