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

Generated by: LCOV version 1.11