diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/divelogexportlogic.cpp | 13 | ||||
-rw-r--r-- | core/statistics.c | 26 | ||||
-rw-r--r-- | core/statistics.h | 6 | ||||
-rw-r--r-- | core/units.h | 5 |
4 files changed, 29 insertions, 21 deletions
diff --git a/core/divelogexportlogic.cpp b/core/divelogexportlogic.cpp index 926dd461c..017689568 100644 --- a/core/divelogexportlogic.cpp +++ b/core/divelogexportlogic.cpp @@ -99,12 +99,15 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin out << "\"AVG_SAC\":\"" << get_volume_string(stats_yearly[i].avg_sac) << "\","; out << "\"MIN_SAC\":\"" << get_volume_string(stats_yearly[i].min_sac) << "\","; out << "\"MAX_SAC\":\"" << get_volume_string(stats_yearly[i].max_sac) << "\","; - if ( stats_yearly[i].combined_count ) - out << "\"AVG_TEMP\":\"" << QString::number(stats_yearly[i].combined_temp / stats_yearly[i].combined_count, 'f', 1) << "\","; - else + if ( stats_yearly[i].combined_count ) { + temperature_t avg_temp; + avg_temp.mkelvin = stats_yearly[i].combined_temp.mkelvin / stats_yearly[i].combined_count; + out << "\"AVG_TEMP\":\"" << get_temperature_string(avg_temp) << "\","; + } else { out << "\"AVG_TEMP\":\"0.0\","; - out << "\"MIN_TEMP\":\"" << ( stats_yearly[i].min_temp == 0 ? 0 : get_temp_units(stats_yearly[i].min_temp, NULL)) << "\","; - out << "\"MAX_TEMP\":\"" << ( stats_yearly[i].max_temp == 0 ? 0 : get_temp_units(stats_yearly[i].max_temp, NULL)) << "\","; + } + out << "\"MIN_TEMP\":\"" << ( stats_yearly[i].min_temp.mkelvin == 0 ? 0 : get_temperature_string(stats_yearly[i].min_temp)) << "\","; + out << "\"MAX_TEMP\":\"" << ( stats_yearly[i].max_temp.mkelvin == 0 ? 0 : get_temperature_string(stats_yearly[i].max_temp)) << "\","; out << "},"; total_stats.selection_size += stats_yearly[i].selection_size; total_stats.total_time.seconds += stats_yearly[i].total_time.seconds; diff --git a/core/statistics.c b/core/statistics.c index 13bcc4a97..c7cd213ff 100644 --- a/core/statistics.c +++ b/core/statistics.c @@ -24,23 +24,23 @@ stats_t *stats_by_type = NULL; static void process_temperatures(struct dive *dp, stats_t *stats) { - int min_temp, mean_temp, max_temp = 0; + temperature_t min_temp, mean_temp, max_temp = {.mkelvin = 0}; - max_temp = dp->maxtemp.mkelvin; - if (max_temp && (!stats->max_temp || max_temp > stats->max_temp)) - stats->max_temp = max_temp; + max_temp.mkelvin = dp->maxtemp.mkelvin; + if (max_temp.mkelvin && (!stats->max_temp.mkelvin || max_temp.mkelvin > stats->max_temp.mkelvin)) + stats->max_temp.mkelvin = max_temp.mkelvin; - min_temp = dp->mintemp.mkelvin; - if (min_temp && (!stats->min_temp || min_temp < stats->min_temp)) - stats->min_temp = min_temp; + min_temp.mkelvin = dp->mintemp.mkelvin; + if (min_temp.mkelvin && (!stats->min_temp.mkelvin || min_temp.mkelvin < stats->min_temp.mkelvin)) + stats->min_temp.mkelvin = min_temp.mkelvin; - if (min_temp || max_temp) { - mean_temp = min_temp; - if (mean_temp) - mean_temp = (mean_temp + max_temp) / 2; + if (min_temp.mkelvin || max_temp.mkelvin) { + mean_temp.mkelvin = min_temp.mkelvin; + if (mean_temp.mkelvin) + mean_temp.mkelvin = (mean_temp.mkelvin + max_temp.mkelvin) / 2; else - mean_temp = max_temp; - stats->combined_temp += get_temp_units(mean_temp, NULL); + mean_temp.mkelvin = max_temp.mkelvin; + stats->combined_temp.mkelvin += mean_temp.mkelvin; stats->combined_count++; } } diff --git a/core/statistics.h b/core/statistics.h index 9f045c16c..48e75594d 100644 --- a/core/statistics.h +++ b/core/statistics.h @@ -28,9 +28,9 @@ typedef struct volume_t max_sac; volume_t min_sac; volume_t avg_sac; - int max_temp; - int min_temp; - double combined_temp; + temperature_t max_temp; + temperature_t min_temp; + temperature_sum_t combined_temp; unsigned int combined_count; unsigned int selection_size; unsigned int total_sac_time; diff --git a/core/units.h b/core/units.h index 21f646f79..e124826ce 100644 --- a/core/units.h +++ b/core/units.h @@ -110,6 +110,11 @@ typedef struct typedef struct { + uint64_t mkelvin; // up to 18446744073 MdegK (temperatures in K are always positive) +} temperature_sum_t; + +typedef struct +{ int mliter; } volume_t; |