Пример #1
0
QList<SummaryMetrics> DBAccess::getAllMetricsFor(QDateTime start, QDateTime end)
{
    QList<SummaryMetrics> metrics;
    
    
    QSqlQuery query("SELECT filename, ride_date, ride_time, average_cad, workout_time, total_distance," 
                    "x_power, average_speed, total_work, average_power, average_hr,"
                    "relative_intensity, bike_scoreFROM metrics WHERE ride_date >=:start AND ride_date <=:end");
    query.bindValue(":start", start);
    query.bindValue(":end", end);
    
    while(query.next())
    {
 
        SummaryMetrics summaryMetrics;
        summaryMetrics.setFileName(query.value(0).toString());
        summaryMetrics.setRideDate(query.value(1).toDateTime());
        summaryMetrics.setRideTime(query.value(2).toDouble());
        summaryMetrics.setCadence(query.value(3).toDouble());
        summaryMetrics.setWorkoutTime(query.value(4).toDouble());
        summaryMetrics.setDistance(query.value(5).toDouble());
        summaryMetrics.setXPower(query.value(6).toDouble());
        summaryMetrics.setSpeed(query.value(7).toDouble());
        summaryMetrics.setTotalWork(query.value(8).toDouble());
        summaryMetrics.setWatts(query.value(9).toDouble());
        summaryMetrics.setHeartRate(query.value(10).toDouble());
        summaryMetrics.setRelativeIntensity(query.value(11).toDouble());
        summaryMetrics.setBikeScore(query.value(12).toDouble());        
            
        metrics << summaryMetrics;
    }
                    
    return metrics;
}
Пример #2
0
bool MetricAggregator::importRide(QDir path, RideFile *ride, QString fileName, unsigned long fingerprint, bool modify)
{
    SummaryMetrics *summaryMetric = new SummaryMetrics();
    QFile file(path.absolutePath() + "/" + fileName);

    QRegExp rx = RideFileFactory::instance().rideFileRegExp();
    if (!rx.exactMatch(fileName)) {
        return false; // not a ridefile!
    }
    summaryMetric->setFileName(fileName);
    assert(rx.numCaptures() == 7);
    QDate date(rx.cap(1).toInt(), rx.cap(2).toInt(),rx.cap(3).toInt());
    QTime time(rx.cap(4).toInt(), rx.cap(5).toInt(),rx.cap(6).toInt());
    QDateTime dateTime(date, time);

    summaryMetric->setRideDate(dateTime);
    summaryMetric->setId(ride->id());

    const RideMetricFactory &factory = RideMetricFactory::instance();
    QStringList metrics;

    for (int i = 0; i < factory.metricCount(); ++i)
        metrics << factory.metricName(i);

    // compute all the metrics
    QHash<QString, RideMetricPtr> computed = RideMetric::computeMetrics(main, ride, zones, hrzones, metrics);

    // get metrics into summaryMetric QMap
    for(int i = 0; i < factory.metricCount(); ++i) {
        // check for override
        summaryMetric->setForSymbol(factory.metricName(i), computed.value(factory.metricName(i))->value(true));
    }

    // what color will this ride be?
    QColor color = colorEngine->colorFor(ride->getTag(main->rideMetadata()->getColorField(), ""));

    dbaccess->importRide(summaryMetric, ride, color, fingerprint, modify);
#ifdef GC_HAVE_LUCENE
    main->lucene->importRide(summaryMetric, ride, color, fingerprint, modify);
#endif
    delete summaryMetric;

    return true;
}