mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
d7103f97f7
commit
e0ac1c9a26
3 changed files with 61 additions and 36 deletions
|
@ -196,46 +196,69 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
|
||||||
return airuse / atm * 60 / duration;
|
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;
|
struct plot_data *plot_entry = pi->entry + entry; // fixed
|
||||||
int time = entry->sec;
|
struct plot_data *p = plot_entry; // moves with 'entry'
|
||||||
int seconds = 90 * (index + 1);
|
int seconds = 90 * (index + 1);
|
||||||
struct plot_data *min, *max;
|
int start = p->sec - seconds, end = p->sec + seconds;
|
||||||
int avg, nr;
|
int min, max;
|
||||||
|
int firsttime, lasttime, lastdepth;
|
||||||
|
int depth_time_2;
|
||||||
|
|
||||||
/* Go back 'seconds' in time */
|
/* Go back 'seconds' in time */
|
||||||
while (p > first) {
|
while (entry > 0) {
|
||||||
if (p[-1].sec < time - seconds)
|
if (p[-1].sec < start)
|
||||||
break;
|
break;
|
||||||
|
entry--;
|
||||||
p--;
|
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 */
|
/* Then go forward until we hit an entry past the time */
|
||||||
min = max = p;
|
while (entry < pi->nr) {
|
||||||
avg = p->depth;
|
int time = p->sec;
|
||||||
nr = 1;
|
|
||||||
while (++p < last) {
|
|
||||||
int depth = p->depth;
|
int depth = p->depth;
|
||||||
if (p->sec > time + seconds)
|
|
||||||
|
if (time > end)
|
||||||
break;
|
break;
|
||||||
avg += depth;
|
|
||||||
nr++;
|
depth_time_2 += (time - lasttime) * (depth + lastdepth);
|
||||||
if (depth < min->depth)
|
lasttime = time;
|
||||||
min = p;
|
lastdepth = depth;
|
||||||
if (depth > max->depth)
|
|
||||||
max = p;
|
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;
|
plot_entry->min[index] = min;
|
||||||
entry->avg[index] = (avg + nr / 2) / nr;
|
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(pi, entry, 0);
|
||||||
analyze_plot_info_minmax_minute(entry, first, last, 1);
|
analyze_plot_info_minmax_minute(pi, entry, 1);
|
||||||
analyze_plot_info_minmax_minute(entry, first, last, 2);
|
analyze_plot_info_minmax_minute(pi, entry, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static velocity_t velocity(int speed)
|
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 */
|
/* 3, 6 and 9-minute minmax data */
|
||||||
for (i = 0; i < nr; i++) {
|
for (i = 0; i < nr; i++)
|
||||||
struct plot_data *entry = pi->entry + i;
|
analyze_plot_info_minmax(pi, i);
|
||||||
analyze_plot_info_minmax(entry, pi->entry, pi->entry + nr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,9 @@ struct plot_data {
|
||||||
double mod, ead, end, eadd;
|
double mod, ead, end, eadd;
|
||||||
velocity_t velocity;
|
velocity_t velocity;
|
||||||
int speed;
|
int speed;
|
||||||
struct plot_data *min[3];
|
// stats over 3, 6, 9 minute windows:
|
||||||
struct plot_data *max[3];
|
int min[3], max[3]; // indices into pi->entry[]
|
||||||
int avg[3];
|
int avg[3]; // actual depth average
|
||||||
/* values calculated by us */
|
/* values calculated by us */
|
||||||
unsigned int in_deco_calc : 1;
|
unsigned int in_deco_calc : 1;
|
||||||
int ndl_calc;
|
int ndl_calc;
|
||||||
|
|
|
@ -225,17 +225,21 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI
|
||||||
|
|
||||||
int last = -1;
|
int last = -1;
|
||||||
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
|
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];
|
||||||
|
|
||||||
struct plot_data *entry = dataModel->data().entry + i;
|
|
||||||
if (entry->depth < 2000)
|
if (entry->depth < 2000)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((entry == entry->max[2]) && entry->depth / 100 != last) {
|
if ((entry == max_entry) && entry->depth / 100 != last) {
|
||||||
plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignBottom, getColor(SAMPLE_DEEP));
|
plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignBottom, getColor(SAMPLE_DEEP));
|
||||||
last = entry->depth / 100;
|
last = entry->depth / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((entry == entry->min[2]) && entry->depth / 100 != last) {
|
if ((entry == min_entry) && entry->depth / 100 != last) {
|
||||||
plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignTop, getColor(SAMPLE_SHALLOW));
|
plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignTop, getColor(SAMPLE_SHALLOW));
|
||||||
last = entry->depth / 100;
|
last = entry->depth / 100;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue