This commit is contained in:
michaelandreen 2024-02-20 07:52:53 +13:00 committed by GitHub
commit a74e56b8cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 44 additions and 8 deletions

View file

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <limits.h>
#include "dive.h"
#include "deco.h"
#include "gettext.h"
#include "subsurface-string.h"
#include "libdivecomputer.h"
@ -1315,6 +1316,25 @@ struct dive *fixup_dive(struct dive *dive)
if (!dive->id)
dive->id = dive_getUniqID();
struct deco_state ds;
/* Load tissues from previous dives */
init_decompression(&ds, dive, false);
/* Load tissues from this dive */
add_dive_to_deco(&ds, dive, false, true);
double surface_pressure = get_surface_pressure_in_mbar(dive, true) / 1000.0;
/* Sets buehlmann_inertgas_[ab] */
tissue_tolerance_calc(&ds, dive, surface_pressure, false);
dive->end_gf = 0;
for (int j = 0; j < 16; j++) {
double surface_m_value = ds.buehlmann_inertgas_a[j] + surface_pressure / ds.buehlmann_inertgas_b[j];
double surface_gf = 100.0 * (ds.tissue_inertgas_saturation[j] - surface_pressure) / (surface_m_value - surface_pressure);
if (surface_gf > dive->end_gf)
dive->end_gf = (int)ceil(surface_gf);
}
return dive;
}

View file

@ -41,6 +41,7 @@ struct dive {
int rating;
int wavesize, current, visibility, surge, chill; /* 0 - 5 star ratings */
int sac, otu, cns, maxcns;
int end_gf;
/* Calculated based on dive computer data */
temperature_t mintemp, maxtemp, watertemp, airtemp;

View file

@ -396,7 +396,7 @@ static int calculate_sac(const struct dive *dive)
}
/* for now we do this based on the first divecomputer */
static void add_dive_to_deco(struct deco_state *ds, struct dive *dive, bool in_planner)
void add_dive_to_deco(struct deco_state *ds, struct dive *dive, bool in_planner, bool early_exit)
{
struct divecomputer *dc = &dive->dc;
struct gasmix gasmix = gasmix_air;
@ -414,6 +414,10 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive, bool in_p
int t1 = sample->time.seconds;
int j;
/* Early exit for when there are a lot of surface samples at the end */
if (early_exit && t1 > dive->duration.seconds)
break;
for (j = t0; j < t1; j++) {
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
gasmix = get_gasmix(dive, dc, j, &ev, gasmix);
@ -489,6 +493,12 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
printf("Check if dive #%d %d has to be considered as prev dive: ", i, get_dive(i)->number);
#endif
struct dive *pdive = get_dive(i);
if (!pdive || pdive->when >= dive->when || dive_endtime(pdive) + 48 * 60 * 60 < last_starttime) {
#if DECO_CALC_DEBUG & 2
printf("No\n");
#endif
break;
}
/* we don't want to mix dives from different trips as we keep looking
* for how far back we need to go */
if (dive->divetrip && pdive->divetrip != dive->divetrip) {
@ -497,12 +507,6 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
#endif
continue;
}
if (!pdive || pdive->when >= dive->when || dive_endtime(pdive) + 48 * 60 * 60 < last_starttime) {
#if DECO_CALC_DEBUG & 2
printf("No\n");
#endif
break;
}
last_starttime = pdive->when;
#if DECO_CALC_DEBUG & 2
printf("Yes\n");
@ -566,7 +570,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
#endif
}
add_dive_to_deco(ds, pdive, in_planner);
add_dive_to_deco(ds, pdive, in_planner, false);
last_starttime = pdive->when;
last_endtime = dive_endtime(pdive);

View file

@ -27,6 +27,7 @@ static const struct dive_table empty_dive_table = { 0, 0, (struct dive **)0 };
extern void sort_dive_table(struct dive_table *table);
extern void update_cylinder_related_info(struct dive *);
extern int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_planner);
void add_dive_to_deco(struct deco_state *ds, struct dive *dive, bool in_planner, bool early_exit);
/* divelist core logic functions */
extern void process_loaded_dives();

View file

@ -43,6 +43,7 @@ static QVariant dive_table_alignment(int column)
case DiveTripModelBase::SAC:
case DiveTripModelBase::OTU:
case DiveTripModelBase::MAXCNS:
case DiveTripModelBase::ENDGF:
// Right align numeric columns
return int(Qt::AlignRight | Qt::AlignVCenter);
// NR needs to be left aligned because its the indent marker for trips too
@ -247,6 +248,8 @@ QString DiveTripModelBase::getDescription(int column)
return tr("OTU");
case MAXCNS:
return tr("Max. CNS");
case ENDGF:
return tr("EndGF");
case TAGS:
return tr("Tags");
case PHOTOS:
@ -346,6 +349,8 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
return QString("%1%").arg(d->maxcns);
else
return d->maxcns;
case ENDGF:
return d->end_gf;
case TAGS:
return get_taglist_string(d->tag_list);
case PHOTOS:
@ -440,6 +445,8 @@ QVariant DiveTripModelBase::headerData(int section, Qt::Orientation orientation,
return tr("OTU");
case MAXCNS:
return tr("Max CNS");
case ENDGF:
return tr("EndGF");
case TAGS:
return tr("Tags");
case PHOTOS:
@ -1765,6 +1772,8 @@ bool DiveTripModelList::lessThan(const QModelIndex &i1, const QModelIndex &i2) c
return lessThanHelper(d1->otu - d2->otu, row_diff);
case MAXCNS:
return lessThanHelper(d1->maxcns - d2->maxcns, row_diff);
case ENDGF:
return lessThanHelper(d1->end_gf - d2->end_gf, row_diff);
case TAGS: {
char *s1 = taglist_get_tagstring(d1->tag_list);
char *s2 = taglist_get_tagstring(d2->tag_list);

View file

@ -37,6 +37,7 @@ public:
SAC,
OTU,
MAXCNS,
ENDGF,
TAGS,
PHOTOS,
BUDDIES,