diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-04-20 15:55:51 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-20 15:55:51 -0700 |
commit | eb07faef00c98ddcca3d0035d23661a3c4f30448 (patch) | |
tree | e51017e7939e1457447ae758f5784a0a7ce72bff | |
parent | e0ac1c9a26c6f82a42dea3d25bd0c8bd2a68ceb6 (diff) | |
download | subsurface-eb07faef00c98ddcca3d0035d23661a3c4f30448.tar.gz |
Only do 9 minute interval for min/max/avg
We don't use 3 and 6 minute values anywhere, so why calculate them.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/display.h | 2 | ||||
-rw-r--r-- | core/profile.c | 41 | ||||
-rw-r--r-- | core/profile.h | 6 | ||||
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 6 |
4 files changed, 24 insertions, 31 deletions
diff --git a/core/display.h b/core/display.h index 9e3e1d159..adda5c03a 100644 --- a/core/display.h +++ b/core/display.h @@ -21,7 +21,7 @@ struct plot_info { int minpressure, maxpressure; int minhr, maxhr; int mintemp, maxtemp; - enum {AIR, NITROX, TRIMIX, FREEDIVING} dive_type; + enum {AIR, NITROX, TRIMIX, FREEDIVING} dive_type; double endtempcoord; double maxpp; bool has_ndl; diff --git a/core/profile.c b/core/profile.c index 7d72508a1..fe73ab47e 100644 --- a/core/profile.c +++ b/core/profile.c @@ -196,37 +196,37 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str return airuse / atm * 60 / duration; } +#define HALF_INTERVAL 9 * 30 /* - * We do three min/max/avg calculations: over 3, 6 and 9 minutes + * Run the min/max calculations: over a 9 minute interval * around the entry point (indices 0, 1, 2 respectively). */ -static void analyze_plot_info_minmax_minute(struct plot_info *pi, int entry, int index) +static void analyze_plot_info_minmax(struct plot_info *pi, int entry_index) { - struct plot_data *plot_entry = pi->entry + entry; // fixed + struct plot_data *plot_entry = pi->entry + entry_index; // fixed struct plot_data *p = plot_entry; // moves with 'entry' - int seconds = 90 * (index + 1); - int start = p->sec - seconds, end = p->sec + seconds; + int start = p->sec - HALF_INTERVAL, end = p->sec + HALF_INTERVAL; int min, max; int firsttime, lasttime, lastdepth; int depth_time_2; /* Go back 'seconds' in time */ - while (entry > 0) { + while (entry_index > 0) { if (p[-1].sec < start) break; - entry--; + entry_index--; p--; } // indexes to the min/max entries - min = max = entry; + min = max = entry_index; // accumulated depth*time*2 depth_time_2 = 0; firsttime = lasttime = p->sec; lastdepth = p->depth; /* Then go forward until we hit an entry past the time */ - while (entry < pi->nr) { + while (entry_index < pi->nr) { int time = p->sec; int depth = p->depth; @@ -238,27 +238,20 @@ static void analyze_plot_info_minmax_minute(struct plot_info *pi, int entry, int lastdepth = depth; if (depth < pi->entry[min].depth) - min = entry; + min = entry_index; if (depth > pi->entry[max].depth) - max = entry; + max = entry_index; p++; - entry++; + entry_index++; } - plot_entry->min[index] = min; - plot_entry->max[index] = max; + plot_entry->min = min; + plot_entry->max = max; if (firsttime == lasttime) - plot_entry->avg[index] = pi->entry[min].depth; + plot_entry->avg = pi->entry[min].depth; else - plot_entry->avg[index] = depth_time_2 / 2 / (lasttime - firsttime); -} - -static void analyze_plot_info_minmax(struct plot_info *pi, int entry) -{ - analyze_plot_info_minmax_minute(pi, entry, 0); - analyze_plot_info_minmax_minute(pi, entry, 1); - analyze_plot_info_minmax_minute(pi, entry, 2); + plot_entry->avg = depth_time_2 / 2 / (lasttime - firsttime); } static velocity_t velocity(int speed) @@ -322,7 +315,7 @@ struct plot_info *analyze_plot_info(struct plot_info *pi) } } - /* 3, 6 and 9-minute minmax data */ + /* get minmax data */ for (i = 0; i < nr; i++) analyze_plot_info_minmax(pi, i); diff --git a/core/profile.h b/core/profile.h index 21cc263b7..b837b31a1 100644 --- a/core/profile.h +++ b/core/profile.h @@ -50,9 +50,9 @@ struct plot_data { double mod, ead, end, eadd; velocity_t velocity; int speed; - // stats over 3, 6, 9 minute windows: - int min[3], max[3]; // indices into pi->entry[] - int avg[3]; // actual depth average + // stats over 9 minute window: + int min, max; // indices into pi->entry[] + int avg; // actual depth average /* values calculated by us */ unsigned int in_deco_calc : 1; int ndl_calc; diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 9ea90ea2f..6eb678b3b 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -227,9 +227,9 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI for (int i = 0, count = dataModel->rowCount(); i < count; i++) { struct plot_data *pd = dataModel->data().entry; struct plot_data *entry = pd + i; - // "min/max[2]" are the 9-minute window min/max indices - struct plot_data *min_entry = pd + entry->min[2]; - struct plot_data *max_entry = pd + entry->max[2]; + // "min/max" are the 9-minute window min/max indices + struct plot_data *min_entry = pd + entry->min; + struct plot_data *max_entry = pd + entry->max; if (entry->depth < 2000) continue; |