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

Generated by: LCOV version 1.10