gnumeric r16824 - in trunk: . src/dialogs src/tools
- From: guelzow svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r16824 - in trunk: . src/dialogs src/tools
- Date: Wed, 24 Sep 2008 06:07:50 +0000 (UTC)
Author: guelzow
Date: Wed Sep 24 06:07:50 2008
New Revision: 16824
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16824&view=rev
Log:
2008-09-23 Andreas J. Guelzow <aguelzow pyrshep ca>
* analysis-tools.c (analysis_tool_moving_average_engine_run): fix
central moving average for even interval (we should average the
averages), add weighted and cumulative moving averages.
* analysis-tools.h (moving_average_type_t): new type
(analysis_tools_data_moving_average_t): new field
2008-09-23 Andreas J. Guelzow <aguelzow pyrshep ca>
* moving-averages.glade: move items
* dialog-analysis-tools.c (moving_average_group): new
group for radio buttons
(average_tool_sma_cb): new
(average_tool_cma_cb): new
(average_tool_wma_cb): new
(average_tool_spencer_cb): new
(dialog_average_tool): setup new controls
(average_tool_ok_clicked_cb): handle new controls
Modified:
trunk/NEWS
trunk/src/dialogs/ChangeLog
trunk/src/dialogs/dialog-analysis-tools.c
trunk/src/dialogs/moving-averages.glade
trunk/src/tools/ChangeLog
trunk/src/tools/analysis-tools.c
trunk/src/tools/analysis-tools.h
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Wed Sep 24 06:07:50 2008
@@ -16,6 +16,7 @@
* Make more dialog buttons obey no-icon request. [#302883]
* Fix and improve the sampling tool. [#552975]
* Improve moving averages tool. [#527489]
+ * Add weighted and cumulative moving averages.
Jean:
* Fix printing of rotated text. [#539734]
Modified: trunk/src/dialogs/dialog-analysis-tools.c
==============================================================================
--- trunk/src/dialogs/dialog-analysis-tools.c (original)
+++ trunk/src/dialogs/dialog-analysis-tools.c Wed Sep 24 06:07:50 2008
@@ -123,6 +123,14 @@
NULL
};
+static char const * const moving_average_group[] = {
+ "sma-button",
+ "cma-button",
+ "wma-button",
+ "spencer-ma-button",
+ NULL
+};
+
typedef struct {
@@ -188,6 +196,10 @@
GtkWidget *offset_button;
GtkWidget *offset_spin;
GtkWidget *graph_button;
+ GtkWidget *sma_button;
+ GtkWidget *cma_button;
+ GtkWidget *wma_button;
+ GtkWidget *spencer_button;
} AverageToolState;
typedef struct {
@@ -2428,6 +2440,29 @@
data->show_graph = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->graph_button));
data->df = gnumeric_glade_group_value (state->base.gui, n_group);
+
+ data->ma_type = gnumeric_glade_group_value (state->base.gui, moving_average_group);
+
+ switch (data->ma_type) {
+ case moving_average_type_sma:
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->central_button))
+ && (data->interval % 2 == 0))
+ data->ma_type = moving_average_type_central_sma;
+ break;
+ case moving_average_type_cma:
+ data->interval = 0;
+ data->offset = 0;
+ break;
+ case moving_average_type_spencer_ma:
+ data->interval = 0;
+ data->offset = 0;
+ break;
+ case moving_average_type_wma:
+ data->offset = 0;
+ break;
+ default:
+ break;
+ }
if (!cmd_analysis_tool (WORKBOOK_CONTROL (state->base.wbcg), state->base.sheet,
dao, data, analysis_tool_moving_average_engine))
@@ -2451,6 +2486,7 @@
{
int interval, err, offset;
GSList *input_range;
+ moving_average_type_t type;
input_range = gnm_expr_entry_parse_as_list (
@@ -2463,23 +2499,29 @@
} else
range_list_destroy (input_range);
- err = entry_to_int (GTK_ENTRY (state->interval_entry), &interval, FALSE);
- if (err!= 0 || interval <= 0) {
- gtk_label_set_text (GTK_LABEL (state->base.warning),
- _("The given interval is invalid."));
- gtk_widget_set_sensitive (state->base.ok_button, FALSE);
- return;
+ type = gnumeric_glade_group_value (state->base.gui, moving_average_group);
+
+ if (type == moving_average_type_sma || moving_average_type_wma) {
+ err = entry_to_int (GTK_ENTRY (state->interval_entry),
+ &interval, FALSE);
+ if (err!= 0 || interval <= 0) {
+ gtk_label_set_text (GTK_LABEL (state->base.warning),
+ _("The given interval is invalid."));
+ gtk_widget_set_sensitive (state->base.ok_button, FALSE);
+ return;
+ }
}
- err = entry_to_int (GTK_ENTRY (state->offset_spin), &offset, FALSE);
- if (err!= 0 || offset < 0 || offset > interval) {
- gtk_label_set_text (GTK_LABEL (state->base.warning),
- _("The given offset is invalid."));
- gtk_widget_set_sensitive (state->base.ok_button, FALSE);
- return;
+ if (type == moving_average_type_sma) {
+ err = entry_to_int (GTK_ENTRY (state->offset_spin), &offset, FALSE);
+ if (err!= 0 || offset < 0 || offset > interval) {
+ gtk_label_set_text (GTK_LABEL (state->base.warning),
+ _("The given offset is invalid."));
+ gtk_widget_set_sensitive (state->base.ok_button, FALSE);
+ return;
+ }
}
-
if (!gnm_dao_is_ready (GNM_DAO (state->base.gdao))) {
gtk_label_set_text (GTK_LABEL (state->base.warning),
_("The output specification "
@@ -2545,6 +2587,64 @@
}
+static void
+average_tool_sma_cb (GtkToggleButton *togglebutton, gpointer user_data)
+{
+ AverageToolState *state = (AverageToolState *)user_data;
+
+ if (!gtk_toggle_button_get_active (togglebutton))
+ return;
+
+ gtk_widget_set_sensitive (state->prior_button, TRUE);
+ gtk_widget_set_sensitive (state->central_button, TRUE);
+ gtk_widget_set_sensitive (state->offset_button, TRUE);
+ gtk_widget_set_sensitive (state->interval_entry, TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->prior_button), TRUE);
+}
+
+static void
+average_tool_cma_cb (GtkToggleButton *togglebutton, gpointer user_data)
+{
+ AverageToolState *state = (AverageToolState *)user_data;
+
+ if (!gtk_toggle_button_get_active (togglebutton))
+ return;
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->prior_button), TRUE);
+ gtk_widget_set_sensitive (state->prior_button, FALSE);
+ gtk_widget_set_sensitive (state->central_button, FALSE);
+ gtk_widget_set_sensitive (state->offset_button, FALSE);
+ gtk_widget_set_sensitive (state->interval_entry, FALSE);
+}
+
+static void
+average_tool_wma_cb (GtkToggleButton *togglebutton, gpointer user_data)
+{
+ AverageToolState *state = (AverageToolState *)user_data;
+
+ if (!gtk_toggle_button_get_active (togglebutton))
+ return;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->prior_button), TRUE);
+ gtk_widget_set_sensitive (state->prior_button, FALSE);
+ gtk_widget_set_sensitive (state->central_button, FALSE);
+ gtk_widget_set_sensitive (state->offset_button, FALSE);
+ gtk_widget_set_sensitive (state->interval_entry, TRUE);
+}
+
+static void
+average_tool_spencer_cb (GtkToggleButton *togglebutton, gpointer user_data)
+{
+ AverageToolState *state = (AverageToolState *)user_data;
+
+ if (!gtk_toggle_button_get_active (togglebutton))
+ return;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->central_button), TRUE);
+ gtk_widget_set_sensitive (state->prior_button, FALSE);
+ gtk_widget_set_sensitive (state->central_button, FALSE);
+ gtk_widget_set_sensitive (state->offset_button, FALSE);
+ gtk_widget_set_sensitive (state->interval_entry, FALSE);
+}
+
/**
* dialog_average_tool:
* @wbcg:
@@ -2592,6 +2692,11 @@
state->offset_spin = glade_xml_get_widget (state->base.gui, "offset-spinbutton");
state->show_std_errors = glade_xml_get_widget (state->base.gui, "std-errors-button");
state->graph_button = glade_xml_get_widget (state->base.gui, "graph-check");
+ state->sma_button = glade_xml_get_widget (state->base.gui, "sma-button");
+ state->cma_button = glade_xml_get_widget (state->base.gui, "cma-button");
+ state->wma_button = glade_xml_get_widget (state->base.gui, "wma-button");
+ state->spencer_button = glade_xml_get_widget (state->base.gui, "spencer-ma-button");
+
g_signal_connect_after (G_OBJECT (state->n_button),
"toggled",
@@ -2613,6 +2718,18 @@
"toggled",
G_CALLBACK (average_tool_offset_cb), state);
+ g_signal_connect_after (G_OBJECT (state->sma_button),
+ "toggled",
+ G_CALLBACK (average_tool_sma_cb), state);
+ g_signal_connect_after (G_OBJECT (state->cma_button),
+ "toggled",
+ G_CALLBACK (average_tool_cma_cb), state);
+ g_signal_connect_after (G_OBJECT (state->wma_button),
+ "toggled",
+ G_CALLBACK (average_tool_wma_cb), state);
+ g_signal_connect_after (G_OBJECT (state->spencer_button),
+ "toggled",
+ G_CALLBACK (average_tool_spencer_cb), state);
g_signal_connect_after (G_OBJECT (state->interval_entry),
Modified: trunk/src/dialogs/moving-averages.glade
==============================================================================
--- trunk/src/dialogs/moving-averages.glade (original)
+++ trunk/src/dialogs/moving-averages.glade Wed Sep 24 06:07:50 2008
@@ -34,6 +34,48 @@
<placeholder/>
</child>
<child>
+ <widget class="GtkCheckButton" id="labels_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">_Labels</property>
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Grouped by:</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="var1-label">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Input range:</property>
+ <property name="use_underline">True</property>
+ </widget>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
@@ -71,48 +113,6 @@
<property name="y_options"></property>
</packing>
</child>
- <child>
- <widget class="GtkLabel" id="var1-label">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Input range:</property>
- <property name="use_underline">True</property>
- </widget>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Grouped by:</property>
- </widget>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkCheckButton" id="labels_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">_Labels</property>
- <property name="use_underline">True</property>
- <property name="response_id">0</property>
- <property name="draw_indicator">True</property>
- </widget>
- <packing>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
</widget>
</child>
<child>
@@ -131,34 +131,23 @@
<property name="n_rows">4</property>
<property name="n_columns">1</property>
<child>
- <widget class="GtkRadioButton" id="sma-button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">Simple moving average</property>
- <property name="response_id">0</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- </widget>
- </child>
- <child>
- <widget class="GtkRadioButton" id="cma-button">
+ <widget class="GtkRadioButton" id="spencer-ma-button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Cumulative moving average</property>
+ <property name="label" translatable="yes">Spencer's 15-point moving average</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<property name="group">sma-button</property>
</widget>
<packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="wma-button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Weighted moving average</property>
<property name="response_id">0</property>
@@ -171,20 +160,29 @@
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="sma-button1">
+ <widget class="GtkRadioButton" id="cma-button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Spencer's 15-point moving average</property>
+ <property name="label" translatable="yes">Cumulative moving average</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<property name="group">sma-button</property>
</widget>
<packing>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
</packing>
</child>
+ <child>
+ <widget class="GtkRadioButton" id="sma-button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Simple moving average</property>
+ <property name="response_id">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -208,64 +206,88 @@
<widget class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<child>
- <widget class="GtkTable" id="table1">
+ <widget class="GtkTable" id="table3">
<property name="visible">True</property>
<property name="border_width">12</property>
- <property name="n_rows">3</property>
- <property name="n_columns">4</property>
+ <property name="n_rows">1</property>
+ <property name="n_columns">2</property>
<property name="column_spacing">12</property>
- <property name="row_spacing">6</property>
<child>
- <widget class="GtkLabel" id="label3">
+ <widget class="GtkEntry" id="interval-entry">
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Interval:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">interval-entry</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">*</property>
+ <property name="text" translatable="yes">3</property>
+ <property name="xalign">1</property>
</widget>
<packing>
- <property name="x_options">GTK_FILL</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkEntry" id="interval-entry">
+ <widget class="GtkLabel" id="label3">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">*</property>
- <property name="text" translatable="yes">3</property>
- <property name="xalign">1</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Interval:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">interval-entry</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkHSeparator" id="hseparator3">
+ <property name="visible">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="border_width">12</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">4</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
<child>
- <widget class="GtkCheckButton" id="std-errors-button">
+ <widget class="GtkRadioButton" id="nm2-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">_Standard errors</property>
- <property name="use_underline">True</property>
+ <property name="label" translatable="yes">nâ2</property>
<property name="response_id">0</property>
+ <property name="active">True</property>
<property name="draw_indicator">True</property>
+ <property name="group">n-button</property>
</widget>
<packing>
+ <property name="left_attach">3</property>
<property name="right_attach">4</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label7">
+ <widget class="GtkRadioButton" id="nm1-button">
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Denominator:</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">nâ1</property>
+ <property name="response_id">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">n-button</property>
</widget>
<packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
@@ -291,18 +313,12 @@
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="nm1-button">
+ <widget class="GtkLabel" id="label7">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">nâ1</property>
- <property name="response_id">0</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- <property name="group">n-button</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Denominator:</property>
</widget>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
@@ -310,23 +326,25 @@
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="nm2-button">
+ <widget class="GtkCheckButton" id="std-errors-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">nâ2</property>
+ <property name="label" translatable="yes">_Standard errors</property>
+ <property name="use_underline">True</property>
<property name="response_id">0</property>
- <property name="active">True</property>
<property name="draw_indicator">True</property>
- <property name="group">n-button</property>
</widget>
<packing>
- <property name="left_attach">3</property>
<property name="right_attach">4</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
</packing>
</child>
</widget>
+ <packing>
+ <property name="position">2</property>
+ </packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator2">
@@ -334,7 +352,7 @@
</widget>
<packing>
<property name="expand">False</property>
- <property name="position">1</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -348,25 +366,27 @@
<placeholder/>
</child>
<child>
- <widget class="GtkRadioButton" id="prior-button">
+ <widget class="GtkSpinButton" id="offset-spinbutton">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Prior moving average</property>
- <property name="response_id">0</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="xalign">1</property>
+ <property name="adjustment">0 0 100 1 10 10</property>
+ <property name="climb_rate">0.20000000000000001</property>
</widget>
<packing>
+ <property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="x_options">GTK_FILL</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="central-button">
+ <widget class="GtkRadioButton" id="offset-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Central moving average</property>
+ <property name="label" translatable="yes">Other offset</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
@@ -374,17 +394,17 @@
</widget>
<packing>
<property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="offset-button">
+ <widget class="GtkRadioButton" id="central-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Other offset</property>
+ <property name="label" translatable="yes">Central moving average</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
@@ -392,33 +412,31 @@
</widget>
<packing>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkSpinButton" id="offset-spinbutton">
+ <widget class="GtkRadioButton" id="prior-button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
- <property name="xalign">1</property>
- <property name="adjustment">0 0 100 1 10 10</property>
- <property name="climb_rate">0.20000000000000001</property>
+ <property name="label" translatable="yes">Prior moving average</property>
+ <property name="response_id">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
</widget>
<packing>
- <property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">3</property>
- <property name="position">2</property>
+ <property name="position">4</property>
</packing>
</child>
<child>
@@ -427,7 +445,7 @@
</widget>
<packing>
<property name="expand">False</property>
- <property name="position">3</property>
+ <property name="position">5</property>
</packing>
</child>
<child>
@@ -449,7 +467,7 @@
</widget>
<packing>
<property name="expand">False</property>
- <property name="position">4</property>
+ <property name="position">6</property>
</packing>
</child>
</widget>
Modified: trunk/src/tools/analysis-tools.c
==============================================================================
--- trunk/src/tools/analysis-tools.c (original)
+++ trunk/src/tools/analysis-tools.c Wed Sep 24 06:07:50 2008
@@ -3436,6 +3436,7 @@
GnmFunc *fd_offset;
GnmFunc *fd_sqrt = NULL;
GnmFunc *fd_sumxmy2 = NULL;
+ GnmFunc *fd_sumproduct = NULL;
GSList *l;
gint col = 0;
gint source;
@@ -3452,6 +3453,10 @@
fd_sumxmy2 = gnm_func_lookup ("SUMXMY2", NULL);
gnm_func_ref (fd_sumxmy2);
}
+ if (moving_average_type_wma == info->ma_type) {
+ fd_sumproduct = gnm_func_lookup ("SUMPRODUCT", NULL);
+ gnm_func_ref (fd_sumproduct);
+ }
fd_average = gnm_func_lookup ("AVERAGE", NULL);
gnm_func_ref (fd_average);
fd_offset = gnm_func_lookup ("OFFSET", NULL);
@@ -3479,9 +3484,10 @@
gint x = 0;
gint y = 0;
gint *mover;
- guint delta_x;
- guint delta_y;
- gint row;
+ guint *delta_mover;
+ guint delta_x = 1;
+ guint delta_y = 1;
+ gint row, base;
Sheet *sheet;
if (info->base.labels) {
@@ -3515,17 +3521,15 @@
case GROUPED_BY_ROW:
height = value_area_get_width (val, NULL);
mover = &x;
- delta_x = info->interval;
- delta_y = 1;
+ delta_mover = &delta_x;
break;
default:
height = value_area_get_height (val, NULL);
mover = &y;
- delta_y = info->interval;
- delta_x = 1;
+ delta_mover = &delta_y;
break;
}
-
+
sheet = val->v_range.cell.a.sheet;
expr_input = gnm_expr_new_constant (val);
@@ -3544,11 +3548,48 @@
NULL);
}
- (*mover) = 1 - info->interval + info->offset;
- for (row = 1; row <= height; row++, (*mover)++) {
- if ((*mover >= 0) && (*mover < height - info->interval + 1)) {
+ switch (info->ma_type) {
+ case moving_average_type_central_sma:
+ {
+ GnmExpr const *expr_offset_last = NULL;
+ GnmExpr const *expr_offset = NULL;
+ *delta_mover = info->interval;
+ (*mover) = 1 - info->interval + info->offset;
+ for (row = 1; row <= height; row++, (*mover)++) {
+ expr_offset_last = expr_offset;
+ expr_offset = NULL;
+ if ((*mover >= 0) && (*mover < height - info->interval + 1)) {
+ GnmExprList *list ;
+
+ list = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_int (delta_x)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (delta_y)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (x)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (y)));
+ list = gnm_expr_list_prepend (list, gnm_expr_copy (expr_input));
+ expr_offset = gnm_expr_new_funcall1 (fd_average, gnm_expr_new_funcall (fd_offset, list));
+
+ if (expr_offset_last == NULL)
+ dao_set_cell_na (dao, col, row);
+ else
+ dao_set_cell_expr (dao, col, row, gnm_expr_new_funcall2 (fd_average, expr_offset_last,
+ gnm_expr_copy (expr_offset)));
+ } else {
+ if (expr_offset_last != NULL) {
+ gnm_expr_free (expr_offset_last);
+ expr_offset_last = NULL;
+ }
+ dao_set_cell_na (dao, col, row);
+ }
+ }
+ base = info->interval - info->offset;
+ }
+ break;
+ case moving_average_type_cma:
+ for (row = 1; row <= height; row++) {
GnmExprList *list ;
GnmExpr const *expr_offset;
+
+ *delta_mover = row;
list = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_int (delta_x)));
list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (delta_y)));
@@ -3558,11 +3599,87 @@
expr_offset = gnm_expr_new_funcall (fd_offset, list);
dao_set_cell_expr (dao, col, row,
gnm_expr_new_funcall1 (fd_average, expr_offset));
+ }
+ base = 0;
+ break;
+ case moving_average_type_wma:
+ {
+ GnmExpr const *expr_row;
+ GnmExpr const *expr_divisor = gnm_expr_new_constant (value_new_int((info->interval * (info->interval + 1))/2));
+
+ if (info->base.group_by == GROUPED_BY_ROW) {
+ GnmFunc *fd_column;
+ GnmCellRef a;
+ GnmCellRef b;
+
+ fd_column = gnm_func_lookup ("COLUMN", NULL);
+ gnm_func_ref (fd_column);
+ gnm_cellref_init (&a, NULL, 0, 0, FALSE);
+ gnm_cellref_init (&b, NULL, info->interval - 1, 0, FALSE);
+ expr_row = gnm_expr_new_funcall1 (fd_column,
+ gnm_expr_new_constant (value_new_cellrange_unsafe (&a, &b)));
+ gnm_func_unref (fd_column);
} else {
- dao_set_cell_na (dao, col, row);
- if (info->std_error_flag)
- dao_set_cell_na (dao, col + 1, row);
+ GnmFunc *fd_row;
+ GnmCellRef a;
+ GnmCellRef b;
+
+ fd_row = gnm_func_lookup ("ROW", NULL);
+ gnm_func_ref (fd_row);
+ gnm_cellref_init (&a, NULL, 0, 0, FALSE);
+ gnm_cellref_init (&b, NULL, 0, info->interval - 1, FALSE);
+ expr_row = gnm_expr_new_funcall1 (fd_row,
+ gnm_expr_new_constant (value_new_cellrange_unsafe (&a, &b)));
+ gnm_func_unref (fd_row);
+ }
+
+ (*delta_mover) = info->interval;
+ (*mover) = 1 - info->interval;
+ for (row = 1; row <= height; row++, (*mover)++) {
+ if ((*mover >= 0) && (*mover < height - info->interval + 1)) {
+ GnmExprList *list ;
+ GnmExpr const *expr_offset;
+
+ list = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_int (delta_x)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (delta_y)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (x)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (y)));
+ list = gnm_expr_list_prepend (list, gnm_expr_copy (expr_input));
+ expr_offset = gnm_expr_new_funcall (fd_offset, list);
+ dao_set_cell_expr (dao, col, row,
+ gnm_expr_new_binary
+ (gnm_expr_new_funcall2 (fd_sumproduct, expr_offset, gnm_expr_copy (expr_row)),
+ GNM_EXPR_OP_DIV,
+ gnm_expr_copy (expr_divisor)));
+ } else
+ dao_set_cell_na (dao, col, row);
}
+ gnm_expr_free (expr_row);
+ gnm_expr_free (expr_divisor);
+ base = info->interval - 1;
+ }
+ break;
+ default:
+ (*delta_mover) = info->interval;
+ (*mover) = 1 - info->interval + info->offset;
+ for (row = 1; row <= height; row++, (*mover)++) {
+ if ((*mover >= 0) && (*mover < height - info->interval + 1)) {
+ GnmExprList *list ;
+ GnmExpr const *expr_offset;
+
+ list = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_int (delta_x)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (delta_y)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (x)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (y)));
+ list = gnm_expr_list_prepend (list, gnm_expr_copy (expr_input));
+ expr_offset = gnm_expr_new_funcall (fd_offset, list);
+ dao_set_cell_expr (dao, col, row,
+ gnm_expr_new_funcall1 (fd_average, expr_offset));
+ } else
+ dao_set_cell_na (dao, col, row);
+ }
+ base = info->interval - info->offset - 1;
+ break;
}
if (info->std_error_flag) {
@@ -3570,12 +3687,17 @@
dao_set_italic (dao, col, 0, col, 0);
dao_set_cell (dao, col, 0, _("Standard Error"));
- (*mover) = 1 - info->interval;
- for (row = 1; row <= height; row++, (*mover)++) {
- if ((*mover >= info->interval - info->offset - 1) && (*mover < height - info->interval + 1)) {
+ (*mover) = base;
+ for (row = 1; row <= height; row++) {
+ if (row > base && row <= height - info->offset && (row - base - info->df) > 0) {
GnmExpr const *expr_offset;
GnmExprList *list ;
+ if (info->base.group_by == GROUPED_BY_ROW)
+ delta_x = row - base;
+ else
+ delta_y = row - base;
+
list = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_int (delta_x)));
list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (delta_y)));
list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (x)));
@@ -3589,14 +3711,12 @@
(gnm_expr_new_funcall2
(fd_sumxmy2,
expr_offset,
- make_rangeref (-1, - info->interval + 1, -1, 0)),
+ make_rangeref (-1, - row + base + 1, -1, 0)),
GNM_EXPR_OP_DIV,
- gnm_expr_new_constant (value_new_int (info->interval - info->df)))));
- } else {
+ gnm_expr_new_constant (value_new_int
+ (row - base - info->df)))));
+ } else
dao_set_cell_na (dao, col, row);
- if (info->std_error_flag)
- dao_set_cell_na (dao, col, row);
- }
}
@@ -3615,6 +3735,8 @@
gnm_func_unref (fd_sqrt);
if (fd_sumxmy2 != NULL)
gnm_func_unref (fd_sumxmy2);
+ if (fd_sumproduct != NULL)
+ gnm_func_unref (fd_sumproduct);
gnm_func_unref (fd_average);
gnm_func_unref (fd_offset);
Modified: trunk/src/tools/analysis-tools.h
==============================================================================
--- trunk/src/tools/analysis-tools.h (original)
+++ trunk/src/tools/analysis-tools.h Wed Sep 24 06:07:50 2008
@@ -85,6 +85,14 @@
/************** Moving Averages **** *************/
+typedef enum {
+ moving_average_type_sma = 0,
+ moving_average_type_cma,
+ moving_average_type_wma,
+ moving_average_type_spencer_ma,
+ moving_average_type_central_sma
+} moving_average_type_t;
+
typedef struct {
analysis_tools_data_generic_t base;
int interval;
@@ -92,6 +100,7 @@
int df;
int offset;
gboolean show_graph;
+ moving_average_type_t ma_type;
} analysis_tools_data_moving_average_t;
gboolean analysis_tool_moving_average_engine (data_analysis_output_t *dao, gpointer specs,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]