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;
}
This diff is collapsed.
......@@ -32,6 +32,8 @@ static int dialog_ttest_eq_tool (Workbook *wb, Sheet *sheet);
static int dialog_ttest_neq_tool (Workbook *wb, Sheet *sheet);
static int dialog_ftest_tool (Workbook *wb, Sheet *sheet);
static int dialog_average_tool (Workbook *wb, Sheet *sheet);
static int dialog_fourier_tool (Workbook *wb, Sheet *sheet);
static int dialog_histogram_tool (Workbook *wb, Sheet *sheet);
static int dialog_random_tool (Workbook *wb, Sheet *sheet);
static int dialog_regression_tool (Workbook *wb, Sheet *sheet);
static int dialog_anova_single_factor_tool (Workbook *wb, Sheet *sheet);
......@@ -88,6 +90,10 @@ static tool_list_t tools[] = {
dialog_descriptive_stat_tool },
{ N_("F-Test: Two-Sample for Variances"),
dialog_ftest_tool },
{ N_("Fourier Analysis"),
dialog_fourier_tool },
{ N_("Histogram"),
dialog_histogram_tool },
{ N_("Moving Average"),
dialog_average_tool },
{ N_("Random Number Generation"),
......@@ -589,7 +595,8 @@ dialog_correlation_tool (Workbook *wb, Sheet *sheet)
int group, selection, x1, x2, y1, y2;
Range range;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -1122,7 +1129,8 @@ dialog_ttest_paired_tool (Workbook *wb, Sheet *sheet)
int selection, x1, x2, y1, y2;
Range range_input1, range_input2;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -1255,7 +1263,8 @@ dialog_ttest_eq_tool (Workbook *wb, Sheet *sheet)
int selection, x1, x2, y1, y2;
Range range_input1, range_input2;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -1388,7 +1397,8 @@ dialog_ttest_neq_tool (Workbook *wb, Sheet *sheet)
int selection, x1, x2, y1, y2;
Range range_input1, range_input2;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -1521,7 +1531,8 @@ dialog_ftest_tool (Workbook *wb, Sheet *sheet)
int selection, x1, x2, y1, y2;
Range range_input1, range_input2;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -1784,7 +1795,8 @@ dialog_random_tool (Workbook *wb, Sheet *sheet)
int selection, x1, x2, y1, y2;
int i, dist_str_no;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -2087,7 +2099,6 @@ dialog_loop:
}
static int
dialog_average_tool (Workbook *wb, Sheet *sheet)
{
......@@ -2108,7 +2119,8 @@ dialog_average_tool (Workbook *wb, Sheet *sheet)
int selection, x1, x2, y1, y2;
Range range;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb), "analysis-tools.glade");
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
......@@ -2204,6 +2216,257 @@ dialog_loop:
return 0;
}
static int
dialog_fourier_tool (Workbook *wb, Sheet *sheet)
{
GladeXML *gui;
GtkWidget *range_entry;
GtkWidget *dialog;
GtkWidget *checkbutton;
GtkWidget *checkbutton2;
GtkWidget *output_range_entry;
data_analysis_output_t dao;
gboolean labels = FALSE;
gboolean standard_errors_flag = FALSE;
char *text;
int selection, x1, x2, y1, y2;
Range range;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
dao.type = NewSheetOutput;
dialog = glade_xml_get_widget (gui, "FourierAnalysis");
range_entry = glade_xml_get_widget (gui, "fa_entry1");
checkbutton = glade_xml_get_widget (gui, "fa_checkbutton");
checkbutton2 = glade_xml_get_widget (gui, "fa_checkbutton2");
output_range_entry
= glade_xml_get_widget (gui, "fa_output_range_entry");
if (!dialog || !range_entry || !output_range_entry || !checkbutton ||
!checkbutton2) {
printf ("Corrupt file analysis-tools.glade\n");
return 0;
}
gnome_dialog_editable_enters (GNOME_DIALOG (dialog),
GTK_EDITABLE (range_entry));
gnome_dialog_editable_enters (GNOME_DIALOG (dialog),
GTK_EDITABLE (output_range_entry));
if (set_output_option_signals (gui, &dao, "fa"))
return 0;
gtk_signal_connect (GTK_OBJECT (checkbutton), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled), &labels);
gtk_signal_connect (GTK_OBJECT (checkbutton2), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled),
&standard_errors_flag);
gtk_widget_grab_focus (range_entry);
dialog_loop:
selection = gnumeric_dialog_run (wb, GNOME_DIALOG (dialog));
if (selection == -1) {
gtk_object_unref (GTK_OBJECT (gui));
return 1;
}
if (selection != 0) {
gtk_object_destroy (GTK_OBJECT (dialog));
return 1;
}
text = gtk_entry_get_text (GTK_ENTRY (range_entry));
if (!parse_range (text, &range.start.col,
&range.start.row,
&range.end.col,
&range.end.row)) {
error_in_entry(wb, range_entry,
_("You should introduce a valid cell range "
"in 'Range:'"));
goto dialog_loop;
}
dao.labels_flag = labels;
if (dao.type == RangeOutput) {
text = gtk_entry_get_text (GTK_ENTRY (output_range_entry));
if (!parse_range (text, &x1, &y1, &x2, &y2)) {
error_in_entry(wb, output_range_entry,
_("You should introduce a valid cell "
"range in 'Output Range:'"));
goto dialog_loop;
} else {
dao.start_col = x1;
dao.start_row = y1;
dao.cols = x2-x1+1;
dao.rows = y2-y1+1;
dao.sheet = sheet;
}
}
error_in_entry(wb, output_range_entry,
_("Fourier analysis is not implemented yet. Sorry."));
workbook_focus_sheet(sheet);
gtk_object_destroy (GTK_OBJECT (dialog));
gtk_object_unref (GTK_OBJECT (gui));
return 0;
}
static int
dialog_histogram_tool (Workbook *wb, Sheet *sheet)
{
GladeXML *gui;
GtkWidget *range1_entry, *range2_entry;
GtkWidget *dialog;
GtkWidget *checkbutton;
GtkWidget *sorted_cb, *percentage_cb, *chart_cb;
GtkWidget *output_range_entry;
data_analysis_output_t dao;
gboolean labels = FALSE;
gboolean sorted = FALSE;
gboolean percentage = FALSE;
gboolean chart = FALSE;
char *text;
int selection, x1, x2, y1, y2, err;
Range range_input1, range_input2;
gui = gnumeric_glade_xml_new (workbook_command_context_gui (wb),
"analysis-tools.glade");
if (gui == NULL)
return 0;
dao.type = NewSheetOutput;
dialog = glade_xml_get_widget (gui, "Histogram");
range1_entry = glade_xml_get_widget (gui, "hist_entry1");
range2_entry = glade_xml_get_widget (gui, "hist_entry2");
checkbutton = glade_xml_get_widget (gui, "hist_checkbutton");
sorted_cb = glade_xml_get_widget (gui, "hist_checkbutton2");
percentage_cb = glade_xml_get_widget (gui, "hist_checkbutton3");
chart_cb = glade_xml_get_widget (gui, "hist_checkbutton4");
output_range_entry
= glade_xml_get_widget (gui, "hist_output_range_entry");
if (!dialog || !range1_entry || !range2_entry ||
!output_range_entry || !checkbutton || !sorted_cb ||
!percentage_cb || !chart_cb) {
printf ("Corrupt file analysis-tools.glade\n");
return 0;
}
gnome_dialog_editable_enters (GNOME_DIALOG (dialog),
GTK_EDITABLE (range1_entry));
gnome_dialog_editable_enters (GNOME_DIALOG (dialog),
GTK_EDITABLE (range2_entry));
gnome_dialog_editable_enters (GNOME_DIALOG (dialog),
GTK_EDITABLE (output_range_entry));
if (set_output_option_signals (gui, &dao, "hist"))
return 0;
gtk_signal_connect (GTK_OBJECT (checkbutton), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled), &labels);
gtk_signal_connect (GTK_OBJECT (sorted_cb), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled), &sorted);
gtk_signal_connect (GTK_OBJECT (percentage_cb), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled),
&percentage);
gtk_signal_connect (GTK_OBJECT (chart_cb), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled), &chart);
gtk_widget_grab_focus (range1_entry);
dialog_loop:
selection = gnumeric_dialog_run (wb, GNOME_DIALOG (dialog));
if (selection == -1) {
gtk_object_unref (GTK_OBJECT (gui));
return 1;
}
if (selection != 0) {
gtk_object_destroy (GTK_OBJECT (dialog));
return 1;
}
text = gtk_entry_get_text (GTK_ENTRY (range1_entry));
if (!parse_range (text, &range_input1.start.col,
&range_input1.start.row,
&range_input1.end.col,
&range_input1.end.row)) {
error_in_entry(wb, range1_entry,
_("You should introduce a valid cell range "
"in 'Input Range:'"));
goto dialog_loop;
}
text = gtk_entry_get_text (GTK_ENTRY (range2_entry));
if (!parse_range (text, &range_input2.start.col,
&range_input2.start.row,
&range_input2.end.col,
&range_input2.end.row)) {
error_in_entry(wb, range2_entry,
_("You should introduce a valid cell range "
"in 'Bin Range:'"));
goto dialog_loop;
}
if (dao.type == RangeOutput) {
text = gtk_entry_get_text (GTK_ENTRY (output_range_entry));
if (!parse_range (text, &x1, &y1, &x2, &y2)) {
error_in_entry(wb, output_range_entry,
_("You should introduce a valid cell "
"range in 'Output Range:'"));
goto dialog_loop;
} else {
dao.start_col = x1;
dao.start_row = y1;
dao.cols = x2-x1+1;
dao.rows = y2-y1+1;
dao.sheet = sheet;
}
}
dao.labels_flag = labels;
err = histogram_tool (wb, sheet, &range_input1, &range_input2,
labels, sorted, percentage, chart, &dao);
if (err == 1) {
error_in_entry(wb, range1_entry,
_("Given input range contains non-numeric "
"data. "));
goto dialog_loop;
} else if (err == 2) {
error_in_entry(wb, range2_entry,
_("Given bin range contains non-numeric data."));
goto dialog_loop;
}<