stats->max_depth.mm = dp->maxdepth.mm;
if (stats->min_depth.mm == 0 || dp->maxdepth.mm < stats->min_depth.mm)
stats->min_depth.mm = dp->maxdepth.mm;
+ if (dp->watertemp.mkelvin) {
+ if (stats->min_temp == 0 || dp->watertemp.mkelvin < stats->min_temp)
+ stats->min_temp = dp->watertemp.mkelvin;
+ if (dp->watertemp.mkelvin > stats->max_temp)
+ stats->max_temp = dp->watertemp.mkelvin;
+ stats->combined_temp += get_temp_units(dp->watertemp.mkelvin, &unit);
+ stats->combined_count++;
+ }
+
+ /* Maybe we should drop zero-duration dives */
+ if (!dp->duration.seconds)
+ return;
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 */
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)
- stats->min_temp = dp->watertemp.mkelvin;
- if (dp->watertemp.mkelvin > stats->max_temp)
- stats->max_temp = dp->watertemp.mkelvin;
- stats->combined_temp += get_temp_units(dp->watertemp.mkelvin, &unit);
- stats->combined_count++;
- }
}
static void process_all_dives(struct dive *dive, struct dive **prev_dive)
}
}
-void process_selected_dives(GList *selected_dives, GtkTreeModel *model)
+/* make sure we skip the selected summary entries */
+void process_selected_dives(GList *selected_dives, int *selectiontracker, GtkTreeModel *model)
{
struct dive *dp;
- unsigned int i;
+ unsigned int i, j;
+ int idx;
GtkTreeIter iter;
GtkTreePath *path;
memset(&stats_selection, 0, sizeof(stats_selection));
- stats_selection.selection_size = amount_selected;
- for (i = 0; i < amount_selected; ++i) {
+ /* adjust amount_selected and remove negative index entries from list */
+ for (i = 0, j = 0; j < amount_selected; ++i) {
GValue value = {0, };
path = g_list_nth_data(selected_dives, i);
if (gtk_tree_model_get_iter(model, &iter, path)) {
gtk_tree_model_get_value(model, &iter, 0, &value);
- dp = get_dive(g_value_get_int(&value));
+ idx = g_value_get_int(&value);
+ if (idx > 0) {
+ dp = get_dive(idx);
+ if (dp) {
+ selectiontracker[j] = idx;
+ process_dive(dp, &stats_selection);
+ j++;
+ continue;
+ }
+ }
}
- process_dive(dp, &stats_selection);
+ /* we didn't process it, so shorten the list */
+ amount_selected--;
}
+ /* record the actual number of dives selected */
+ stats_selection.selection_size = amount_selected;
}
static void set_label(GtkWidget *w, const char *fmt, ...)
static void show_total_dive_stats(struct dive *dive)
{
double value;
- int decimals;
+ int decimals, seconds;
const char *unit;
stats_t *stats_ptr;
set_label(stats_w.max_temp, "%.1f %s", value, unit);
}
set_label(stats_w.total_time, get_time_string(stats_ptr->total_time.seconds, 0));
- set_label(stats_w.avg_time, get_time_string(stats_ptr->total_time.seconds / stats_ptr->selection_size, 0));
+ seconds = stats_ptr->total_time.seconds;
+ if (stats_ptr->selection_size)
+ seconds /= stats_ptr->selection_size;
+ set_label(stats_w.avg_time, get_time_string(seconds, 0));
set_label(stats_w.longest_time, get_time_string(stats_ptr->longest_time.seconds, 0));
set_label(stats_w.shortest_time, get_time_string(stats_ptr->shortest_time.seconds, 0));
value = get_depth_units(stats_ptr->max_depth.mm, &decimals, &unit);