summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2012-03-30 08:10:05 +0300
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-03-29 22:37:32 -0700
commit9fad1cb50f5976767c06aefe6d2b4d919d9a9634 (patch)
tree837187569aeec91ff1e3341c273bd1501df85423 /statistics.c
parentf69be7b571def1ae35ff7e96bdbac0de94df50fc (diff)
downloadsubsurface-9fad1cb50f5976767c06aefe6d2b4d919d9a9634.tar.gz
Fix broken average SAC calculation
old_sac_time was always 0 when calculating average air consumption. Thus the results were incorrect. Move the counter to stats_t structure as suggested by Linus. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/statistics.c b/statistics.c
index 65efdf145..34f487b52 100644
--- a/statistics.c
+++ b/statistics.c
@@ -69,6 +69,7 @@ typedef struct {
unsigned int combined_temp;
unsigned int combined_count;
unsigned int selection_size;
+ unsigned int total_sac_time;
} stats_t;
static stats_t stats;
@@ -93,14 +94,14 @@ static void process_dive(struct dive *dp, stats_t *stats)
stats->avg_depth.mm = (1.0 * old_tt * stats->avg_depth.mm +
dp->duration.seconds * dp->meandepth.mm) / stats->total_time.seconds;
if (dp->sac > 2800) { /* less than .1 cuft/min (2800ml/min) is bogus */
- int old_sac_time = sac_time;
- sac_time += dp->duration.seconds;
- stats->avg_sac.mliter = (1.0 * old_sac_time * stats->avg_sac.mliter +
+ sac_time = stats->total_sac_time + dp->duration.seconds;
+ stats->avg_sac.mliter = (1.0 * stats->total_sac_time * stats->avg_sac.mliter +
dp->duration.seconds * dp->sac) / sac_time ;
if (dp->sac > stats->max_sac.mliter)
stats->max_sac.mliter = dp->sac;
if (stats->min_sac.mliter == 0 || dp->sac < stats->min_sac.mliter)
stats->min_sac.mliter = dp->sac;
+ stats->total_sac_time = sac_time;
}
if (dp->watertemp.mkelvin) {
if (stats->min_temp == 0 || dp->watertemp.mkelvin < stats->min_temp)