Changeset 5aa9c6fa in subsurface


Ignore:
Timestamp:
Feb 3, 2017, 7:45:24 AM (4 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
7c8461a
Parents:
67de8f3
git-author:
Robert Helling <helling@…> (02/03/17 02:14:51)
git-committer:
Dirk Hohndel <dirk@…> (02/03/17 07:45:24)
Message:

Do not count gas used in planned dives for statistics

This is important if in one dive we have the real dive and
a planned version of the dive as different computers using
different sets of cylinders.

[Dirk Hohndel: an early version of this was mistakenly pushed out

by me; I reverted that and added this commit since
fixing things up as I had done for the other two
patches made things nearly unreadable]

Signed-off-by: Robert C. Helling <helling@…>
Signed-off-by: Dirk Hohndel <dirk@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/statistics.c

    r08c4281 r5aa9c6fa  
    327327#define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used
    328328
     329bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx) {
     330        bool first_gas_explicit = false;
     331        struct event *event = get_next_event(dc->events, "gaschange");
     332        while (event) {
     333                if (dc->sample && (event->time.seconds == 0 ||
     334                                   (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
     335                        first_gas_explicit = true;
     336                if (get_cylinder_index(dive, event) == idx)
     337                        return true;
     338                event = get_next_event(event->next, "gaschange");
     339        }
     340        if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
     341                return true;
     342        return !first_gas_explicit && idx == 0;
     343}
     344
    329345bool is_cylinder_used(struct dive *dive, int idx)
    330346{
    331347        struct divecomputer *dc;
    332         bool firstGasExplicit = false;
    333348        if (cylinder_none(&dive->cylinder[idx]))
    334349                return false;
     
    337352                return true;
    338353        for_each_dc(dive, dc) {
    339                 struct event *event = get_next_event(dc->events, "gaschange");
    340                 while (event) {
    341                         if (dc->sample && (event->time.seconds == 0 ||
    342                                            (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
    343                                 firstGasExplicit = true;
    344                         if (get_cylinder_index(dive, event) == idx)
    345                                 return true;
    346                         event = get_next_event(event->next, "gaschange");
    347                 }
    348                 if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
     354                if (has_gaschange_event(dive, dc, idx))
    349355                        return true;
    350356        }
    351         if (idx == 0 && !firstGasExplicit)
    352                 return true;
    353357        return false;
    354358}
     
    357361{
    358362        int idx;
     363        struct divecomputer *dc;
     364        bool used;
     365
    359366        for (idx = 0; idx < MAX_CYLINDERS; idx++) {
     367                used = false;
    360368                cylinder_t *cyl = &dive->cylinder[idx];
    361369                pressure_t start, end;
    362370
    363                 if (!is_cylinder_used(dive, idx))
     371                for_each_dc(dive, dc) {
     372                        if (!strcmp(dc->model, "planned dive"))
     373                                continue;
     374                        if (has_gaschange_event(dive, dc, idx))
     375                                used = true;
     376                }
     377
     378                if (!used)
    364379                        continue;
    365380
Note: See TracChangeset for help on using the changeset viewer.