Commit e38de134 authored by Richard Hestilow's avatar Richard Hestilow Committed by Rachel Hestilow

Added new statistics plugin

1998-10-02  Richard Hestilow <hestgray@ionet.net>

        * Added new statistics plugin
parent d75141a4
1998-10-02 Richard Hestilow <hestgray@ionet.net>
* Added new statistics plugin
1998-10-02 Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz>
* src/dialog-cell-format.c (apply_coloring_format): fix,
......
1998-10-02 Richard Hestilow <hestgray@ionet.net>
* Added new statistics plugin
1998-10-02 Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz>
* src/dialog-cell-format.c (apply_coloring_format): fix,
......
1998-10-02 Richard Hestilow <hestgray@ionet.net>
* Added new statistics plugin
1998-10-02 Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz>
* src/dialog-cell-format.c (apply_coloring_format): fix,
......
1998-10-02 Richard Hestilow <hestgray@ionet.net>
* Added new statistics plugin
1998-10-02 Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz>
* src/dialog-cell-format.c (apply_coloring_format): fix,
......
......@@ -91,6 +91,7 @@ plugins/Makefile
plugins/sample/Makefile
plugins/python/Makefile
plugins/perl/Makefile
plugins/stat/Makefile
intl/Makefile
po/Makefile.in
macros/Makefile
......
......@@ -11,4 +11,4 @@ else
PERL =
endif
SUBDIRS = sample $(PYTHON) $(PERL)
SUBDIRS = sample $(PYTHON) $(PERL) stat
#
# Sample Makefile for a Gnumeric plugin.
#
# Where can we find the Gnumeric include files.
#
GNUMERIC_SRC_DIR = $(srcdir)/../../src
#
# Where to install the plugin
#
plugindir = $(libdir)/gnumeric/plugins
CFLAGS += -g -Wall \
-Wshadow -Wpointer-arith \
-Wmissing-prototypes -Wmissing-declarations
plugin_LTLIBRARIES = libstat.la
libstat_la_SOURCES = stat.c stat.h
INCLUDES = \
-I$(GNUMERIC_SRC_DIR) \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-I$(includedir) \
$(GNOME_INCLUDEDIR)
/* Statistics Plugin
*
* Richard Hestilow <hestgray@ionet.net>
*/
#include "stat.h"
#include <math.h>
static char *help_stat_stdev = {
N_("@FUNCTION=STDEV\n"
"@SYNTAX = STDEV(value1, value2, ...)"
"@DESCRIPTION="
"Computes the standard deviation of all the values and cells"
" referenced in the argument list. This is equivalent to the square "
"root of the variance."
"\n"
"@SEEALSO=VARIANCE")
};
static char *help_stat_variance = {
N_("@FUNCTION=VARIANCE\n"
"@SYNTAX = VARIANCE(value1, value2, ...)"
"@DESCRIPTION="
"Computes the variation of all the values and cells referenced in the "
"argument list. This is equivalent to the sum of (value - average)^2, "
"divided by the number of values minus 1."
"@SEEALSO=AVERAGE")
};
static FunctionDefinition plugin_functions[] = {
{"stdev", "", "", &help_stat_stdev, stat_stdev, NULL },
{"variance", "", "", &help_stat_variance, stat_variance, NULL },
{ NULL, NULL },};
static int can_unload(PluginData *pd) {
Symbol *sym;
sym = symbol_lookup("stat_variance");
return sym->ref_count <= 1;
}
int init_plugin (PluginData *pd) {
install_symbols(plugin_functions);
pd->can_unload = can_unload;
pd->cleanup_plugin = cleanup_plugin;
pd->title = g_strdup("Statistics Plugin");
return 0;
}
static void cleanup_plugin (PluginData *pd) {
Symbol *sym;
unsigned int i;
g_free (pd->title);
for(i=0;i<(((sizeof(plugin_functions))/(sizeof(FunctionDefinition)))-1);i++) {
sym = symbol_lookup(plugin_functions[i].name);
if (sym)
symbol_unref(sym);
}
}
static Value *stat_variance(void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string) {
Value *result, *avg, *tmpval;
GPtrArray *values;
gpointer *pdata;
float tmp;
unsigned int i;
values = g_ptr_array_new();
result = g_new(Value, 1);
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
function_iterate_argument_values(sheet, callback_var, values,
expr_node_list, eval_col, eval_row,
error_string);
avg = function_call_with_values(sheet, "average", values->len,
values->pdata, error_string);
for(i=0;i<(values->len); i++) {
tmpval = g_ptr_array_index(values, i);
tmp = tmpval->v.v_float - value_get_as_double(avg);
tmp *= tmp;
result->v.v_float += tmp;
}
result->v.v_float /= values->len - 1;
return result;
}
static Value *stat_stdev(void *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string) {
Value *result, *var;
result = g_new(Value, 1);
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
var = stat_variance(sheet, expr_node_list, eval_col, eval_row,
error_string);
result->v.v_float = sqrt(var->v.v_float);
return result;
}
int callback_var ( Sheet *sheet, Value *value, char **error_string,
void *closure) {
GPtrArray *values = (GPtrArray *) closure;
float tmp;
tmp =value_get_as_double(value);
value->v.v_float = tmp;
value->type = VALUE_FLOAT;
g_ptr_array_add(values, g_memdup(value, sizeof(*value)));
return TRUE;
}
#ifndef GNUMERIC_STAT_H
#define GNUMERIC_STAT_H
#include <glib.h>
#include <gnome.h>
#include "../../src/gnumeric.h"
#include "../../src/func.h"
#include "../../src/plugin.h"
static Value *stat_stdev (void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string);
static Value *stat_variance(void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string);
int callback_var(Sheet *sheet, Value *value,
char **error_string, void *closure);
static void cleanup_plugin(PluginData *pd);
int init_plugin(PluginData *pd);
#endif /* GNUMERIC_STAT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment