summaryrefslogtreecommitdiffstats
path: root/core/profile.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2016-04-20 15:12:53 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-20 15:36:25 -0700
commite0ac1c9a26c6f82a42dea3d25bd0c8bd2a68ceb6 (patch)
tree2fa7fa8677d41b8d1e285a079839d5f7abab4f4c /core/profile.c
parentd7103f97f70417476468608b1535758dd4b344b7 (diff)
downloadsubsurface-e0ac1c9a26c6f82a42dea3d25bd0c8bd2a68ceb6.tar.gz
Fix 3-, 6- and 9-minute min/max calculations
Make them use indices into the plot-info, fix calculation of average depth, and fix and add comments. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/profile.c')
-rw-r--r--core/profile.c81
1 files changed, 51 insertions, 30 deletions
diff --git a/core/profile.c b/core/profile.c
index b4f7279a0..7d72508a1 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -196,46 +196,69 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
return airuse / atm * 60 / duration;
}
-static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot_data *first, struct plot_data *last, int index)
+/*
+ * We do three min/max/avg calculations: over 3, 6 and 9 minutes
+ * around the entry point (indices 0, 1, 2 respectively).
+ */
+static void analyze_plot_info_minmax_minute(struct plot_info *pi, int entry, int index)
{
- struct plot_data *p = entry;
- int time = entry->sec;
+ struct plot_data *plot_entry = pi->entry + entry; // fixed
+ struct plot_data *p = plot_entry; // moves with 'entry'
int seconds = 90 * (index + 1);
- struct plot_data *min, *max;
- int avg, nr;
+ int start = p->sec - seconds, end = p->sec + seconds;
+ int min, max;
+ int firsttime, lasttime, lastdepth;
+ int depth_time_2;
/* Go back 'seconds' in time */
- while (p > first) {
- if (p[-1].sec < time - seconds)
+ while (entry > 0) {
+ if (p[-1].sec < start)
break;
+ entry--;
p--;
}
+ // indexes to the min/max entries
+ min = max = entry;
+ // 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 */
- min = max = p;
- avg = p->depth;
- nr = 1;
- while (++p < last) {
+ while (entry < pi->nr) {
+ int time = p->sec;
int depth = p->depth;
- if (p->sec > time + seconds)
+
+ if (time > end)
break;
- avg += depth;
- nr++;
- if (depth < min->depth)
- min = p;
- if (depth > max->depth)
- max = p;
+
+ depth_time_2 += (time - lasttime) * (depth + lastdepth);
+ lasttime = time;
+ lastdepth = depth;
+
+ if (depth < pi->entry[min].depth)
+ min = entry;
+ if (depth > pi->entry[max].depth)
+ max = entry;
+
+ p++;
+ entry++;
}
- entry->min[index] = min;
- entry->max[index] = max;
- entry->avg[index] = (avg + nr / 2) / nr;
+
+ plot_entry->min[index] = min;
+ plot_entry->max[index] = max;
+ if (firsttime == lasttime)
+ plot_entry->avg[index] = pi->entry[min].depth;
+ else
+ plot_entry->avg[index] = depth_time_2 / 2 / (lasttime - firsttime);
}
-static void analyze_plot_info_minmax(struct plot_data *entry, struct plot_data *first, struct plot_data *last)
+static void analyze_plot_info_minmax(struct plot_info *pi, int entry)
{
- analyze_plot_info_minmax_minute(entry, first, last, 0);
- analyze_plot_info_minmax_minute(entry, first, last, 1);
- analyze_plot_info_minmax_minute(entry, first, last, 2);
+ analyze_plot_info_minmax_minute(pi, entry, 0);
+ analyze_plot_info_minmax_minute(pi, entry, 1);
+ analyze_plot_info_minmax_minute(pi, entry, 2);
}
static velocity_t velocity(int speed)
@@ -299,11 +322,9 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
}
}
- /* One-, two- and three-minute minmax data */
- for (i = 0; i < nr; i++) {
- struct plot_data *entry = pi->entry + i;
- analyze_plot_info_minmax(entry, pi->entry, pi->entry + nr);
- }
+ /* 3, 6 and 9-minute minmax data */
+ for (i = 0; i < nr; i++)
+ analyze_plot_info_minmax(pi, i);
return pi;
}