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

Generated by: LCOV version 1.10