[goffice] Protect against missing data in trend lines. [#742859]
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Protect against missing data in trend lines. [#742859]
- Date: Wed, 14 Jan 2015 11:10:47 +0000 (UTC)
commit a7a6855b7711fbd4631f056cce47da634d3f898c
Author: Jean Brefort <jean brefort normalesup org>
Date: Wed Jan 14 12:10:09 2015 +0100
Protect against missing data in trend lines. [#742859]
ChangeLog | 7 ++++
plugins/reg_linear/gog-lin-reg.c | 2 +-
plugins/reg_logfit/gog-logfit.c | 66 +++++++++++++++++++----------------
plugins/smoothing/gog-moving-avg.c | 2 +-
4 files changed, 45 insertions(+), 32 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2224401..1e1e72c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-14 Jean Brefort <jean brefort normalesup org>
+
+ * plugins/reg_linear/gog-lin-reg.c (gog_lin_reg_curve_update): protect
+ against missing data. [#742859]
+ * plugins/reg_logfit/gog-logfit.c (gog_log_fit_curve_update): ditto.
+ * plugins/smoothing/gog-moving-avg.c (gog_moving_avg_update): ditto.
+
2015-01-11 Jean Brefort <jean brefort normalesup org>
* libgoffice.pc.in: add missing libraries to Requires.private.
diff --git a/plugins/reg_linear/gog-lin-reg.c b/plugins/reg_linear/gog-lin-reg.c
index b72a217..7feb6c3 100644
--- a/plugins/reg_linear/gog-lin-reg.c
+++ b/plugins/reg_linear/gog-lin-reg.c
@@ -60,7 +60,7 @@ gog_lin_reg_curve_update (GogObject *obj)
return;
nb = gog_series_get_xy_data (series, &x_vals, &y_vals);
- used = (GOG_LIN_REG_CURVE_GET_CLASS(rc))->build_values (rc, x_vals, y_vals, nb);
+ used = (y_vals)? (GOG_LIN_REG_CURVE_GET_CLASS(rc))->build_values (rc, x_vals, y_vals, nb): 0;
if (used > 1) {
go_regression_stat_t *stats = go_regression_stat_new ();
GORegressionResult res =
diff --git a/plugins/reg_logfit/gog-logfit.c b/plugins/reg_logfit/gog-logfit.c
index 891c74c..bfe64c7 100644
--- a/plugins/reg_logfit/gog-logfit.c
+++ b/plugins/reg_logfit/gog-logfit.c
@@ -39,45 +39,51 @@ gog_log_fit_curve_update (GogObject *obj)
GogSeries *series = GOG_SERIES (obj->parent);
double const *y_vals, *x_vals = NULL;
double *tx_vals, *ty_vals, x, y;
- int i, used, nb;
+ int i, used = 0, nb;
double xmin, xmax;
g_return_if_fail (gog_series_is_valid (series));
nb = gog_series_get_xy_data (series, &x_vals, &y_vals);
- gog_reg_curve_get_bounds (rc, &xmin, &xmax);
- tx_vals = g_new (double, nb);
- ty_vals = g_new (double, nb);
- for (i = 0, used = 0; i < nb; i++) {
- x = (x_vals)? x_vals[i]: i;
- y = y_vals[i];
- if (!go_finite (x) || !go_finite (y)) {
- if (rc->skip_invalid)
+ if (nb > 0) {
+ gog_reg_curve_get_bounds (rc, &xmin, &xmax);
+ tx_vals = g_new (double, nb);
+ ty_vals = g_new (double, nb);
+ for (i = 0, used = 0; i < nb; i++) {
+ x = (x_vals)? x_vals[i]: i;
+ y = y_vals[i];
+ if (!go_finite (x) || !go_finite (y)) {
+ if (rc->skip_invalid)
+ continue;
+ used = 0;
+ break;
+ }
+ if (x < xmin || x > xmax)
continue;
- used = 0;
- break;
+ tx_vals[used] = x;
+ ty_vals[used] = y;
+ used++;
}
- if (x < xmin || x > xmax)
- continue;
- tx_vals[used] = x;
- ty_vals[used] = y;
- used++;
- }
- if (used > 4) {
- GORegressionResult res = go_logarithmic_fit (tx_vals, ty_vals,
- used, rc->a);
- if (res == GO_REG_ok) {
- go_range_devsq (ty_vals, used, &x);
- rc->R2 = (x - rc->a[4]) / x;
- } else for (nb = 0; nb < 5; nb++)
- rc->a[nb] = go_nan;
+ if (used > 4) {
+ GORegressionResult res = go_logarithmic_fit (tx_vals, ty_vals,
+ used, rc->a);
+ if (res == GO_REG_ok) {
+ go_range_devsq (ty_vals, used, &x);
+ rc->R2 = (x - rc->a[4]) / x;
+ } else for (nb = 0; nb < 5; nb++)
+ rc->a[nb] = go_nan;
+ } else {
+ rc->R2 = go_nan;
+ for (nb = 0; nb < 5; nb++)
+ rc->a[nb] = go_nan;
+ }
+ g_free (tx_vals);
+ g_free (ty_vals);
} else {
- rc->R2 = go_nan;
- for (nb = 0; nb < 5; nb++)
- rc->a[nb] = go_nan;
+ model->R2 = go_nan;
+ for (i = 0; i < 5; i++)
+ model->a[i] = go_nan;
}
- g_free (tx_vals);
- g_free (ty_vals);
g_free (rc->equation);
rc->equation = NULL;
gog_object_emit_changed (GOG_OBJECT (obj), FALSE);
diff --git a/plugins/smoothing/gog-moving-avg.c b/plugins/smoothing/gog-moving-avg.c
index 8b7f578..946dac4 100644
--- a/plugins/smoothing/gog-moving-avg.c
+++ b/plugins/smoothing/gog-moving-avg.c
@@ -133,7 +133,7 @@ gog_moving_avg_update (GogObject *obj)
return;
nb = gog_series_get_xy_data (series, &x_vals, &y_vals);
- if (nb < ma->span)
+ if (nb < ma->span || y_vals == NULL)
return;
ma->base.nb = nb - ma->span + 1;
ma->base.x = g_new (double, ma->base.nb);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]