2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/yearlystatisticsmodel.h"
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "core/qthelper.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/metrics.h"
|
|
|
|
#include "core/statistics.h"
|
2015-05-28 21:12:11 +00:00
|
|
|
|
|
|
|
class YearStatisticsItem : public TreeItem {
|
2018-09-14 19:25:00 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(YearStatisticsItem)
|
2015-05-28 21:12:11 +00:00
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
YEAR,
|
|
|
|
DIVES,
|
|
|
|
TOTAL_TIME,
|
|
|
|
AVERAGE_TIME,
|
|
|
|
SHORTEST_TIME,
|
|
|
|
LONGEST_TIME,
|
|
|
|
AVG_DEPTH,
|
|
|
|
MIN_DEPTH,
|
|
|
|
MAX_DEPTH,
|
|
|
|
AVG_SAC,
|
|
|
|
MIN_SAC,
|
|
|
|
MAX_SAC,
|
|
|
|
AVG_TEMP,
|
|
|
|
MIN_TEMP,
|
|
|
|
MAX_TEMP,
|
|
|
|
COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const;
|
|
|
|
YearStatisticsItem(stats_t interval);
|
|
|
|
|
|
|
|
private:
|
|
|
|
stats_t stats_interval;
|
|
|
|
};
|
|
|
|
|
|
|
|
YearStatisticsItem::YearStatisticsItem(stats_t interval) : stats_interval(interval)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant YearStatisticsItem::data(int column, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
|
|
|
|
|
|
|
if (role == Qt::FontRole) {
|
|
|
|
QFont font = defaultModelFont();
|
|
|
|
font.setBold(stats_interval.is_year);
|
|
|
|
return font;
|
|
|
|
} else if (role != Qt::DisplayRole) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
switch (column) {
|
|
|
|
case YEAR:
|
|
|
|
if (stats_interval.is_trip) {
|
|
|
|
ret = stats_interval.location;
|
|
|
|
} else {
|
|
|
|
ret = stats_interval.period;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIVES:
|
|
|
|
ret = stats_interval.selection_size;
|
|
|
|
break;
|
|
|
|
case TOTAL_TIME:
|
2017-05-11 20:43:36 +00:00
|
|
|
ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ");
|
2015-05-28 21:12:11 +00:00
|
|
|
break;
|
|
|
|
case AVERAGE_TIME:
|
|
|
|
ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size);
|
|
|
|
break;
|
|
|
|
case SHORTEST_TIME:
|
|
|
|
ret = get_minutes(stats_interval.shortest_time.seconds);
|
|
|
|
break;
|
|
|
|
case LONGEST_TIME:
|
|
|
|
ret = get_minutes(stats_interval.longest_time.seconds);
|
|
|
|
break;
|
|
|
|
case AVG_DEPTH:
|
|
|
|
ret = get_depth_string(stats_interval.avg_depth);
|
|
|
|
break;
|
|
|
|
case MIN_DEPTH:
|
|
|
|
ret = get_depth_string(stats_interval.min_depth);
|
|
|
|
break;
|
|
|
|
case MAX_DEPTH:
|
|
|
|
ret = get_depth_string(stats_interval.max_depth);
|
|
|
|
break;
|
|
|
|
case AVG_SAC:
|
|
|
|
ret = get_volume_string(stats_interval.avg_sac);
|
|
|
|
break;
|
|
|
|
case MIN_SAC:
|
|
|
|
ret = get_volume_string(stats_interval.min_sac);
|
|
|
|
break;
|
|
|
|
case MAX_SAC:
|
|
|
|
ret = get_volume_string(stats_interval.max_sac);
|
|
|
|
break;
|
|
|
|
case AVG_TEMP:
|
2018-02-18 20:55:57 +00:00
|
|
|
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);
|
2015-05-28 21:12:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MIN_TEMP:
|
2018-02-18 20:55:57 +00:00
|
|
|
if (stats_interval.min_temp.mkelvin)
|
|
|
|
ret = get_temperature_string(stats_interval.min_temp);
|
2015-05-28 21:12:11 +00:00
|
|
|
break;
|
|
|
|
case MAX_TEMP:
|
2018-02-18 20:55:57 +00:00
|
|
|
if (stats_interval.max_temp.mkelvin)
|
|
|
|
ret = get_temperature_string(stats_interval.max_temp);
|
2015-05-28 21:12:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:43:20 +00:00
|
|
|
YearlyStatisticsModel::YearlyStatisticsModel(QObject *parent) : TreeModel(parent)
|
2015-05-28 21:12:11 +00:00
|
|
|
{
|
|
|
|
columns = COLUMNS;
|
|
|
|
update_yearly_stats();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
QVariant val;
|
|
|
|
if (role == Qt::FontRole)
|
|
|
|
val = defaultModelFont();
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
|
|
|
switch (section) {
|
|
|
|
case YEAR:
|
|
|
|
val = tr("Year \n > Month / Trip");
|
|
|
|
break;
|
|
|
|
case DIVES:
|
|
|
|
val = tr("#");
|
|
|
|
break;
|
|
|
|
case TOTAL_TIME:
|
|
|
|
val = tr("Duration \n Total");
|
|
|
|
break;
|
|
|
|
case AVERAGE_TIME:
|
|
|
|
val = tr("\nAverage");
|
|
|
|
break;
|
|
|
|
case SHORTEST_TIME:
|
|
|
|
val = tr("\nShortest");
|
|
|
|
break;
|
|
|
|
case LONGEST_TIME:
|
|
|
|
val = tr("\nLongest");
|
|
|
|
break;
|
|
|
|
case AVG_DEPTH:
|
|
|
|
val = QString(tr("Depth (%1)\n Average")).arg(get_depth_unit());
|
|
|
|
break;
|
|
|
|
case MIN_DEPTH:
|
|
|
|
val = tr("\nMinimum");
|
|
|
|
break;
|
|
|
|
case MAX_DEPTH:
|
|
|
|
val = tr("\nMaximum");
|
|
|
|
break;
|
|
|
|
case AVG_SAC:
|
|
|
|
val = QString(tr("SAC (%1)\n Average")).arg(get_volume_unit());
|
|
|
|
break;
|
|
|
|
case MIN_SAC:
|
|
|
|
val = tr("\nMinimum");
|
|
|
|
break;
|
|
|
|
case MAX_SAC:
|
|
|
|
val = tr("\nMaximum");
|
|
|
|
break;
|
|
|
|
case AVG_TEMP:
|
|
|
|
val = QString(tr("Temp. (%1)\n Average").arg(get_temp_unit()));
|
|
|
|
break;
|
|
|
|
case MIN_TEMP:
|
|
|
|
val = tr("\nMinimum");
|
|
|
|
break;
|
|
|
|
case MAX_TEMP:
|
|
|
|
val = tr("\nMaximum");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void YearlyStatisticsModel::update_yearly_stats()
|
|
|
|
{
|
|
|
|
int i, month = 0;
|
|
|
|
unsigned int j, combined_months;
|
2018-10-06 08:58:12 +00:00
|
|
|
stats_summary_auto_free stats;
|
2018-10-06 14:50:46 +00:00
|
|
|
calculate_stats_summary(&stats, false);
|
2015-05-28 21:12:11 +00:00
|
|
|
|
2018-10-06 08:58:12 +00:00
|
|
|
for (i = 0; stats.stats_yearly != NULL && stats.stats_yearly[i].period; ++i) {
|
|
|
|
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_yearly[i]);
|
2015-05-28 21:12:11 +00:00
|
|
|
combined_months = 0;
|
2018-10-06 08:58:12 +00:00
|
|
|
for (j = 0; combined_months < stats.stats_yearly[i].selection_size; ++j) {
|
|
|
|
combined_months += stats.stats_monthly[month].selection_size;
|
|
|
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_monthly[month]);
|
2015-05-28 21:12:11 +00:00
|
|
|
item->children.append(iChild);
|
|
|
|
iChild->parent = item;
|
|
|
|
month++;
|
|
|
|
}
|
|
|
|
rootItem->children.append(item);
|
2018-07-25 19:23:19 +00:00
|
|
|
item->parent = rootItem.get();
|
2015-05-28 21:12:11 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 08:58:12 +00:00
|
|
|
if (stats.stats_by_trip != NULL && stats.stats_by_trip[0].is_trip == true) {
|
|
|
|
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_by_trip[0]);
|
|
|
|
for (i = 1; stats.stats_by_trip != NULL && stats.stats_by_trip[i].is_trip; ++i) {
|
|
|
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_by_trip[i]);
|
2015-05-28 21:12:11 +00:00
|
|
|
item->children.append(iChild);
|
|
|
|
iChild->parent = item;
|
|
|
|
}
|
|
|
|
rootItem->children.append(item);
|
2018-07-25 19:23:19 +00:00
|
|
|
item->parent = rootItem.get();
|
2015-05-28 21:12:11 +00:00
|
|
|
}
|
2016-01-17 19:18:36 +00:00
|
|
|
|
|
|
|
/* Show the statistic sorted by dive type */
|
2018-10-06 08:58:12 +00:00
|
|
|
if (stats.stats_by_type != NULL && stats.stats_by_type[0].selection_size) {
|
|
|
|
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_by_type[0]);
|
2018-05-08 14:24:51 +00:00
|
|
|
for (i = 1; i <= NUM_DIVEMODE; ++i) {
|
2018-10-06 08:58:12 +00:00
|
|
|
if (stats.stats_by_type[i].selection_size == 0)
|
2016-01-17 19:18:36 +00:00
|
|
|
continue;
|
2018-10-06 08:58:12 +00:00
|
|
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_by_type[i]);
|
2016-01-17 19:18:36 +00:00
|
|
|
item->children.append(iChild);
|
|
|
|
iChild->parent = item;
|
|
|
|
}
|
|
|
|
rootItem->children.append(item);
|
2018-07-25 19:23:19 +00:00
|
|
|
item->parent = rootItem.get();
|
2016-01-17 19:18:36 +00:00
|
|
|
}
|
2015-05-28 21:12:11 +00:00
|
|
|
}
|