LCOV - code coverage report
Current view: top level - chart2/source/tools - MovingAverageRegressionCurveCalculator.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 33 78.8 %
Date: 2015-06-13 12:38:46 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           7 : MovingAverageRegressionCurveCalculator::MovingAverageRegressionCurveCalculator()
      35           7 : {}
      36             : 
      37          14 : MovingAverageRegressionCurveCalculator::~MovingAverageRegressionCurveCalculator()
      38          14 : {}
      39             : 
      40             : // ____ XRegressionCurveCalculator ____
      41           7 : 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           7 :     ::rtl::math::setNan( & m_fCorrelationCoeffitient );
      47             : 
      48             :     RegressionCalculationHelper::tDoubleVectorPair aValues(
      49             :         RegressionCalculationHelper::cleanup(
      50             :             aXValues, aYValues,
      51           7 :             RegressionCalculationHelper::isValid()));
      52             : 
      53           7 :     const size_t aSize = aValues.first.size();
      54             : 
      55           7 :     aYList.clear();
      56           7 :     aXList.clear();
      57             : 
      58          42 :     for( size_t i = mPeriod - 1; i < aSize; ++i )
      59             :     {
      60             :         double yAvg;
      61          35 :         yAvg = 0.0;
      62             : 
      63         140 :         for (sal_Int32 j = 0; j < mPeriod; j++)
      64             :         {
      65         105 :             yAvg += aValues.second[i - j];
      66             :         }
      67          35 :         yAvg /= mPeriod;
      68             : 
      69          35 :         double x = aValues.first[i];
      70          35 :         aYList.push_back(yAvg);
      71          35 :         aXList.push_back(x);
      72           7 :     }
      73           7 : }
      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           7 : 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           7 :     uno::Sequence< geometry::RealPoint2D > aResult( aYList.size() );
      93             : 
      94          42 :     for( size_t i = 0; i < aYList.size(); ++i )
      95             :     {
      96          35 :         aResult[i].X = aXList[i];
      97          35 :         aResult[i].Y = aYList[i];
      98             :     }
      99           7 :     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.11