GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 275dc86f authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Implemented `Histogram' tool (mostly).

2000-07-03  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/analysis-tools.c: Implemented `Histogram' tool (mostly).

	* src/dialogs/tools.h: Related changes.

	* src/dialogs/analysis-tools.glade,
	src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
	and `Fourier Analysis' tools.  The later is not implemented yet.
parent 7dc4e081
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
......@@ -6,7 +6,7 @@ Jody:
Jukka:
* Started the implementation of `Anova: Two-Factor With Replication'
data analysis tool
and `Histogram' data analysis tools
* Implemented COUPNUM and started COUPDAYS.
* Implemented TRUE and FALSE logical functions.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
......
......@@ -37,12 +37,11 @@ Gnumeric Spread Sheet task list
* CELL, COUPDAYS, and DURATION
* Data Analysis Tools
* Finish `Anova: Two-Factor With Replication'
* Finish `Anova: Two-Factor With Replication' and `Histogram' tools
* Implement `Patterned distribution' for `Random Number Generation'
* Implement new tools:
- `Exponential Smoothing'
- `Fourier Analysis'
- `Histogram'
- `Fourier Analysis' (the dialog is implemented)
* Finish the documentation
* Printing
......
......@@ -234,7 +234,7 @@ coupnum(GDate *settlement, GDate *maturity, int freq, int basis)
+ (g_date_is_leap_year (sy) && sd==28 && sm==2);
if (freq == 1)
return years + (months > 0 || days > 0);
return years + (months > 0) + (months == 0 && days > 0);
else if (freq == 2)
return years*2
+ (months > 6) + (months == 6 && days > 0)
......
......@@ -131,14 +131,16 @@ set_cell_na (data_analysis_output_t *dao, int col, int row)
}
static void
/* Returns 1 if non-numeric data was found, 0 otherwise.
*/
static int
get_data (Sheet *sheet, Range *range, data_set_t *data)
{
gpointer p;
Cell *cell;
Value *v;
float_t x;
int row, col;
int row, col, status = 0;
data->sum = 0;
data->sum2 = 0;
......@@ -153,8 +155,10 @@ get_data (Sheet *sheet, Range *range, data_set_t *data)
v = cell->value;
if (VALUE_IS_NUMBER (v))
x = value_get_as_float (v);
else
else {
x = 0;
status = 1;
}
p = g_new (float_t, 1);
* ((float_t *) p) = x;
......@@ -171,10 +175,13 @@ get_data (Sheet *sheet, Range *range, data_set_t *data)
data->max = x;
}
data->n++;
}
} else
status = 1;
}
data->sum2 = data->sum * data->sum;
return status;
}
static void
......@@ -335,6 +342,7 @@ set_italic (data_analysis_output_t *dao, int col1, int row1,
sheet_style_attach (dao->sheet, range, mstyle);
}
/************* Correlation Tool *******************************************
*
* The correlation tool calculates the correlation coefficient of two
......@@ -489,8 +497,7 @@ correlation_tool (Workbook *wb, Sheet *sheet,
return 0;
}
/************* Covariance Tool ********************************************
*
* The covariance tool calculates the covariance of two data sets.
......@@ -640,7 +647,7 @@ covariance_tool (Workbook *wb, Sheet *sheet,
return 0;
}
/************* Descriptive Statistics Tool *******************************
*
* Descriptive Statistics Tool calculates some useful statistical
......@@ -932,8 +939,7 @@ descriptive_stat_tool (Workbook *wb, Sheet *current_sheet,
return 0;
}
/************* Sampling Tool *********************************************
*
* Sampling tool takes a sample from a given data set. Sample can be
......@@ -1044,8 +1050,7 @@ int sampling_tool (Workbook *wb, Sheet *sheet, Range *input_range,
return 0;
}
/************* z-Test: Two Sample for Means ******************************
*
* The results are given in a table which can be printed out in a new
......@@ -1143,7 +1148,7 @@ int ztest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
return 0;
}
/************* t-Test Tools ********************************************
*
* The t-Test tool set consists of three kinds of tests to test the
......@@ -1155,8 +1160,6 @@ int ztest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
*
**/
/* t-Test: Paired Two Sample for Means.
*/
int
......@@ -1530,7 +1533,7 @@ ttest_neq_var_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
return 0;
}
/************* F-Test Tool *********************************************
*
* The results are given in a table which can be printed out in a new
......@@ -1638,8 +1641,7 @@ ftest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
return 0;
}
/************* Random Number Generation Tool ******************************
*
* The results are given in a table which can be printed out in a new
......@@ -1801,8 +1803,7 @@ int random_tool (Workbook *wb, Sheet *sheet, int vars, int count,
return 0;
}
/************* Regression Tool *********************************************
*
* The results are given in a table which can be printed out in a new
......@@ -2084,7 +2085,7 @@ these values can be tiny.*/
return 0;
}
/************* Moving Average Tool *****************************************
*
* The moving average tool calculates moving averages of given data
......@@ -2145,7 +2146,7 @@ int average_tool (Workbook *wb, Sheet *sheet, Range *range, int interval,
return 0;
}
/************* Rank and Percentile Tool ************************************
*
* The results are given in a table which can be printed out in a new
......@@ -2291,7 +2292,7 @@ int ranking_tool (Workbook *wb, Sheet *sheet, Range *input_range,
return 0;
}
/************* Anova: Single Factor Tool **********************************
*
* The results are given in a table which can be printed out in a new
......@@ -2457,7 +2458,7 @@ int anova_single_factor_tool (Workbook *wb, Sheet *sheet, Range *range,
return 0;
}
/************* Anova: Two-Factor Without Replication Tool ****************
*
* The results are given in a table which can be printed out in a new
......@@ -2612,6 +2613,7 @@ int anova_two_factor_without_r_tool (Workbook *wb, Sheet *sheet, Range *range,
return 0;
}
/************* Anova: Two-Factor With Replication Tool *******************
*
* The results are given in a table which can be printed out in a new
......@@ -2765,3 +2767,89 @@ int anova_two_factor_with_r_tool (Workbook *wb, Sheet *sheet, Range *range,
return 0;
}
/************* Histogram Tool *********************************************
*
* The results are given in a table which can be printed out in a new
* sheet, in a new workbook, or simply into an existing sheet.
*
**/
int histogram_tool (Workbook *wb, Sheet *sheet, Range *range, Range *bin_range,
gboolean labels, gboolean sorted, gboolean percentage,
gboolean chart, data_analysis_output_t *dao)
{
data_set_t bin_set, set;
GSList *list;
int i, j, cols, rows, cum_sum;
float_t *intval;
int *count;
cols = bin_range->end.col - bin_range->start.col + 1;
rows = bin_range->end.row - bin_range->start.row + 1;
if (get_data (sheet, range, &set)) {
free_data_set (&set);
return 1;
}
if (get_data (sheet, bin_range, &bin_set)) {
free_data_set (&set);
free_data_set (&bin_set);
return 2;
}
bin_set.array = g_slist_sort (bin_set.array,
(GCompareFunc) float_compare);
prepare_output (wb, dao, _("Histogram"));
i = 1;
set_cell (dao, 0, 0, _("Bin"));
set_cell (dao, 1, 0, _("Frequency"));
if (percentage)
set_cell (dao, ++i, 0, _("Cumulative %"));
set_italic (dao, 0, 0, i, 0);
count = g_new (int, bin_set.n+1);
intval = g_new (float_t, bin_set.n);
list = bin_set.array;
for (i=0; i<bin_set.n; i++) {
float_t x = *((float_t *) list->data);
set_cell_float (dao, 0, i+1, x);
intval[i] = x;
count[i] = 0;
list = list->next;
}
set_cell (dao, 0, i+1, "More");
count[i] = 0;
list = set.array;
for (i=0; i<set.n; i++) {
float_t x = *((float_t *) list->data);
/* FIXME: Slow!, O(n^2) */
for (j=0; j<bin_set.n; j++)
if (x <= intval[j]) {
count[j]++;
goto next;
}
count[j]++;
next:
list = list->next;
}
cum_sum = 0;
for (i=0; i<=bin_set.n; i++) {
set_cell_int (dao, 1, i+1, count[i]);
cum_sum += count[i];
if (percentage)
set_cell_float (dao, 2, i+1,
(float_t) cum_sum / set.n);
}
free_data_set (&set);
free_data_set (&bin_set);
return 0;
}
......@@ -3396,9 +3396,9 @@
<widget>
<class>GnomeDialog</class>
<name>Correlation</name>
<name>FourierAnalysis</name>
<visible>False</visible>
<title>Correlation</title>
<title>Fourier Analysis</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
......@@ -3433,7 +3433,7 @@
<widget>
<class>GtkFrame</class>
<name>frame13</name>
<name>frame7</name>
<label>Input</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
......@@ -3445,44 +3445,17 @@
<widget>
<class>GtkTable</class>
<name>table17</name>
<name>table7</name>
<border_width>4</border_width>
<rows>4</rows>
<rows>3</rows>
<columns>2</columns>
<homogeneous>False</homogeneous>
<row_spacing>0</row_spacing>
<column_spacing>4</column_spacing>
<widget>
<class>GtkLabel</class>
<name>label60</name>
<label>_Input Range:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<default_focus_target>corr_entry1</default_focus_target>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>False</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>corr_entry1</name>
<name>fa_entry1</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
......@@ -3504,71 +3477,21 @@
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label61</name>
<label>Grouped by:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkCheckButton</class>
<name>corr_checkbutton</name>
<name>fa_checkbutton</name>
<can_focus>True</can_focus>
<label>_Labels</label>
<label>_Labels in First Row</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<left_attach>0</left_attach>
<right_attach>2</right_attach>
<top_attach>3</top_attach>
<bottom_attach>4</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkRadioButton</class>
<name>corr_radiobutton2</name>
<can_focus>True</can_focus>
<label>_Rows</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>corr_group</group>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
......@@ -3578,18 +3501,21 @@
</widget>
<widget>
<class>GtkRadioButton</class>
<name>corr_radiobutton1</name>
<can_focus>True</can_focus>
<label>_Columns</label>
<active>True</active>
<draw_indicator>True</draw_indicator>
<group>corr_group</group>
<class>GtkLabel</class>
<name>label19</name>
<label>_Input Range:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>4</xpad>
<ypad>0</ypad>
<default_focus_target>fa_entry1</default_focus_target>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
......@@ -3603,6 +3529,20 @@
</widget>
</widget>
<widget>
<class>GtkCheckButton</class>
<name>fa_checkbutton2</name>
<can_focus>True</can_focus>
<label>I_nverse</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame2</name>
......@@ -3626,45 +3566,45 @@
<column_spacing>0</column_spacing>
<widget>
<class>GtkRadioButton</class>
<name>corr_radiobutton5</name>
<class>GtkEntry</class>
<name>fa_output_range_entry</name>
<can_focus>True</can_focus>
<label>_Output Range:</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>corr_output</group>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>False</xfill>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>corr_output_range_entry</name>
<class>GtkRadioButton</class>
<name>fa_radiobutton5</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<label>_Output Range:</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>fa_output</group>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
......@@ -3675,12 +3615,12 @@
<widget>
<class>GtkRadioButton</class>
<name>corr_radiobutton4</name>
<name>fa_radiobutton4</name>
<can_focus>True</can_focus>
<label>N_ew Workbook</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>corr_output</group>
<group>fa_output</group>
<child>
<left_attach>0</left_attach>
<right_attach>2</right_attach>
......@@ -3699,13 +3639,13 @@
<widget>
<class>GtkRadioButton</class>
<name>corr_radiobutton3</name>
<name>fa_radiobutton3</name>
<has_default>True</has_default>
<can_focus>True</can_focus>
<label>_New Sheet</label>
<active>True</active>
<draw_indicator>True</draw_indicator>
<group>corr_output</group>
<group>fa_output</group>
<child>
<left_attach>0</left_attach>
<right_attach>2</right_attach>
......@@ -3764,9 +3704,9 @@
<widget>
<class>GnomeDialog</class>
<name>Covariance</name>
<name>Correlation</name>
<visible>False</visible>
<title>Covariance</title>
<title>Correlation</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
......@@ -3831,7 +3771,7 @@
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>