6 Status::Status(JourneyModel
&journeymodel
, QObject
*parent
) : QObject(parent
),
9 journeymodel(journeymodel
)
14 bool Status::getCycling() const {
18 quint64
Status::getStartTime() const {
22 quint64
Status::getDuration() const {
23 return (QDateTime::currentMSecsSinceEpoch() - startTime
) / 1000;
26 void Status::setCycling(bool value
) {
28 emit
cyclingChanged(cycling
);
31 void Status::setStartTime(quint64 value
) {
33 emit
startTimeChanged(startTime
);
36 void Status::startJourney() {
38 setStartTime(QDateTime::currentMSecsSinceEpoch());
41 quint64
Status::getJourneyCount() const {
42 return journeymodel
.rowCount();
45 quint64
Status::getTimeSpentCycling() const {
47 QList
<Journey
> const & journeys
= journeymodel
.getData();
50 foreach(Journey journey
, journeys
) {
51 time
+= journey
.getDuration();
57 double Status::getAverageDuration() const {
58 quint64 time
= getTimeSpentCycling();
59 quint64 count
= Status::getJourneyCount();
63 average
= ((double)time
/ (double)count
);
72 double Status::getSpeedPercentile() const {
75 QList
<Journey
> const & journeys
= journeymodel
.getData();
80 foreach(Journey journey
, journeys
) {
81 overtook
+= journey
.getOvertook();
82 overtakenby
+= journey
.getOvertakenBy();
85 if (overtook
+ overtakenby
> 0.0) {
86 percentile
= (double)overtook
/ (double)(overtook
+ overtakenby
);
95 QString
Status::getFormattedTime(quint64 seconds
, int min
, int max
) {
96 static const QString plural
[5] = {"s", "m", "h", "d", "y"};
97 static const QString singular
[5] = {"s", "m", "h", "d", "y"};
98 static const quint64 base
[5] = {60, 60, 24, 365, (quint64
)-1};
102 QList
<quint64
> portions
;
104 min
= qBound(0, min
, static_cast<int>(sizeof(base
)));
105 max
= qBound(0, max
, static_cast<int>(sizeof(base
)));
108 for (int unit
= 0; unit
< max
; unit
++) {
109 portion
= (unit
== max
- 1) ? remaining
: remaining
% base
[unit
];
111 remaining
/= base
[unit
];
115 for (int unit
= max
- 1; unit
>= min
; unit
--) {
116 portion
= portions
[unit
];
119 if (formatted
.length() > 0) {
122 formatted
+= QString::number(portion
) + " " + ((portion
== 1) ? singular
[unit
] : plural
[unit
]);
126 if (formatted
== "") {
133 QList
<float> Status::getGraphData() {
134 static QList
<float> data({0.1, 0.2, 0.3, 0.4, 1.0, 0.8, 0.7, 0.9, 0.5, 1.0});