mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Make gas use statistics be coherent and more complete
The gas use logic in the dive statistics page is confused. The SAC case had a special case for "unknown", but only for the first gas. Other gases had the normal empty case. Also, the logic was really odd - if you had gases that weren't used (or pressures not known) intermixed with gases you *did* have pressure for, the statistics got really confused. The list of gases showed all gases that we know about during the dive, but then the gas use and SAC-rate lists wouldn't necessarily match, because the loops that computed those stopped after the first gas that didn't have any pressure change. To make things worse, the first cylinder was special-cased again, so it all lined up for the single-cylinder case. This makes all the cylinders act the same way, leaving unknown gas use (and thus SAC) just empty for that gas. It also fixes the SAC calculation case where we don't have real samples, and the profile is a fake profile - possibly with gas changes in between the fake points. We now make the SAC calculations match what we show - which is admittedly not at all necessarily what the dive was, but at least we're consistent. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
d982096144
commit
3aaf8b1f5a
4 changed files with 33 additions and 44 deletions
17
dive.c
17
dive.c
|
@ -7,6 +7,7 @@
|
|||
#include "gettext.h"
|
||||
#include "dive.h"
|
||||
#include "libdivecomputer.h"
|
||||
#include "device.h"
|
||||
|
||||
/* one could argue about the best place to have this variable -
|
||||
* it's used in the UI, but it seems to make the most sense to have it
|
||||
|
@ -586,14 +587,28 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
|
|||
duration[0] = dc->duration.seconds;
|
||||
return;
|
||||
}
|
||||
if (!dc->samples)
|
||||
dc = fake_dc(dc);
|
||||
for (i = 0; i < dc->samples; i++) {
|
||||
struct sample *sample = dc->sample + i;
|
||||
int time = sample->time.seconds;
|
||||
int depth = sample->depth.mm;
|
||||
if (ev && time >= ev->time.seconds) {
|
||||
|
||||
/* Make sure to move the event past 'lasttime' */
|
||||
while (ev && lasttime >= ev->time.seconds) {
|
||||
idx = get_cylinder_index(dive, ev);
|
||||
ev = get_next_event(ev->next, "gaschange");
|
||||
}
|
||||
|
||||
/* Do we need to fake a midway sample at an event? */
|
||||
if (ev && time > ev->time.seconds) {
|
||||
int newtime = ev->time.seconds;
|
||||
int newdepth = interpolate(lastdepth, depth, newtime - lasttime, time - lasttime);
|
||||
|
||||
time = newtime;
|
||||
depth = newdepth;
|
||||
i--;
|
||||
}
|
||||
/* We ignore segments at the surface */
|
||||
if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) {
|
||||
duration[idx] += time - lasttime;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue