/src/libreoffice/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
Line | Count | Source |
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 <memory> |
12 | | |
13 | | #include <reffact.hxx> |
14 | | #include <TableFillingAndNavigationTools.hxx> |
15 | | #include <ExponentialSmoothingDialog.hxx> |
16 | | #include <scresid.hxx> |
17 | | #include <strings.hrc> |
18 | | |
19 | | ScExponentialSmoothingDialog::ScExponentialSmoothingDialog( |
20 | | SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow, |
21 | | weld::Window* pParent, ScViewData& rViewData ) |
22 | 0 | : ScStatisticsInputOutputDialog( |
23 | 0 | pSfxBindings, pChildWindow, pParent, rViewData, |
24 | 0 | u"modules/scalc/ui/exponentialsmoothingdialog.ui"_ustr, |
25 | 0 | u"ExponentialSmoothingDialog"_ustr) |
26 | 0 | , mxSmoothingFactor(m_xBuilder->weld_spin_button(u"smoothing-factor-spin"_ustr)) |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | | ScExponentialSmoothingDialog::~ScExponentialSmoothingDialog() |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | void ScExponentialSmoothingDialog::Close() |
35 | 0 | { |
36 | 0 | DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() ); |
37 | 0 | } |
38 | | |
39 | | TranslateId ScExponentialSmoothingDialog::GetUndoNameId() |
40 | 0 | { |
41 | 0 | return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME; |
42 | 0 | } |
43 | | |
44 | | ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell& rDocShell) |
45 | 0 | { |
46 | 0 | AddressWalkerWriter output(mOutputAddress, rDocShell, mDocument, |
47 | 0 | formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv)); |
48 | 0 | FormulaTemplate aTemplate(&mDocument); |
49 | | |
50 | | // Smoothing factor |
51 | 0 | double aSmoothingFactor = mxSmoothingFactor->get_value() / 100.0; |
52 | | |
53 | | // Alpha |
54 | 0 | output.writeBoldString(ScResId(STR_LABEL_ALPHA)); |
55 | 0 | output.nextRow(); |
56 | | |
57 | | // Alpha Value |
58 | 0 | ScAddress aSmoothingFactorAddress = output.current(); |
59 | 0 | output.writeValue(aSmoothingFactor); |
60 | 0 | output.nextRow(); |
61 | | |
62 | | // Exponential Smoothing |
63 | 0 | output.push(); |
64 | |
|
65 | 0 | std::unique_ptr<DataRangeIterator> pIterator; |
66 | 0 | if (mGroupedBy == BY_COLUMN) |
67 | 0 | pIterator.reset(new DataRangeByColumnIterator(mInputRange)); |
68 | 0 | else |
69 | 0 | pIterator.reset(new DataRangeByRowIterator(mInputRange)); |
70 | |
|
71 | 0 | for( ; pIterator->hasNext(); pIterator->next() ) |
72 | 0 | { |
73 | 0 | output.resetRow(); |
74 | |
|
75 | 0 | ScRange aCurrentRange = pIterator->get(); |
76 | | |
77 | | // Write column label |
78 | 0 | if (mGroupedBy == BY_COLUMN) |
79 | 0 | aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE)); |
80 | 0 | else |
81 | 0 | aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE)); |
82 | 0 | aTemplate.applyNumber(u"%NUMBER%", pIterator->index() + 1); |
83 | 0 | output.writeBoldString(aTemplate.getTemplate()); |
84 | 0 | output.nextRow(); |
85 | | |
86 | | // Initial value |
87 | 0 | if ((false)) |
88 | 0 | { |
89 | 0 | aTemplate.setTemplate("=AVERAGE(%RANGE%)"); |
90 | 0 | aTemplate.applyRange(u"%RANGE%", aCurrentRange); |
91 | 0 | output.writeFormula(aTemplate.getTemplate()); |
92 | 0 | } |
93 | 0 | else |
94 | 0 | { |
95 | 0 | aTemplate.setTemplate("=%VAR%"); |
96 | 0 | aTemplate.applyAddress(u"%VAR%", aCurrentRange.aStart); |
97 | 0 | output.writeFormula(aTemplate.getTemplate()); |
98 | 0 | } |
99 | |
|
100 | 0 | output.nextRow(); |
101 | |
|
102 | 0 | DataCellIterator aDataCellIterator = pIterator->iterateCells(); |
103 | |
|
104 | 0 | for (; aDataCellIterator.hasNext(); aDataCellIterator.next()) |
105 | 0 | { |
106 | 0 | aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%"); |
107 | 0 | aTemplate.applyAddress(u"%PREVIOUS_INPUT%", aDataCellIterator.get()); |
108 | 0 | aTemplate.applyAddress(u"%PREVIOUS_OUTPUT%", output.current(0, -1)); |
109 | 0 | aTemplate.applyAddress(u"%VALUE%", aSmoothingFactorAddress); |
110 | |
|
111 | 0 | output.writeFormula(aTemplate.getTemplate()); |
112 | 0 | output.nextRow(); |
113 | 0 | } |
114 | 0 | output.nextColumn(); |
115 | 0 | } |
116 | |
|
117 | 0 | return ScRange (output.mMinimumAddress, output.mMaximumAddress); |
118 | 0 | } |
119 | | |
120 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |