fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <svl/zforlist.hxx>
|
|
|
|
#include <svl/undo.hxx>
|
|
|
|
|
|
|
|
#include "formulacell.hxx"
|
|
|
|
#include "rangelst.hxx"
|
|
|
|
#include "scitems.hxx"
|
|
|
|
#include "docsh.hxx"
|
|
|
|
#include "document.hxx"
|
|
|
|
#include "uiitems.hxx"
|
|
|
|
#include "reffact.hxx"
|
2013-10-30 00:09:57 +01:00
|
|
|
#include "strload.hxx"
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
#include "random.hxx"
|
|
|
|
#include "docfunc.hxx"
|
2013-10-30 00:09:57 +01:00
|
|
|
#include "StatisticsDialogs.hrc"
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
|
|
|
|
#include <boost/random.hpp>
|
|
|
|
|
|
|
|
#include "DescriptiveStatisticsDialog.hxx"
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-07-18 22:32:22 +02:00
|
|
|
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
struct StatisticCalculation {
|
2013-07-25 13:07:57 +03:00
|
|
|
sal_Int16 aCalculationNameId;
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
const char* aFormula;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const StatisticCalculation lclCalcDefinitions[] =
|
|
|
|
{
|
2013-10-30 00:32:52 +01:00
|
|
|
{ STRID_CALC_MEAN, "=AVERAGE(%RANGE%)" },
|
|
|
|
{ STRID_CALC_STD_ERROR, "=SQRT(VAR(%RANGE%)/COUNT(%RANGE%))"},
|
|
|
|
{ STRID_CALC_MODE, "=MODE(%RANGE%)"},
|
|
|
|
{ STRID_CALC_MEDIAN, "=MEDIAN(%RANGE%)"},
|
|
|
|
{ STRID_CALC_VARIANCE, "=VAR(%RANGE%)"},
|
|
|
|
{ STRID_CALC_STD_DEVIATION, "=STDEV(%RANGE%)"},
|
|
|
|
{ STRID_CALC_KURTOSIS, "=KURT(%RANGE%)"},
|
|
|
|
{ STRID_CALC_SKEWNESS, "=SKEW(%RANGE%)"},
|
|
|
|
{ STRID_CALC_RANGE, "=MAX(%RANGE%)-MIN(%RANGE%)"},
|
|
|
|
{ STRID_CALC_MIN, "=MIN(%RANGE%)"},
|
|
|
|
{ STRID_CALC_MAX, "=MAX(%RANGE%)"},
|
|
|
|
{ STRID_CALC_SUM, "=SUM(%RANGE%)"},
|
|
|
|
{ STRID_CALC_COUNT, "=COUNT(%RANGE%)" },
|
|
|
|
{ 0, NULL }
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
};
|
|
|
|
|
2013-11-03 12:10:19 +01:00
|
|
|
static const OUString strWildcardRange("%RANGE%");
|
2013-07-22 18:35:07 +02:00
|
|
|
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ScDescriptiveStatisticsDialog::ScDescriptiveStatisticsDialog(
|
2013-07-18 22:32:22 +02:00
|
|
|
SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
|
|
|
|
Window* pParent, ScViewData* pViewData ) :
|
2013-07-22 18:35:07 +02:00
|
|
|
ScStatisticsInputOutputDialog(
|
|
|
|
pSfxBindings, pChildWindow, pParent, pViewData,
|
|
|
|
"DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" )
|
|
|
|
{}
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
|
|
|
|
ScDescriptiveStatisticsDialog::~ScDescriptiveStatisticsDialog()
|
|
|
|
{}
|
|
|
|
|
|
|
|
sal_Bool ScDescriptiveStatisticsDialog::Close()
|
|
|
|
{
|
|
|
|
return DoClose( ScDescriptiveStatisticsDialogWrapper::GetChildWindowId() );
|
|
|
|
}
|
|
|
|
|
2013-07-22 18:35:07 +02:00
|
|
|
void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
{
|
2013-07-19 16:51:05 +02:00
|
|
|
OUString aUndo(SC_RESSTR(STR_DESCRIPTIVE_STATISTICS_UNDO_NAME));
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
ScDocShell* pDocShell = mViewData->GetDocShell();
|
|
|
|
svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
|
|
|
|
pUndoManager->EnterListAction( aUndo, aUndo );
|
|
|
|
|
|
|
|
ScAddress aStart = mInputRange.aStart;
|
|
|
|
ScAddress aEnd = mInputRange.aEnd;
|
|
|
|
|
|
|
|
SCTAB outTab = mOutputAddress.Tab();
|
|
|
|
SCCOL outCol = mOutputAddress.Col();
|
|
|
|
SCROW outRow = mOutputAddress.Row();
|
|
|
|
|
|
|
|
OUString aReferenceString;
|
|
|
|
ScAddress aAddress;
|
|
|
|
|
|
|
|
for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
|
|
|
|
{
|
|
|
|
outCol = mOutputAddress.Col();
|
|
|
|
|
|
|
|
for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
|
|
|
|
{
|
|
|
|
aAddress = ScAddress(outCol, outRow, outTab);
|
2013-07-19 16:51:05 +02:00
|
|
|
OUString aCalculationName(SC_RESSTR(lclCalcDefinitions[i].aCalculationNameId));
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
pDocShell->GetDocFunc().SetStringCell(aAddress, aCalculationName, true);
|
|
|
|
outRow++;
|
|
|
|
}
|
|
|
|
outCol++;
|
|
|
|
|
|
|
|
for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
|
|
|
|
{
|
|
|
|
outRow = mOutputAddress.Row();
|
|
|
|
ScRange aColumnRange (
|
|
|
|
ScAddress(inCol, mInputRange.aStart.Row(), inTab),
|
|
|
|
ScAddress(inCol, mInputRange.aEnd.Row(), inTab)
|
|
|
|
);
|
|
|
|
|
2013-08-29 20:44:22 +01:00
|
|
|
aReferenceString = aColumnRange.Format(SCR_ABS, mDocument, mAddressDetails);
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
OUString aFormulaString;
|
|
|
|
OUString aFormulaTemplate;
|
|
|
|
|
|
|
|
for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
|
|
|
|
{
|
|
|
|
aAddress = ScAddress(outCol, outRow, outTab);
|
|
|
|
aFormulaTemplate = OUString::createFromAscii(lclCalcDefinitions[i].aFormula);
|
2013-11-03 12:10:19 +01:00
|
|
|
aFormulaString = aFormulaTemplate.replaceAll(strWildcardRange, aReferenceString);
|
fdo#66477 Add descriptive statistics calculation to Calc.
New menu entry in "Data>>Statistics>>Descriptive Statistics..." to
quickly calculate basic statistics for a row of data. These are
Mean, Standard Error, Mode, Median, Variance, Standard Deviation,
Kurtosis, Skewness, Range, Minimum, Maximum, Sum and Count.
Change-Id: I7c4a75adf7731f42f9c7f8e741ff1b5fa245c1c8
2013-07-18 21:44:54 +02:00
|
|
|
pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
|
|
|
|
outRow++;
|
|
|
|
}
|
|
|
|
outCol++;
|
|
|
|
}
|
|
|
|
outTab++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScRange aOutputRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
|
|
|
|
pUndoManager->LeaveListAction();
|
|
|
|
pDocShell->PostPaint( aOutputRange, PAINT_GRID );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|