LCOV - code coverage report
Current view: top level - chart2/source/tools - MeanValueRegressionCurveCalculator.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 44 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
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 "MeanValueRegressionCurveCalculator.hxx"
      21             : #include "macros.hxx"
      22             : 
      23             : #include <rtl/math.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : 
      26             : using namespace ::com::sun::star;
      27             : 
      28             : namespace chart
      29             : {
      30             : 
      31           0 : MeanValueRegressionCurveCalculator::MeanValueRegressionCurveCalculator() :
      32           0 :         m_fMeanValue( 0.0 )
      33             : {
      34           0 :     ::rtl::math::setNan( & m_fMeanValue );
      35           0 : }
      36             : 
      37           0 : MeanValueRegressionCurveCalculator::~MeanValueRegressionCurveCalculator()
      38           0 : {}
      39             : 
      40             : // ____ XRegressionCurveCalculator ____
      41           0 : void SAL_CALL MeanValueRegressionCurveCalculator::recalculateRegression(
      42             :     const uno::Sequence< double >& /*aXValues*/,
      43             :     const uno::Sequence< double >& aYValues )
      44             :     throw (uno::RuntimeException, std::exception)
      45             : {
      46           0 :     const sal_Int32 nDataLength = aYValues.getLength();
      47           0 :     sal_Int32 nMax = nDataLength;
      48           0 :     double fSumY = 0.0;
      49           0 :     const double * pY = aYValues.getConstArray();
      50             : 
      51           0 :     for( sal_Int32 i = 0; i < nDataLength; ++i )
      52             :     {
      53           0 :         if( ::rtl::math::isNan( pY[i] ) ||
      54           0 :             ::rtl::math::isInf( pY[i] ))
      55           0 :             --nMax;
      56             :         else
      57           0 :             fSumY += pY[i];
      58             :     }
      59             : 
      60           0 :     m_fCorrelationCoeffitient = 0.0;
      61             : 
      62           0 :     if( nMax == 0 )
      63             :     {
      64           0 :         ::rtl::math::setNan( & m_fMeanValue );
      65             :     }
      66             :     else
      67             :     {
      68           0 :         m_fMeanValue = fSumY / static_cast< double >( nMax );
      69             : 
      70             :         // correlation coefficient: standard deviation
      71           0 :         if( nMax > 1 )
      72             :         {
      73           0 :             double fErrorSum = 0.0;
      74           0 :             for( sal_Int32 i = 0; i < nDataLength; ++i )
      75             :             {
      76           0 :                 if( !::rtl::math::isNan( pY[i] ) &&
      77           0 :                     !::rtl::math::isInf( pY[i] ))
      78             :                 {
      79           0 :                     double v = m_fMeanValue - pY[i];
      80           0 :                     fErrorSum += (v*v);
      81             :                 }
      82             :             }
      83             :             OSL_ASSERT( fErrorSum >= 0.0 );
      84           0 :             m_fCorrelationCoeffitient = sqrt( fErrorSum / (nMax - 1 ));
      85             :         }
      86             :     }
      87           0 : }
      88             : 
      89           0 : double SAL_CALL MeanValueRegressionCurveCalculator::getCurveValue( double /*x*/ )
      90             :     throw (lang::IllegalArgumentException,
      91             :            uno::RuntimeException, std::exception)
      92             : {
      93           0 :     return m_fMeanValue;
      94             : }
      95             : 
      96           0 : uno::Sequence< geometry::RealPoint2D > SAL_CALL MeanValueRegressionCurveCalculator::getCurveValues(
      97             :     double min, double max, ::sal_Int32 nPointCount,
      98             :     const uno::Reference< chart2::XScaling >& xScalingX,
      99             :     const uno::Reference< chart2::XScaling >& xScalingY,
     100             :     sal_Bool bMaySkipPointsInCalculation )
     101             :     throw (lang::IllegalArgumentException,
     102             :            uno::RuntimeException, std::exception)
     103             : {
     104           0 :     if( bMaySkipPointsInCalculation )
     105             :     {
     106             :         // optimize result
     107           0 :         uno::Sequence< geometry::RealPoint2D > aResult( 2 );
     108           0 :         aResult[0].X = min;
     109           0 :         aResult[0].Y = m_fMeanValue;
     110           0 :         aResult[1].X = max;
     111           0 :         aResult[1].Y = m_fMeanValue;
     112             : 
     113           0 :         return aResult;
     114             :     }
     115           0 :     return RegressionCurveCalculator::getCurveValues( min, max, nPointCount, xScalingX, xScalingY, bMaySkipPointsInCalculation );
     116             : }
     117             : 
     118           0 : OUString MeanValueRegressionCurveCalculator::ImplGetRepresentation(
     119             :     const uno::Reference< util::XNumberFormatter >& xNumFormatter,
     120             :     ::sal_Int32 nNumberFormatKey ) const
     121             : {
     122           0 :     OUString aBuf = "f(x) = " +
     123           0 :                     getFormattedString( xNumFormatter, nNumberFormatKey, m_fMeanValue );
     124             : 
     125           0 :     return aBuf;
     126             : }
     127             : 
     128             : } //  namespace chart
     129             : 
     130             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10