Пример #1
0
static void show_single_dive_stats(struct dive *dive)
{
    char buf[80];
    double value;
    int decimals;
    const char *unit;
    int idx, offset, gas_used;
    struct dive *prev_dive;
    struct tm tm;

    process_all_dives(dive, &prev_dive);

    utc_mkdate(dive->when, &tm);
    snprintf(buf, sizeof(buf),
             /*++GETTEXT 80 chars: weekday, monthname, day, year, hour, min */
             _("%1$s, %2$s %3$d, %4$d %5$2d:%6$02d"),
             weekday(tm.tm_wday),
             monthname(tm.tm_mon),
             tm.tm_mday, tm.tm_year + 1900,
             tm.tm_hour, tm.tm_min);

    set_label(single_w.date, buf);
    set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60);
    if (prev_dive)
        set_label(single_w.surf_intv,
                  get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4));
    else
        set_label(single_w.surf_intv, _("unknown"));
    value = get_depth_units(dive->maxdepth.mm, &decimals, &unit);
    set_label(single_w.max_depth, "%.*f %s", decimals, value, unit);
    value = get_depth_units(dive->meandepth.mm, &decimals, &unit);
    set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit);
    if (dive->watertemp.mkelvin) {
        value = get_temp_units(dive->watertemp.mkelvin, &unit);
        set_label(single_w.water_temp, "%.1f %s", value, unit);
    } else
        set_label(single_w.water_temp, "");
    value = get_volume_units(dive->sac, &decimals, &unit);
    if (value > 0) {
        set_label(single_w.sac, _("%.*f %s/min"), decimals, value, unit);
    } else
        set_label(single_w.sac, "");
    set_label(single_w.otu, "%d", dive->otu);
    offset = 0;
    gas_used = 0;
    buf[0] = '\0';
    /* 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;
        if (!cylinder_none(cyl)) {
            /* 0% O2 strangely means air, so 21% - I don't like that at all */
            int o2 = cyl->gasmix.o2.permille ? : AIR_PERMILLE;
            if (offset > 0) {
                snprintf(buf+offset, 80-offset, ", ");
                offset += 2;
            }
            snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10,
                     (cyl->gasmix.he.permille + 5) / 10);
            offset = strlen(buf);
        }
        /* and if we have size, start and end pressure, we can
         * calculate the total gas used */
        if (cyl->type.size.mliter && start && end)
            gas_used += cyl->type.size.mliter / 1000.0 * (start - end);
    }
Пример #2
0
void show_dive_stats(struct dive *dive)
{
	char buf[80];
	double value;
	int decimals;
	const char *unit;
	int idx, offset, gas_used;
	struct dive *prev_dive;
	struct tm *tm;

	process_all_dives(dive, &prev_dive);

	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 + 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);
	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);
	} else
		set_label(info_stat_w.sac, "");
	set_label(info_stat_w.otu, "%d", dive->otu);
	offset = 0;
	gas_used = 0;
	buf[0] = '\0';
	/* 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 || 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) {
				snprintf(buf+offset, 80-offset, ", ");
				offset += 2;
			}
			snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10,
				(cyl->gasmix.he.permille + 5) / 10);
			offset = strlen(buf);
		}
		/* and if we have size, start and end pressure, we can
		 * calculate the total gas used */
		if (cyl->type.size.mliter && start && end)
			gas_used += cyl->type.size.mliter / 1000.0 * (start - end);
	}
Пример #3
0
/* we try to show the data from the currently selected divecomputer
 * right now for some values (e.g., surface pressure) we could fall back
 * to dive data, but for consistency we don't. */
static void show_single_dive_stats(struct dive *dive)
{
	char buf[256];
	double value;
	int decimals;
	const char *unit;
	int idx, offset, gas_used, mbar;
	struct dive *prev_dive;
	struct tm tm;
	struct divecomputer *dc;

	process_all_dives(dive, &prev_dive);
	if (!dive)
		return;
	dc = select_dc(&dive->dc);
	utc_mkdate(dive->when, &tm);
	snprintf(buf, sizeof(buf),
		/*++GETTEXT 80 chars: weekday, monthname, day, year, hour, min */
		_("%1$s, %2$s %3$d, %4$d %5$2d:%6$02d"),
		weekday(tm.tm_wday),
		monthname(tm.tm_mon),
		tm.tm_mday, tm.tm_year + 1900,
		tm.tm_hour, tm.tm_min);

	set_label(single_w.date, buf);
	set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60);
	if (prev_dive)
		set_label(single_w.surf_intv,
			get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4));
	else
		set_label(single_w.surf_intv, _("unknown"));
	value = get_depth_units(dc->maxdepth.mm, &decimals, &unit);
	set_label(single_w.max_depth, "%.*f %s", decimals, value, unit);
	value = get_depth_units(dc->meandepth.mm, &decimals, &unit);
	set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit);
	set_label(single_w.viz, star_strings[dive->visibility]);
	if (dc->watertemp.mkelvin) {
		value = get_temp_units(dc->watertemp.mkelvin, &unit);
		set_label(single_w.water_temp, "%.1f %s", value, unit);
	} else {
		set_label(single_w.water_temp, "");
	}
	if (dc->airtemp.mkelvin) {
		value = get_temp_units(dc->airtemp.mkelvin, &unit);
		set_label(single_w.air_temp, "%.1f %s", value, unit);
	} else {
		if (dive->airtemp.mkelvin) {
			value = get_temp_units(dive->airtemp.mkelvin, &unit);
			set_label(single_w.air_temp, "%.1f %s", value, unit);
		} else {
				set_label(single_w.air_temp, "");
		}
	}
	mbar = dc->surface_pressure.mbar;
	/* it would be easy to get dive data here:
	 *	if (!mbar)
	 *		mbar = get_surface_pressure_in_mbar(dive, FALSE);
	 */
	if (mbar) {
		set_label(single_w.air_press, "%d mbar", mbar);
	} else {
		set_label(single_w.air_press, "");
	}
	value = get_volume_units(dive->sac, &decimals, &unit);
	if (value > 0)
		set_label(single_w.sac, _("%.*f %s/min"), decimals, value, unit);
	else
		set_label(single_w.sac, "");
	set_label(single_w.otu, "%d", dive->otu);
	offset = 0;
	gas_used = 0;
	buf[0] = '\0';
	/* for the O2/He readings just create a list of them */
	for (idx = 0; idx < MAX_CYLINDERS; idx++) {
		cylinder_t *cyl = &dive->cylinder[idx];
		pressure_t start, end;

		start = cyl->start.mbar ? cyl->start : cyl->sample_start;
		end = cyl->end.mbar ?cyl->sample_end : cyl->sample_end;
		if (!cylinder_none(cyl)) {
			/* 0% O2 strangely means air, so 21% - I don't like that at all */
			int o2 = get_o2(&cyl->gasmix);
			int he = get_he(&cyl->gasmix);
			if (offset > 0) {
				snprintf(buf+offset, 80-offset, ", ");
				offset += 2;
			}
			snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (he + 5) / 10);
			offset = strlen(buf);
		}
		/* and if we have size, start and end pressure, we can
		 * calculate the total gas used */
		if (start.mbar && end.mbar)
			gas_used += gas_volume(cyl, start) - gas_volume(cyl, end);
	}
	set_label(single_w.o2he, buf);
	if (gas_used) {
		value = get_volume_units(gas_used, &decimals, &unit);
		set_label(single_w.gas_used, "%.*f %s", decimals, value, unit);
	} else {
		set_label(single_w.gas_used, "");
	}
}