~ubuntu-branches/ubuntu/vivid/goldencheetah/vivid-proposed

« back to all changes in this revision

Viewing changes to src/PwxRideFile.cpp

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-12-25 10:30:44 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131225103044-11ttdb8r9us31lpn
Tags: 3.0.1-1
* New upstream release.
  Use dirstributed tarball to build. (Closes: #711722)
* New Standards-Version: 3.9.5
* remove qwt-format patch (merged at upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "Settings.h"
21
21
#include <QDomDocument>
22
22
#include <QVector>
23
 
#include <assert.h>
24
23
 
25
24
#include <QDebug>
26
25
 
172
171
                }
173
172
            }
174
173
 
175
 
        // data points: offset, hr, spd, pwr, torq, cad, dist, lat, lon, alt (ignored: temp, time)
 
174
        // data points: offset, hr, spd, pwr, torq, cad, dist, lat, lon, alt, temp
176
175
        } else if (node.nodeName() == "sample") {
177
176
            RideFilePoint add;
178
177
 
222
221
            QDomElement alt = node.firstChildElement("alt");
223
222
            if (!alt.isNull()) add.alt = alt.text().toDouble();
224
223
            else add.alt = 0.0;
 
224
            // temp
 
225
            QDomElement temp = node.firstChildElement("temp");
 
226
            if (!temp.isNull()) add.temp = temp.text().toDouble();
 
227
            else add.temp = 0.0;
225
228
 
226
229
            // do we need to calculate distance?
227
230
            if (add.km == 0.0 && samples) {
394
397
    QDomElement summarydata = doc.createElement("summarydata");
395
398
    root.appendChild(summarydata);
396
399
    QDomElement beginning = doc.createElement("beginning");
397
 
    text = doc.createTextNode(QString("%1").arg(ride->dataPoints().first()->secs));
 
400
    text = doc.createTextNode(QString("%1").arg(ride->dataPoints().empty()
 
401
        ? 0 : ride->dataPoints().first()->secs));
398
402
    beginning.appendChild(text);
399
403
    summarydata.appendChild(beginning);
400
404
 
401
405
    QDomElement duration = doc.createElement("duration");
402
 
    text = doc.createTextNode(QString("%1").arg(ride->dataPoints().last()->secs));
 
406
    text = doc.createTextNode(QString("%1").arg(ride->dataPoints().empty()
 
407
        ? 0 : ride->dataPoints().last()->secs));
403
408
    duration.appendChild(text);
404
409
    summarydata.appendChild(duration);
405
410
 
441
446
        summarydata.appendChild(s);
442
447
    }
443
448
    QDomElement dist = doc.createElement("dist");
444
 
    text = doc.createTextNode(QString("%1").arg((int)(ride->dataPoints().last()->km * 1000)));
 
449
    text = doc.createTextNode(QString("%1")
 
450
        .arg((int)(ride->dataPoints().empty() ? 0
 
451
            : ride->dataPoints().last()->km * 1000)));
445
452
    dist.appendChild(text);
446
453
    summarydata.appendChild(dist);
447
454
 
453
460
        summarydata.appendChild(s);
454
461
    }
455
462
 
 
463
    if (ride->areDataPresent()->temp) {
 
464
        QDomElement s = doc.createElement("temp");
 
465
        s.setAttribute("max", "0");
 
466
        s.setAttribute("min", "0");
 
467
        s.setAttribute("avg", "0");
 
468
        summarydata.appendChild(s);
 
469
    }
 
470
 
456
471
    // interval "segments"
457
 
    if (!ride->intervals().empty()) {
458
 
        foreach (RideFileInterval i, ride->intervals()) {
459
 
            QDomElement segment = doc.createElement("segment");
460
 
            root.appendChild(segment);
461
 
 
462
 
            // name
463
 
            QDomElement name = doc.createElement("name");
464
 
            text = doc.createTextNode(i.name); name.appendChild(text);
465
 
            segment.appendChild(name);
466
 
 
467
 
            // summarydata
468
 
            QDomElement summarydata = doc.createElement("summarydata");
469
 
            segment.appendChild(summarydata);
470
 
 
471
 
            // beginning
472
 
            QDomElement beginning = doc.createElement("beginning");
473
 
            text = doc.createTextNode(QString("%1").arg(i.start));
474
 
            beginning.appendChild(text);
475
 
            summarydata.appendChild(beginning);
476
 
 
477
 
            // duration
478
 
            QDomElement duration = doc.createElement("duration");
479
 
            text = doc.createTextNode(QString("%1").arg(i.stop - i.start));
480
 
            duration.appendChild(text);
481
 
            summarydata.appendChild(duration);
482
 
        }
 
472
    foreach (RideFileInterval i, ride->intervals()) {
 
473
        QDomElement segment = doc.createElement("segment");
 
474
        root.appendChild(segment);
 
475
 
 
476
        // name
 
477
        QDomElement name = doc.createElement("name");
 
478
        text = doc.createTextNode(i.name); name.appendChild(text);
 
479
        segment.appendChild(name);
 
480
 
 
481
        // summarydata
 
482
        QDomElement summarydata = doc.createElement("summarydata");
 
483
        segment.appendChild(summarydata);
 
484
 
 
485
        // beginning
 
486
        QDomElement beginning = doc.createElement("beginning");
 
487
        text = doc.createTextNode(QString("%1").arg(i.start));
 
488
        beginning.appendChild(text);
 
489
        summarydata.appendChild(beginning);
 
490
 
 
491
        // duration
 
492
        QDomElement duration = doc.createElement("duration");
 
493
        text = doc.createTextNode(QString("%1").arg(i.stop - i.start));
 
494
        duration.appendChild(text);
 
495
        summarydata.appendChild(duration);
483
496
    }
484
497
 
485
498
    // samples
486
499
    // data points: timeoffset, dist, hr, spd, pwr, torq, cad, lat, lon, alt
487
500
    if (!ride->dataPoints().empty()) {
 
501
        int secs = 0;
 
502
 
488
503
        foreach (const RideFilePoint *point, ride->dataPoints()) {
 
504
            // if there was a gap, log time when this sample started:
 
505
            if( secs + ride->recIntSecs() < point->secs ){
 
506
                QDomElement sample = doc.createElement("sample");
 
507
                root.appendChild(sample);
 
508
 
 
509
                QDomElement timeoffset = doc.createElement("timeoffset");
 
510
                text = doc.createTextNode(QString("%1")
 
511
                    .arg(point->secs - ride->recIntSecs() ));
 
512
                timeoffset.appendChild(text);
 
513
                sample.appendChild(timeoffset);
 
514
            }
 
515
 
489
516
            QDomElement sample = doc.createElement("sample");
490
517
            root.appendChild(sample);
491
518
 
492
519
            // time
493
520
            QDomElement timeoffset = doc.createElement("timeoffset");
494
 
            text = doc.createTextNode(QString("%1").arg((int)point->secs));
 
521
            text = doc.createTextNode(QString("%1").arg(point->secs));
495
522
            timeoffset.appendChild(text);
496
523
            sample.appendChild(timeoffset);
497
524
 
539
566
 
540
567
            // distance - meters
541
568
            QDomElement dist = doc.createElement("dist");
542
 
            text = doc.createTextNode(QString("%1").arg((int)(point->km*1000)));
 
569
            text = doc.createTextNode(QString("%1").arg((point->km*1000)));
543
570
            dist.appendChild(text);
544
571
            sample.appendChild(dist);
545
572
 
566
593
                alt.appendChild(text);
567
594
                sample.appendChild(alt);
568
595
            }
 
596
 
 
597
            // temp
 
598
            if (ride->areDataPresent()->temp) {
 
599
                QDomElement temp = doc.createElement("temp");
 
600
                text = doc.createTextNode(QString("%1").arg(point->temp));
 
601
                temp.appendChild(text);
 
602
                sample.appendChild(temp);
 
603
            }
569
604
        }
570
605
    }
571
606