gnumeric r16825 - in trunk: . src/dialogs src/tools
- From: guelzow svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r16825 - in trunk: . src/dialogs src/tools
- Date: Thu, 25 Sep 2008 04:49:07 +0000 (UTC)
Author: guelzow
Date: Thu Sep 25 04:49:07 2008
New Revision: 16825
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16825&view=rev
Log:
2008-09-24 Andreas J. Guelzow <aguelzow pyrshep ca>
* moving-averages.glade: enable Spencer radio button
* dialog-analysis-tools.c (average_tool_ok_clicked_cb):
set interval and offset for spencer
(average_tool_spencer_cb): set interval value
2008-09-24 Andreas J. Guelzow <aguelzow pyrshep ca>
* analysis-tools.c (analysis_tool_moving_average_engine_run): make
weighted moving averages more silient and add spencer 15 point
moving average
(analysis_tool_moving_average_funcall5): new
(analysis_tool_moving_average_weighted_av): new
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
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Thu Sep 25 04:49:07 2008
@@ -17,6 +17,7 @@
* Fix and improve the sampling tool. [#552975]
* Improve moving averages tool. [#527489]
* Add weighted and cumulative moving averages.
+ * Add Spencer's 15-point moving average.
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 Thu Sep 25 04:49:07 2008
@@ -2454,8 +2454,8 @@
data->offset = 0;
break;
case moving_average_type_spencer_ma:
- data->interval = 0;
- data->offset = 0;
+ data->interval = 15;
+ data->offset = 7;
break;
case moving_average_type_wma:
data->offset = 0;
@@ -2638,6 +2638,7 @@
if (!gtk_toggle_button_get_active (togglebutton))
return;
+ int_to_entry (GTK_ENTRY (state->interval_entry), 15);
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);
Modified: trunk/src/dialogs/moving-averages.glade
==============================================================================
--- trunk/src/dialogs/moving-averages.glade (original)
+++ trunk/src/dialogs/moving-averages.glade Thu Sep 25 04:49:07 2008
@@ -34,48 +34,6 @@
<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>
@@ -113,6 +71,48 @@
<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,57 +131,56 @@
<property name="n_rows">4</property>
<property name="n_columns">1</property>
<child>
- <widget class="GtkRadioButton" id="spencer-ma-button">
+ <widget class="GtkRadioButton" id="sma-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">Simple moving average</property>
<property name="response_id">0</property>
+ <property name="active">True</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>
- </packing>
</child>
<child>
- <widget class="GtkRadioButton" id="wma-button">
+ <widget class="GtkRadioButton" id="cma-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Weighted 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">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="cma-button">
+ <widget class="GtkRadioButton" id="wma-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Cumulative moving average</property>
+ <property name="label" translatable="yes">Weighted 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">2</property>
+ <property name="bottom_attach">3</property>
</packing>
</child>
<child>
- <widget class="GtkRadioButton" id="sma-button">
+ <widget class="GtkRadioButton" id="spencer-ma-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Simple moving average</property>
+ <property name="label" translatable="yes">Spencer's 15-point moving average</property>
<property name="response_id">0</property>
- <property name="active">True</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>
+ </packing>
</child>
</widget>
<packing>
@@ -213,29 +212,29 @@
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<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">2</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<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>
@@ -259,35 +258,28 @@
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<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>
<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>
@@ -313,12 +305,18 @@
</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>
@@ -326,19 +324,20 @@
</packing>
</child>
<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="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>
</widget>
@@ -366,27 +365,25 @@
<placeholder/>
</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>
<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>
@@ -394,17 +391,17 @@
</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="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>
@@ -412,24 +409,26 @@
</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="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>
Modified: trunk/src/tools/analysis-tools.c
==============================================================================
--- trunk/src/tools/analysis-tools.c (original)
+++ trunk/src/tools/analysis-tools.c Thu Sep 25 04:49:07 2008
@@ -3426,6 +3426,40 @@
*
**/
+static GnmExpr const *
+analysis_tool_moving_average_funcall5 (GnmFunc *fd, GnmExpr const *ex, int y, int x, int dy, int dx)
+{
+ GnmExprList *list;
+ list = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_int (dx)));
+ list = gnm_expr_list_prepend (list, gnm_expr_new_constant (value_new_int (dy)));
+ 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 (ex));
+
+ return gnm_expr_new_funcall (fd, list);
+}
+
+static GnmExpr const *
+analysis_tool_moving_average_weighted_av (GnmFunc *fd_sum, GnmFunc *fd_in, GnmExpr const *ex,
+ int y, int x, int dy, int dx, int *w)
+{
+ GnmExprList *list = NULL;
+
+ while (*w != 0) {
+ list = gnm_expr_list_prepend
+ (list, gnm_expr_new_binary
+ (gnm_expr_new_constant (value_new_int (*w)),
+ GNM_EXPR_OP_MULT,
+ gnm_expr_new_funcall3 (fd_in, gnm_expr_copy (ex),
+ gnm_expr_new_constant (value_new_int (y)),
+ gnm_expr_new_constant (value_new_int (x)))));
+ w++;
+ x += dx;
+ y += dy;
+ }
+
+ return gnm_expr_new_funcall (fd_sum, list);
+}
static gboolean
analysis_tool_moving_average_engine_run (data_analysis_output_t *dao,
@@ -3436,7 +3470,7 @@
GnmFunc *fd_offset;
GnmFunc *fd_sqrt = NULL;
GnmFunc *fd_sumxmy2 = NULL;
- GnmFunc *fd_sumproduct = NULL;
+ GnmFunc *fd_sum = NULL;
GSList *l;
gint col = 0;
gint source;
@@ -3453,9 +3487,9 @@
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);
+ if (moving_average_type_wma == info->ma_type || moving_average_type_spencer_ma == info->ma_type) {
+ fd_sum = gnm_func_lookup ("SUM", NULL);
+ gnm_func_ref (fd_sum);
}
fd_average = gnm_func_lookup ("AVERAGE", NULL);
gnm_func_ref (fd_average);
@@ -3559,20 +3593,16 @@
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));
+ expr_offset = gnm_expr_new_funcall1
+ (fd_average, analysis_tool_moving_average_funcall5
+ (fd_offset,expr_input, y, x, delta_y, delta_x));
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)));
+ 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);
@@ -3586,17 +3616,13 @@
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)));
- 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);
+ expr_offset = analysis_tool_moving_average_funcall5
+ (fd_offset, expr_input, y, x, delta_y, delta_x);
+
dao_set_cell_expr (dao, col, row,
gnm_expr_new_funcall1 (fd_average, expr_offset));
}
@@ -3604,59 +3630,70 @@
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));
+ GnmExpr const *expr_divisor = gnm_expr_new_constant
+ (value_new_int((info->interval * (info->interval + 1))/2));
+ int *w = g_new (int, (info->interval + 1));
+ int i;
- 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 {
- 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;
+ for (i = 0; i < info->interval; i++)
+ w[i] = i+1;
+ w[info->interval] = 0;
+
+ delta_x = 0;
+ delta_y= 0;
+ (*delta_mover) = 1;
(*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;
+ GnmExpr const *expr_sum;
+
+ expr_sum = analysis_tool_moving_average_weighted_av
+ (fd_sum, fd_index, expr_input, y+1, x+1, delta_y, delta_x, w);
- 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)),
+ (expr_sum,
GNM_EXPR_OP_DIV,
gnm_expr_copy (expr_divisor)));
} else
dao_set_cell_na (dao, col, row);
}
- gnm_expr_free (expr_row);
+ g_free (w);
gnm_expr_free (expr_divisor);
base = info->interval - 1;
+ delta_x = 1;
+ delta_y= 1;
+ }
+ break;
+ case moving_average_type_spencer_ma:
+ {
+ GnmExpr const *expr_divisor = gnm_expr_new_constant
+ (value_new_int(-3-6-5+3+21+45+67+74+67+46+21+3-5-6-3));
+ int w[] = {-3, -6, -5, 3, 21, 45, 67, 74, 67, 46, 21, 3, -5, -6, -3, 0};
+
+ delta_x = 0;
+ delta_y= 0;
+ (*delta_mover) = 1;
+ (*mover) = 1 - info->interval + info->offset;
+ for (row = 1; row <= height; row++, (*mover)++) {
+ if ((*mover >= 0) && (*mover < height - info->interval + 1)) {
+ GnmExpr const *expr_sum;
+
+ expr_sum = analysis_tool_moving_average_weighted_av
+ (fd_sum, fd_index, expr_input, y+1, x+1, delta_y, delta_x, w);
+
+ dao_set_cell_expr (dao, col, row,
+ gnm_expr_new_binary
+ (expr_sum,
+ GNM_EXPR_OP_DIV,
+ gnm_expr_copy (expr_divisor)));
+ } else
+ dao_set_cell_na (dao, col, row);
+ }
+ gnm_expr_free (expr_divisor);
+ base = info->interval - info->offset - 1;
+ delta_x = 1;
+ delta_y= 1;
}
break;
default:
@@ -3664,15 +3701,10 @@
(*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);
+ expr_offset = analysis_tool_moving_average_funcall5
+ (fd_offset, expr_input, y, x, delta_y, delta_x);
dao_set_cell_expr (dao, col, row,
gnm_expr_new_funcall1 (fd_average, expr_offset));
} else
@@ -3691,19 +3723,14 @@
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)));
- 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);
+ expr_offset = analysis_tool_moving_average_funcall5
+ (fd_offset, expr_input, y, x, delta_y, delta_x);
dao_set_cell_expr (dao, col, row,
gnm_expr_new_funcall1
(fd_sqrt,
@@ -3718,9 +3745,6 @@
} else
dao_set_cell_na (dao, col, row);
}
-
-
-
}
gnm_expr_free (expr_input);
@@ -3735,8 +3759,8 @@
gnm_func_unref (fd_sqrt);
if (fd_sumxmy2 != NULL)
gnm_func_unref (fd_sumxmy2);
- if (fd_sumproduct != NULL)
- gnm_func_unref (fd_sumproduct);
+ if (fd_sum != NULL)
+ gnm_func_unref (fd_sum);
gnm_func_unref (fd_average);
gnm_func_unref (fd_offset);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]