summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Stefan Fuchs <sfuchs@gmx.de>2018-02-18 21:55:57 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-02-24 11:45:17 -0800
commit95a23cf4701d4918f866cb5ef1c25a5b2b380096 (patch)
treed4735ee6e8fe357483f88cab290e1749ad303656
parent928e7ed8694e49efdabe3502eef32c4519bf6b0c (diff)
downloadsubsurface-95a23cf4701d4918f866cb5ef1c25a5b2b380096.tar.gz
Use temperature_t for temperatures in struct stats_t
Use struct temperature_t for temperatures in struct stats_t and use get_temperature_string() when printing these temperatures for statistics and HTML export. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
-rw-r--r--core/divelogexportlogic.cpp13
-rw-r--r--core/statistics.c26
-rw-r--r--core/statistics.h6
-rw-r--r--core/units.h5
-rw-r--r--desktop-widgets/tab-widgets/TabDiveStatistics.cpp15
-rw-r--r--desktop-widgets/templatelayout.h8
-rw-r--r--profile-widget/diveprofileitem.cpp7
-rw-r--r--qt-models/yearlystatisticsmodel.cpp17
8 files changed, 48 insertions, 49 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;
diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp
index 0582ec930..cc7946a88 100644
--- a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp
@@ -71,15 +71,12 @@ void TabDiveStatistics::updateData()
else
ui->sacLimits->setAverage("");
- temperature_t temp;
- temp.mkelvin = stats_selection.max_temp;
- ui->tempLimits->setMaximum(get_temperature_string(temp, true));
- temp.mkelvin = stats_selection.min_temp;
- ui->tempLimits->setMinimum(get_temperature_string(temp, true));
- if (stats_selection.combined_temp && stats_selection.combined_count) {
- const char *unit;
- get_temp_units(0, &unit);
- ui->tempLimits->setAverage(QString("%1%2").arg(stats_selection.combined_temp / stats_selection.combined_count, 0, 'f', 1).arg(unit));
+ ui->tempLimits->setMaximum(get_temperature_string(stats_selection.max_temp, true));
+ ui->tempLimits->setMinimum(get_temperature_string(stats_selection.min_temp, true));
+ if (stats_selection.combined_temp.mkelvin && stats_selection.combined_count) {
+ temperature_t avg_temp;
+ avg_temp.mkelvin = stats_selection.combined_temp.mkelvin / stats_selection.combined_count;
+ ui->tempLimits->setAverage(get_temperature_string(avg_temp, true));
}
diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h
index cb60cc03d..6c3c079e4 100644
--- a/desktop-widgets/templatelayout.h
+++ b/desktop-widgets/templatelayout.h
@@ -104,13 +104,9 @@ if (property == "year") {
} else if (property == "dives") {
return object.year->selection_size;
} else if (property == "min_temp") {
- const char *unit;
- double temp = get_temp_units(object.year->min_temp, &unit);
- return object.year->min_temp == 0 ? "0" : QString::number(temp, 'g', 2) + unit;
+ return object.year->min_temp.mkelvin == 0 ? "0" : get_temperature_string(object.year->min_temp, true);
} else if (property == "max_temp") {
- const char *unit;
- double temp = get_temp_units(object.year->max_temp, &unit);
- return object.year->max_temp == 0 ? "0" : QString::number(temp, 'g', 2) + unit;
+ return object.year->max_temp.mkelvin == 0 ? "0" : get_temperature_string(object.year->max_temp, true);
} else if (property == "total_time") {
return get_dive_duration_string(object.year->total_time.seconds, QObject::tr("h"),
QObject::tr("min"), QObject::tr("sec"), " ");
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp
index 6352d5171..24edba4db 100644
--- a/profile-widget/diveprofileitem.cpp
+++ b/profile-widget/diveprofileitem.cpp
@@ -591,16 +591,15 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
void DiveTemperatureItem::createTextItem(int sec, int mkelvin)
{
- double deg;
- const char *unit;
- deg = get_temp_units(mkelvin, &unit);
+ temperature_t temp;
+ temp.mkelvin = mkelvin;
DiveTextItem *text = new DiveTextItem(this);
text->setAlignment(Qt::AlignRight | Qt::AlignBottom);
text->setBrush(getColor(TEMP_TEXT));
text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin)));
text->setScale(0.8); // need to call this BEFORE setText()
- text->setText(QString("%1%2").arg(deg, 0, 'f', 1).arg(unit));
+ text->setText(get_temperature_string(temp, true));
texts.append(text);
}
diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp
index 54941ac80..fbc65ccab 100644
--- a/qt-models/yearlystatisticsmodel.cpp
+++ b/qt-models/yearlystatisticsmodel.cpp
@@ -39,7 +39,6 @@ YearStatisticsItem::YearStatisticsItem(stats_t interval) : stats_interval(interv
QVariant YearStatisticsItem::data(int column, int role) const
{
- double value;
QVariant ret;
if (role == Qt::FontRole) {
@@ -91,19 +90,19 @@ QVariant YearStatisticsItem::data(int column, int role) const
ret = get_volume_string(stats_interval.max_sac);
break;
case AVG_TEMP:
- if (stats_interval.combined_temp && stats_interval.combined_count) {
- ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1);
+ if (stats_interval.combined_temp.mkelvin && stats_interval.combined_count) {
+ temperature_t avg_temp;
+ avg_temp.mkelvin = stats_interval.combined_temp.mkelvin / stats_interval.combined_count;
+ ret = get_temperature_string(avg_temp);
}
break;
case MIN_TEMP:
- value = get_temp_units(stats_interval.min_temp, NULL);
- if (value > -100.0)
- ret = QString::number(value, 'f', 1);
+ if (stats_interval.min_temp.mkelvin)
+ ret = get_temperature_string(stats_interval.min_temp);
break;
case MAX_TEMP:
- value = get_temp_units(stats_interval.max_temp, NULL);
- if (value > -100.0)
- ret = QString::number(value, 'f', 1);
+ if (stats_interval.max_temp.mkelvin)
+ ret = get_temperature_string(stats_interval.max_temp);
break;
}
return ret;