X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=statistics.c;h=4c637944329f8e3bea52257909c6f7f666acca16;hb=0f139718697035fa8e1b26f908403ad27bb36554;hp=845bc2a03d6ef7a669625d5bbab0bff0e2d484ef;hpb=55352a051cfa7ac519e397cd3d18851e5050517b;p=ext%2Fsubsurface.git diff --git a/statistics.c b/statistics.c index 845bc2a..4c63794 100644 --- a/statistics.c +++ b/statistics.c @@ -76,14 +76,14 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive) info_stat.max_depth.mm = dp->maxdepth.mm; info_stat.avg_depth.mm = (1.0 * old_tt * info_stat.avg_depth.mm + dp->duration.seconds * dp->meandepth.mm) / info_stat.total_time.seconds; - if (dp->sac > 0) { + if (dp->sac > 2800) { /* less than .1 cuft/min (2800ml/min) is bogus */ int old_sac_time = sac_time; sac_time += dp->duration.seconds; info_stat.avg_sac.mliter = (1.0 * old_sac_time * info_stat.avg_sac.mliter + dp->duration.seconds * dp->sac) / sac_time ; if (dp->sac > info_stat.max_sac.mliter) info_stat.max_sac.mliter = dp->sac; - if (info_stat.min_sac.mliter == 0 || dp->sac < info_stat.max_sac.mliter) + if (info_stat.min_sac.mliter == 0 || dp->sac < info_stat.min_sac.mliter) info_stat.min_sac.mliter = dp->sac; } } @@ -125,22 +125,34 @@ void show_dive_stats(struct dive *dive) const char *unit; int idx, offset, gas_used; struct dive *prev_dive; + struct tm *tm; process_all_dives(dive, &prev_dive); - strftime(buf, 80, "%a, %b %d, %Y, %k:%M", gmtime(&dive->when)); + tm = gmtime(&dive->when); + snprintf(buf, sizeof(buf), + "%s, %s %d, %d %2d:%02d", + weekday(tm->tm_wday), + monthname(tm->tm_mon), + tm->tm_mday, tm->tm_year + 1900, + tm->tm_hour, tm->tm_min); + set_label(info_stat_w.date, buf); set_label(info_stat_w.dive_time, "%d min", (dive->duration.seconds + 30) / 60); if (prev_dive) - set_label(info_stat_w.surf_intv, get_time_string(dive->when - prev_dive->when, 4)); + set_label(info_stat_w.surf_intv, + get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(info_stat_w.surf_intv, "unknown"); value = get_depth_units(dive->maxdepth.mm, &decimals, &unit); set_label(info_stat_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dive->meandepth.mm, &decimals, &unit); set_label(info_stat_w.avg_depth, "%.*f %s", decimals, value, unit); - value = get_temp_units(dive->watertemp.mkelvin, &unit); - set_label(info_stat_w.water_temp, "%.1f %s", value, unit); + if (dive->watertemp.mkelvin) { + value = get_temp_units(dive->watertemp.mkelvin, &unit); + set_label(info_stat_w.water_temp, "%.1f %s", value, unit); + } else + set_label(info_stat_w.water_temp, ""); value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) { set_label(info_stat_w.sac, "%.*f %s/min", decimals, value, unit); @@ -153,11 +165,14 @@ void show_dive_stats(struct dive *dive) /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; + unsigned int start, end; + + start = cyl->start.mbar ? : cyl->sample_start.mbar; + end = cyl->end.mbar ? : cyl->sample_end.mbar; /* we assume that every valid cylinder has either a working pressure * or a size; but for good measure let's also accept cylinders with * a starting or ending pressure*/ - if (cyl->type.workingpressure.mbar || cyl->type.size.mliter || - cyl->start.mbar || cyl->end.mbar) { + if (cyl->type.workingpressure.mbar || cyl->type.size.mliter || start || end) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = cyl->gasmix.o2.permille ? : 209; if (offset > 0) { @@ -170,12 +185,10 @@ void show_dive_stats(struct dive *dive) } /* and if we have size, start and end pressure, we can * calculate the total gas used */ - if (cyl->type.size.mliter && cyl->start.mbar && cyl->end.mbar) - gas_used += cyl->type.size.mliter / 1000.0 * - (cyl->start.mbar - cyl->end.mbar); + if (cyl->type.size.mliter && start && end) + gas_used += cyl->type.size.mliter / 1000.0 * (start - end); } - if (offset) - set_label(info_stat_w.o2he, buf); + set_label(info_stat_w.o2he, buf); if (gas_used) { value = get_volume_units(gas_used, &decimals, &unit); set_label(info_stat_w.gas_used, "%.*f %s", decimals, value, unit);