smtk-import - Change cylinder import logic

Until now, we did the cylinder import based on its initial pressure (a
tank without pressure is an unused tank). Based in this assumption, we
just dropped those tanks whose initial press was 0, losing user
introduced tank definitions  and getting some duplicities due to one
cylinder being numbered (e.g.) 2 by libdivecomputer and 3 by SmartTrak.

The new workflow is: get every single tank reported by SmartTrak (giving
preference to libdivecomputer parsed data), then clean the cylinder
table reverse order, dropping tanks without description and  init or end
pressures, and checkig them against the previous cylinder to do a merge,
if they look the same, and try to avoid duplicities.

The new logic assumes a heavier workload for the benefit of lower data
loss (e.g. a user may get his/her tanks descriptions despite he/she
hasn't recorded their pressures because forgot the values or had an issue
with the gas transmitter).

Suggested-by: Alessandro Volpi <volpial@gmail.com>
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
This commit is contained in:
Salvador Cuñat 2017-03-16 17:07:56 +01:00 committed by Dirk Hohndel
parent 16d37c254c
commit 5c757d5c38

View file

@ -863,26 +863,27 @@ void smartrak_import(const char *file, struct dive_table *divetable)
int hefraccol = coln(HEFRAC); int hefraccol = coln(HEFRAC);
int tankidxcol = coln(TANKIDX); int tankidxcol = coln(TANKIDX);
for (i = 0; i < numtanks; i++) { for (i = 0; i < tanks; i++) {
if (smtkdive->cylinder[i].start.mbar == 0) { if (smtkdive->cylinder[i].start.mbar == 0)
smtkdive->cylinder[i].start.mbar = strtod(col[(i*2)+pstartcol]->bind_ptr, NULL) * 1000; smtkdive->cylinder[i].start.mbar = lrint(strtod(col[(i * 2) + pstartcol]->bind_ptr, NULL) * 1000);
smtkdive->cylinder[i].gasmix.o2.permille = strtod(col[i+o2fraccol]->bind_ptr, NULL) * 10;
if (smtk_version == 10213)
smtkdive->cylinder[i].gasmix.he.permille = strtod(col[i+hefraccol]->bind_ptr, NULL) * 10;
else
smtkdive->cylinder[i].gasmix.he.permille = 0;
}
/* /*
* If there is a start pressure ensure that end pressure is not zero as * If there is a start pressure ensure that end pressure is not zero as
* will be registered in DCs which only keep track of differential pressures, * will be registered in DCs which only keep track of differential pressures,
* and collect the data registered by the user in mdb * and collect the data registered by the user in mdb
*/ */
if (smtkdive->cylinder[i].start.mbar != 0) { if (smtkdive->cylinder[i].end.mbar == 0 && smtkdive->cylinder[i].start.mbar != 0)
if (smtkdive->cylinder[i].end.mbar == 0) smtkdive->cylinder[i].end.mbar = lrint(strtod(col[(i * 2) + 1 + pstartcol]->bind_ptr, NULL) * 1000 ? : 1000);
smtkdive->cylinder[i].end.mbar = strtod(col[(i * 2) + 1 + pstartcol]->bind_ptr, NULL) * 1000 ? : 1000; if (smtkdive->cylinder[i].gasmix.o2.permille == 0)
smtk_build_tank_info(mdb_clon, smtkdive, i, col[i + tankidxcol]->bind_ptr); smtkdive->cylinder[i].gasmix.o2.permille = lrint(strtod(col[i + o2fraccol]->bind_ptr, NULL) * 10);
} if (smtk_version == 10213)
if (smtkdive->cylinder[i].gasmix.he.permille == 0)
smtkdive->cylinder[i].gasmix.he.permille = lrint(strtod(col[i + hefraccol]->bind_ptr, NULL) * 10);
else
smtkdive->cylinder[i].gasmix.he.permille = 0;
smtk_build_tank_info(mdb_clon, &smtkdive->cylinder[i], col[i + tankidxcol]->bind_ptr);
} }
/* Check for duplicated cylinders and clean them */
smtk_clean_cylinders(smtkdive);
/* Date issues with libdc parser - Take date time from mdb */ /* Date issues with libdc parser - Take date time from mdb */
smtk_date_to_tm(col[coln(DATE)]->bind_ptr, tm_date); smtk_date_to_tm(col[coln(DATE)]->bind_ptr, tm_date);