mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Creation of dive duration string and surface interval string
Update the function to create the dive duration string in a way that it can be used also in info and stats tab and added some more flexibility. Changed layout for <1h freedives to "0:05:35" (w/o units) or "5:35min" (with units and :) or "5min 35sec" (with units with space). Add a new function to create the surface interval string. Completely remove old function get_time_string() and get_time_string_s(). Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This commit is contained in:
parent
53a8075bd8
commit
e6d884cf26
13 changed files with 68 additions and 48 deletions
|
@ -52,7 +52,8 @@ static void exportHTMLstatisticsTotal(QTextStream &out, stats_t *total_stats)
|
||||||
out << "{";
|
out << "{";
|
||||||
out << "\"YEAR\":\"Total\",";
|
out << "\"YEAR\":\"Total\",";
|
||||||
out << "\"DIVES\":\"" << total_stats->selection_size << "\",";
|
out << "\"DIVES\":\"" << total_stats->selection_size << "\",";
|
||||||
out << "\"TOTAL_TIME\":\"" << get_time_string(total_stats->total_time.seconds, 0) << "\",";
|
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(total_stats->total_time.seconds,
|
||||||
|
QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\",";
|
||||||
out << "\"AVERAGE_TIME\":\"--\",";
|
out << "\"AVERAGE_TIME\":\"--\",";
|
||||||
out << "\"SHORTEST_TIME\":\"--\",";
|
out << "\"SHORTEST_TIME\":\"--\",";
|
||||||
out << "\"LONGEST_TIME\":\"--\",";
|
out << "\"LONGEST_TIME\":\"--\",";
|
||||||
|
@ -87,7 +88,8 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin
|
||||||
out << "{";
|
out << "{";
|
||||||
out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
|
out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
|
||||||
out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
|
out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
|
||||||
out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\",";
|
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats_yearly[i].total_time.seconds,
|
||||||
|
QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\",";
|
||||||
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
|
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
|
||||||
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
|
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
|
||||||
out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\",";
|
out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\",";
|
||||||
|
|
|
@ -36,7 +36,8 @@ int parseWeightToGrams(const QString &text);
|
||||||
int parsePressureToMbar(const QString &text);
|
int parsePressureToMbar(const QString &text);
|
||||||
int parseGasMixO2(const QString &text);
|
int parseGasMixO2(const QString &text);
|
||||||
int parseGasMixHE(const QString &text);
|
int parseGasMixHE(const QString &text);
|
||||||
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText = "", bool isFreeDive = false);
|
QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = QObject::tr("sec"), QString separator = ":", bool isFreeDive = false);
|
||||||
|
QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4);
|
||||||
QString get_dive_date_string(timestamp_t when);
|
QString get_dive_date_string(timestamp_t when);
|
||||||
QString get_short_dive_date_string(timestamp_t when);
|
QString get_short_dive_date_string(timestamp_t when);
|
||||||
bool is_same_day (timestamp_t trip_when, timestamp_t dive_when);
|
bool is_same_day (timestamp_t trip_when, timestamp_t dive_when);
|
||||||
|
|
|
@ -924,10 +924,10 @@ int parseGasMixHE(const QString &text)
|
||||||
return he;
|
return he;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText, bool isFreeDive)
|
QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText, QString separator, bool isFreeDive)
|
||||||
{
|
{
|
||||||
int hrs, mins, fullmins, secs;
|
int hrs, mins, fullmins, secs;
|
||||||
mins = (when + 59) / 60;
|
mins = (when + 30) / 60;
|
||||||
fullmins = when / 60;
|
fullmins = when / 60;
|
||||||
secs = when - 60 * fullmins;
|
secs = when - 60 * fullmins;
|
||||||
hrs = mins / 60;
|
hrs = mins / 60;
|
||||||
|
@ -935,15 +935,50 @@ QString get_dive_duration_string(timestamp_t when, QString hourText, QString min
|
||||||
QString displayTime;
|
QString displayTime;
|
||||||
if (prefs.units.duration_units == units::ALWAYS_HOURS || (prefs.units.duration_units == units::MIXED && hrs)) {
|
if (prefs.units.duration_units == units::ALWAYS_HOURS || (prefs.units.duration_units == units::MIXED && hrs)) {
|
||||||
mins -= hrs * 60;
|
mins -= hrs * 60;
|
||||||
displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(hourText == ":" ? "" : minutesText);
|
displayTime = QString("%1%2%3%4%5").arg(hrs).arg(separator == ":" ? "" : hoursText).arg(separator)
|
||||||
|
.arg(mins, 2, 10, QChar('0')).arg(separator == ":" ? hoursText : minutesText);
|
||||||
|
} else if (isFreeDive && ( prefs.units.duration_units == units::MINUTES_ONLY || minutesText != "" )) {
|
||||||
|
// Freedive <1h and we display no hours but only minutes for other dives
|
||||||
|
// --> display a short (5min 35sec) freedives e.g. as "5:35"
|
||||||
|
// Freedive <1h and we display a unit for minutes
|
||||||
|
// --> display a short (5min 35sec) freedives e.g. as "5:35min"
|
||||||
|
if (separator == ":") displayTime = QString("%1%2%3%4").arg(fullmins).arg(separator)
|
||||||
|
.arg(secs, 2, 10, QChar('0')).arg(minutesText);
|
||||||
|
else displayTime = QString("%1%2%3%4%5").arg(fullmins).arg(minutesText).arg(separator)
|
||||||
|
.arg(secs).arg(secondsText);
|
||||||
} else if (isFreeDive) {
|
} else if (isFreeDive) {
|
||||||
displayTime = QString("%1%2%3%4").arg(fullmins).arg(minutesText).arg(secs, 2, 10, QChar('0')).arg(secondsText);
|
// Mixed display (hh:mm / mm only) and freedive < 1h and we have no unit for minutes
|
||||||
|
// --> Prefix duration with "0:" --> "0:05:35"
|
||||||
|
if (separator == ":") displayTime = QString("%1%2%3%4%5%6").arg(hrs).arg(separator)
|
||||||
|
.arg(fullmins, 2, 10, QChar('0')).arg(separator)
|
||||||
|
.arg(secs, 2, 10, QChar('0')).arg(hoursText);
|
||||||
|
// Separator != ":" and no units for minutes --> unlikely case - remove?
|
||||||
|
else displayTime = QString("%1%2%3%4%5%6%7%8").arg(hrs).arg(hoursText).arg(separator)
|
||||||
|
.arg(fullmins).arg(minutesText).arg(separator)
|
||||||
|
.arg(secs).arg(secondsText);
|
||||||
} else {
|
} else {
|
||||||
displayTime = QString("%1%2").arg(mins).arg(hourText == ":" ? "" : minutesText);
|
displayTime = QString("%1%2").arg(mins).arg(minutesText);
|
||||||
}
|
}
|
||||||
return displayTime;
|
return displayTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator, int maxdays)
|
||||||
|
{
|
||||||
|
int days, hrs, mins;
|
||||||
|
days = when / 3600 / 24;
|
||||||
|
hrs = (when - days * 3600 * 24) / 3600;
|
||||||
|
mins = (when + 30 - days * 3600 * 24 - hrs * 3600) / 60;
|
||||||
|
|
||||||
|
QString displayInt;
|
||||||
|
if (maxdays && days > maxdays) displayInt = QString("more than %1 days").arg(maxdays);
|
||||||
|
else if (days) displayInt = QString("%1%2%3%4%5%6%7%8").arg(days).arg(daysText).arg(separator)
|
||||||
|
.arg(hrs).arg(hoursText).arg(separator)
|
||||||
|
.arg(mins).arg(minutesText);
|
||||||
|
else displayInt = QString("%1%2%3%4%5").arg(hrs).arg(hoursText).arg(separator)
|
||||||
|
.arg(mins).arg(minutesText);
|
||||||
|
return displayInt;
|
||||||
|
}
|
||||||
|
|
||||||
QString get_dive_date_string(timestamp_t when)
|
QString get_dive_date_string(timestamp_t when)
|
||||||
{
|
{
|
||||||
QDateTime ts;
|
QDateTime ts;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
/* statistics.c
|
/* statistics.c
|
||||||
*
|
*
|
||||||
* core logic for the Info & Stats page -
|
* core logic for the Info & Stats page -
|
||||||
* char *get_time_string(int seconds, int maxdays);
|
|
||||||
* char *get_minutes(int seconds);
|
* char *get_minutes(int seconds);
|
||||||
* void process_all_dives(struct dive *dive, struct dive **prev_dive);
|
* void process_all_dives(struct dive *dive, struct dive **prev_dive);
|
||||||
* void get_selected_dives_text(char *buffer, int size);
|
* void get_selected_dives_text(char *buffer, int size);
|
||||||
|
@ -236,27 +235,6 @@ void process_selected_dives(void)
|
||||||
stats_selection.selection_size = nr;
|
stats_selection.selection_size = nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_time_string_s(int seconds, int maxdays, bool freediving)
|
|
||||||
{
|
|
||||||
static char buf[80];
|
|
||||||
if (maxdays && seconds > 3600 * 24 * maxdays) {
|
|
||||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "more than %d days"), maxdays);
|
|
||||||
} else {
|
|
||||||
int days = seconds / 3600 / 24;
|
|
||||||
int hours = (seconds - days * 3600 * 24) / 3600;
|
|
||||||
int minutes = (seconds - days * 3600 * 24 - hours * 3600) / 60;
|
|
||||||
int secs = (seconds - days * 3600 * 24 - hours * 3600 - minutes*60);
|
|
||||||
if (days > 0)
|
|
||||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "%dd %dh %dmin"), days, hours, minutes);
|
|
||||||
else
|
|
||||||
if (freediving && seconds < 3600)
|
|
||||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "%dmin %dsecs"), minutes, secs);
|
|
||||||
else
|
|
||||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "%dh %dmin"), hours, minutes);
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this gets called when at least two but not all dives are selected */
|
/* this gets called when at least two but not all dives are selected */
|
||||||
static void get_ranges(char *buffer, int size)
|
static void get_ranges(char *buffer, int size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,6 @@ extern stats_t *stats_monthly;
|
||||||
extern stats_t *stats_by_trip;
|
extern stats_t *stats_by_trip;
|
||||||
extern stats_t *stats_by_type;
|
extern stats_t *stats_by_type;
|
||||||
|
|
||||||
extern char *get_time_string_s(int seconds, int maxdays, bool freediving);
|
|
||||||
extern char *get_minutes(int seconds);
|
extern char *get_minutes(int seconds);
|
||||||
extern void process_all_dives(struct dive *dive, struct dive **prev_dive);
|
extern void process_all_dives(struct dive *dive, struct dive **prev_dive);
|
||||||
extern void get_selected_dives_text(char *buffer, size_t size);
|
extern void get_selected_dives_text(char *buffer, size_t size);
|
||||||
|
@ -52,9 +51,6 @@ extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
|
||||||
extern void process_selected_dives(void);
|
extern void process_selected_dives(void);
|
||||||
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
|
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
|
||||||
|
|
||||||
inline char *get_time_string(int seconds, int maxdays) {
|
|
||||||
return get_time_string_s( seconds, maxdays, false);
|
|
||||||
}
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -124,7 +124,7 @@ QString DiveObjectHelper::gps_decimal() const
|
||||||
|
|
||||||
QString DiveObjectHelper::duration() const
|
QString DiveObjectHelper::duration() const
|
||||||
{
|
{
|
||||||
return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h:"), QObject::tr("min"));
|
return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h"), QObject::tr("min"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiveObjectHelper::noDive() const
|
bool DiveObjectHelper::noDive() const
|
||||||
|
|
|
@ -703,7 +703,7 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
|
||||||
case 0:
|
case 0:
|
||||||
return QVariant(get_short_dive_date_string(d->when));
|
return QVariant(get_short_dive_date_string(d->when));
|
||||||
case 1:
|
case 1:
|
||||||
return QVariant(get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min")));
|
return QVariant(get_dive_duration_string(d->duration.seconds, tr("h"), tr("min")));
|
||||||
case 2:
|
case 2:
|
||||||
return QVariant(get_depth_string(d->maxdepth.mm, true, false));
|
return QVariant(get_depth_string(d->maxdepth.mm, true, false));
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ void SocialNetworkDialog::selectionChanged()
|
||||||
}
|
}
|
||||||
if (ui->duration->isChecked()) {
|
if (ui->duration->isChecked()) {
|
||||||
fullText += tr("Duration: %1 \n").arg(get_dive_duration_string(d->duration.seconds,
|
fullText += tr("Duration: %1 \n").arg(get_dive_duration_string(d->duration.seconds,
|
||||||
tr("h:", "abbreviation for hours plus separator"),
|
tr("h", "abbreviation for hours"),
|
||||||
tr("min", "abbreviation for minutes")));
|
tr("min", "abbreviation for minutes")));
|
||||||
}
|
}
|
||||||
if (ui->Location->isChecked()) {
|
if (ui->Location->isChecked()) {
|
||||||
|
|
|
@ -74,15 +74,15 @@ void TabDiveInformation::updateData()
|
||||||
ui->gasUsedText->setText(volumes);
|
ui->gasUsedText->setText(volumes);
|
||||||
ui->oxygenHeliumText->setText(gaslist);
|
ui->oxygenHeliumText->setText(gaslist);
|
||||||
|
|
||||||
int sum = displayed_dive.dc.divemode != FREEDIVE ? 30 : 0;
|
ui->diveTimeText->setText(get_dive_duration_string(displayed_dive.duration.seconds, tr("h"), tr("min"), tr("sec"),
|
||||||
ui->diveTimeText->setText(get_time_string_s(displayed_dive.duration.seconds + sum, 0, false));
|
" ", displayed_dive.dc.divemode == FREEDIVE));
|
||||||
|
|
||||||
struct dive *prevd;
|
struct dive *prevd;
|
||||||
process_all_dives(&displayed_dive, &prevd);
|
process_all_dives(&displayed_dive, &prevd);
|
||||||
|
|
||||||
if (prevd)
|
if (prevd)
|
||||||
ui->surfaceIntervalText->setText(get_time_string_s(displayed_dive.when - (prevd->when + prevd->duration.seconds), 4,
|
ui->surfaceIntervalText->setText(get_dive_surfint_string(displayed_dive.when - (prevd->when + prevd->duration.seconds), tr("d"), tr("h"), tr("min")));
|
||||||
(displayed_dive.dc.divemode == FREEDIVE)));
|
|
||||||
else
|
else
|
||||||
ui->surfaceIntervalText->clear();
|
ui->surfaceIntervalText->clear();
|
||||||
|
|
||||||
|
|
|
@ -84,14 +84,19 @@ void TabDiveStatistics::updateData()
|
||||||
|
|
||||||
|
|
||||||
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
|
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
|
||||||
ui->totalTimeAllText->setText(get_time_string_s(stats_selection.total_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE)));
|
ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"),
|
||||||
|
" ", displayed_dive.dc.divemode == FREEDIVE));
|
||||||
|
|
||||||
int seconds = stats_selection.total_time.seconds;
|
int seconds = stats_selection.total_time.seconds;
|
||||||
if (stats_selection.selection_size)
|
if (stats_selection.selection_size)
|
||||||
seconds /= stats_selection.selection_size;
|
seconds /= stats_selection.selection_size;
|
||||||
ui->timeLimits->setAverage(get_time_string_s(seconds, 0,(displayed_dive.dc.divemode == FREEDIVE)));
|
ui->timeLimits->setAverage(get_dive_duration_string(seconds, tr("h"), tr("min"), tr("sec"),
|
||||||
|
" ", displayed_dive.dc.divemode == FREEDIVE));
|
||||||
if (amount_selected > 1) {
|
if (amount_selected > 1) {
|
||||||
ui->timeLimits->setMaximum(get_time_string_s(stats_selection.longest_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE)));
|
ui->timeLimits->setMaximum(get_dive_duration_string(stats_selection.longest_time.seconds, tr("h"), tr("min"), tr("sec"),
|
||||||
ui->timeLimits->setMinimum(get_time_string_s(stats_selection.shortest_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE)));
|
" ", displayed_dive.dc.divemode == FREEDIVE));
|
||||||
|
ui->timeLimits->setMinimum(get_dive_duration_string(stats_selection.shortest_time.seconds, tr("h"), tr("min"), tr("sec"),
|
||||||
|
" ", displayed_dive.dc.divemode == FREEDIVE));
|
||||||
} else {
|
} else {
|
||||||
ui->timeLimits->setMaximum("");
|
ui->timeLimits->setMaximum("");
|
||||||
ui->timeLimits->setMinimum("");
|
ui->timeLimits->setMinimum("");
|
||||||
|
|
|
@ -109,7 +109,8 @@ if (property == "year") {
|
||||||
double temp = get_temp_units(object.year->max_temp, &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 == 0 ? "0" : QString::number(temp, 'g', 2) + unit;
|
||||||
} else if (property == "total_time") {
|
} else if (property == "total_time") {
|
||||||
return get_time_string(object.year->total_time.seconds, 0);
|
return get_dive_duration_string(object.year->total_time.seconds, QObject::tr("h"),
|
||||||
|
QObject::tr("min"), QObject::tr("sec"), " ");
|
||||||
} else if (property == "avg_time") {
|
} else if (property == "avg_time") {
|
||||||
return get_minutes(object.year->total_time.seconds / object.year->selection_size);
|
return get_minutes(object.year->total_time.seconds / object.year->selection_size);
|
||||||
} else if (property == "shortest_time") {
|
} else if (property == "shortest_time") {
|
||||||
|
|
|
@ -343,7 +343,9 @@ int DiveItem::countPhotos(dive *dive) const
|
||||||
QString DiveItem::displayDuration() const
|
QString DiveItem::displayDuration() const
|
||||||
{
|
{
|
||||||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||||
return get_dive_duration_string(dive->duration.seconds, ":", "m", "s", dive->dc.divemode == FREEDIVE);
|
return get_dive_duration_string(dive->duration.seconds, "", "", "", ":", dive->dc.divemode == FREEDIVE);
|
||||||
|
// Next line is test for alternative display with units
|
||||||
|
// return get_dive_duration_string(dive->duration.seconds, tr("h"), tr("min"), "", ":", dive->dc.divemode == FREEDIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiveItem::displayTemperature() const
|
QString DiveItem::displayTemperature() const
|
||||||
|
|
|
@ -61,7 +61,7 @@ QVariant YearStatisticsItem::data(int column, int role) const
|
||||||
ret = stats_interval.selection_size;
|
ret = stats_interval.selection_size;
|
||||||
break;
|
break;
|
||||||
case TOTAL_TIME:
|
case TOTAL_TIME:
|
||||||
ret = get_time_string(stats_interval.total_time.seconds, 0);
|
ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ");
|
||||||
break;
|
break;
|
||||||
case AVERAGE_TIME:
|
case AVERAGE_TIME:
|
||||||
ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size);
|
ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size);
|
||||||
|
|
Loading…
Add table
Reference in a new issue