LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - TTestDialog.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 3 113 2.7 %
Date: 2014-04-11 Functions: 2 8 25.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             :  */
      10             : 
      11             : #include <sfx2/dispatch.hxx>
      12             : #include <svl/zforlist.hxx>
      13             : #include <svl/undo.hxx>
      14             : #include <boost/random.hpp>
      15             : #include <boost/scoped_ptr.hpp>
      16             : 
      17             : #include "formulacell.hxx"
      18             : #include "rangelst.hxx"
      19             : #include "scitems.hxx"
      20             : #include "docsh.hxx"
      21             : #include "document.hxx"
      22             : #include "uiitems.hxx"
      23             : #include "reffact.hxx"
      24             : #include "strload.hxx"
      25             : #include "random.hxx"
      26             : #include "docfunc.hxx"
      27             : #include "StatisticsDialogs.hrc"
      28             : #include "TableFillingAndNavigationTools.hxx"
      29             : 
      30             : #include "TTestDialog.hxx"
      31             : 
      32             : namespace
      33             : {
      34             : 
      35          34 : static const OUString strWildcardVariable1Range("%VAR1_RANGE%");
      36          34 : static const OUString strWildcardVariable2Range("%VAR2_RANGE%");
      37             : 
      38             : }
      39             : 
      40           0 : ScTTestDialog::ScTTestDialog(
      41             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      42             :                     Window* pParent, ScViewData* pViewData ) :
      43             :     ScStatisticsTwoVariableDialog(
      44             :             pSfxBindings, pChildWindow, pParent, pViewData,
      45           0 :             "TTestDialog", "modules/scalc/ui/ttestdialog.ui" )
      46           0 : {}
      47             : 
      48           0 : ScTTestDialog::~ScTTestDialog()
      49           0 : {}
      50             : 
      51           0 : bool ScTTestDialog::Close()
      52             : {
      53           0 :     return DoClose( ScTTestDialogWrapper::GetChildWindowId() );
      54             : }
      55             : 
      56           0 : sal_Int16 ScTTestDialog::GetUndoNameId()
      57             : {
      58           0 :     return STR_TTEST_UNDO_NAME;
      59             : }
      60             : 
      61           0 : ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
      62             : {
      63             :     AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
      64           0 :             formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
      65           0 :     FormulaTemplate aTemplate(mDocument, mAddressDetails);
      66             : 
      67           0 :     boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
      68           0 :     if (mGroupedBy == BY_COLUMN)
      69           0 :         pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
      70             :     else
      71           0 :         pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
      72             : 
      73           0 :     boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
      74           0 :     if (mGroupedBy == BY_COLUMN)
      75           0 :         pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
      76             :     else
      77           0 :         pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
      78             : 
      79           0 :     aTemplate.autoReplaceRange(strWildcardVariable1Range, pVariable1Iterator->get());
      80           0 :     aTemplate.autoReplaceRange(strWildcardVariable2Range, pVariable2Iterator->get());
      81             : 
      82           0 :     aOutput.nextRow();
      83           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
      84           0 :     aOutput.nextRow();
      85           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
      86           0 :     aOutput.nextRow();
      87           0 :     aOutput.writeString("Observations");
      88           0 :     aOutput.nextRow();
      89           0 :     aOutput.writeString("Pearson Correlation");
      90           0 :     aOutput.nextRow();
      91           0 :     aOutput.writeString("Hypothesized Mean Difference");
      92           0 :     aOutput.nextRow();
      93           0 :     aOutput.writeString("Observed Mean Difference");
      94           0 :     aOutput.nextRow();
      95           0 :     aOutput.writeString("Variance of the Differences");
      96           0 :     aOutput.nextRow();
      97           0 :     aOutput.writeString("df");
      98           0 :     aOutput.nextRow();
      99           0 :     aOutput.writeString("t Stat");
     100           0 :     aOutput.nextRow();
     101           0 :     aOutput.writeString("P (T<=t) one-tail");
     102           0 :     aOutput.nextRow();
     103           0 :     aOutput.writeString("t Critical one-tail");
     104           0 :     aOutput.nextRow();
     105           0 :     aOutput.writeString("P (T<=t) two-tail");
     106           0 :     aOutput.nextRow();
     107           0 :     aOutput.writeString("t Critical two-tail");
     108           0 :     aOutput.resetRow();
     109             : 
     110           0 :     aOutput.nextColumn();
     111             : 
     112           0 :     aOutput.writeString("Variable 1");
     113           0 :     aOutput.nextRow();
     114             : 
     115           0 :     aTemplate.setTemplate("=AVERAGE(%VAR1_RANGE%)");
     116           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     117           0 :     aOutput.nextRow();
     118             : 
     119           0 :     aTemplate.setTemplate("=VAR(%VAR1_RANGE%)");
     120           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     121           0 :     aOutput.nextRow();
     122             : 
     123           0 :     aTemplate.setTemplate("=COUNT(%VAR1_RANGE%)");
     124           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     125           0 :     aOutput.nextRow();
     126             : 
     127           0 :     aTemplate.setTemplate("=CORREL(%VAR1_RANGE%;%VAR2_RANGE%)");
     128           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     129           0 :     aOutput.nextRow();
     130             : 
     131           0 :     aOutput.writeValue(2);
     132           0 :     aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
     133           0 :     aOutput.nextRow();
     134             : 
     135           0 :     aTemplate.setTemplate("=AVERAGE(IF(ISODD(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)); %VAR1_RANGE% - %VAR2_RANGE%; \"NA\"))");
     136           0 :     aOutput.writeMatrixFormula(aTemplate.getTemplate());
     137           0 :     aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
     138           0 :     aOutput.nextRow();
     139             : 
     140           0 :     aTemplate.setTemplate("=VAR(IF(ISODD(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)); %VAR1_RANGE% - %VAR2_RANGE%; \"NA\"))");
     141           0 :     aOutput.writeMatrixFormula(aTemplate.getTemplate());
     142           0 :     aTemplate.autoReplaceAddress("%VARIANCE_OF_DIFFERENCES%", aOutput.current());
     143           0 :     aOutput.nextRow();
     144             : 
     145           0 :     aTemplate.setTemplate("=SUM(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)) - 1");
     146           0 :     aOutput.writeMatrixFormula(aTemplate.getTemplate());
     147           0 :     aTemplate.autoReplaceAddress("%DEGREE_OF_FREEDOM%", aOutput.current());
     148           0 :     aOutput.nextRow();
     149             : 
     150           0 :     aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / (%VARIANCE_OF_DIFFERENCES% / ( %DEGREE_OF_FREEDOM% + 1)) ^ 0.5");
     151           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     152           0 :     aTemplate.autoReplaceAddress("%T_STAT%", aOutput.current());
     153           0 :     aOutput.nextRow();
     154             : 
     155           0 :     aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 1)");
     156           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     157           0 :     aOutput.nextRow();
     158             : 
     159           0 :     aTemplate.setTemplate("=TINV(2*0.05; %DEGREE_OF_FREEDOM%)");
     160           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     161           0 :     aOutput.nextRow();
     162             : 
     163           0 :     aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 2)");
     164           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     165           0 :     aOutput.nextRow();
     166             : 
     167           0 :     aTemplate.setTemplate("=TINV(0.05; %DEGREE_OF_FREEDOM%)");
     168           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     169           0 :     aOutput.nextRow();
     170             : 
     171           0 :     aOutput.resetRow();
     172             : 
     173           0 :     aOutput.nextColumn();
     174             : 
     175           0 :     aOutput.writeString("Variable 2");
     176           0 :     aOutput.nextRow();
     177             : 
     178           0 :     aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
     179           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     180           0 :     aOutput.nextRow();
     181             : 
     182           0 :     aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
     183           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     184           0 :     aOutput.nextRow();
     185             : 
     186           0 :     aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
     187           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     188           0 :     aOutput.nextRow();
     189             : 
     190           0 :     aOutput.resetRow();
     191             : 
     192           0 :     return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
     193         102 : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10