Exemplo n.º 1
0
void
ZeoDownload::downloadFinished(QNetworkReply *reply)
{
    if (dates.empty()) {
        // We have to build a list of dates
        QString response = reply->readAll();
        //qDebug() << "response " << response;

        QScriptValue sc;
        QScriptEngine se;

        sc = se.evaluate("("+response+")").property("response").property("dateList").property("date");
        int length = sc.property("length").toInteger();

        dates.clear();
        for (int i=0;i<length;i++) {
            QString day = sc.property(i).property("day").toString();
            QString month = sc.property(i).property("month").toString();
            QString year = sc.property(i).property("year").toString();

            dates.append(QDate(year.toInt(), month.toInt(), day.toInt()));
        }
        allMeasures = dates.count();
    } else {
        // We have to read data for the date
        QString response = reply->readAll();
        //qDebug() << "response2 " << response;

        QScriptValue sc;
        QScriptEngine se;

        sc = se.evaluate("("+response+")").property("response").property("sleepStats");
        QString zq = sc.property("zq").toString();

        int deep = sc.property("timeInDeep").toInteger();
        int light = sc.property("timeInLight").toInteger();
        int rem = sc.property("timeInRem").toInteger();
        int time = deep + light + rem;

        if (dates.first() > QDate().addMonths(-1)) {
            //qDebug() << dates.first() << zq;

            SummaryMetrics add;
            add.setDateTime(QDateTime(dates.first(), QTime(0,0,0)));
            add.setText("Sleep index (ZQ)", QString("%1").arg(zq));
            add.setText("Sleep time", QString("%1").arg(time));
            context->athlete->metricDB->importMeasure(&add);
        }

        dates.removeFirst();
    }

    if (!nextDate()) {
        QString status = QString(tr("%1 new on %2 measurements received.")).arg(newMeasures).arg(allMeasures);
        QMessageBox::information(context->mainWindow, tr("Zeo Data Download"), status);
    }
    return;
}
Exemplo n.º 2
0
QString TwitterDialog::metricToString(const RideMetric *m, SummaryMetrics &metrics, bool metricUnits)
{
    QString s = "%1%2";
    if (m->units(metricUnits) == "seconds" || m->units(metricUnits) == tr("seconds")) {
        s = s.arg(time_to_string(metrics.getForSymbol(m->symbol())));
        s = s.arg(""); // no units
    } else {
        s = s.arg(metrics.getForSymbol(m->symbol()) * (metricUnits ? 1 : m->conversion()), 0, 'f', m->precision() + (metricUnits ? 0 : m->conversionSum()));
        s = s.arg(m->units(metricUnits));
    }
    return s;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
bool
ZeoDownload::nextDate()
{
    if (!dates.empty()) {
        bool present = false;
        QDate date = dates.first();
        QString dateStr = date.toString("yyyy-MM-dd");

        QDateTime dateTime = QDateTime(date, QTime(0,0,0));
        QList<SummaryMetrics> list = context->athlete->metricDB->getAllMeasuresFor(dateTime,dateTime);
        for (int i=0;i<list.size();i++) {
            SummaryMetrics sm = list.at(i);
            if (sm.getText("Sleep time", "").length()>0 && sm.getText("Sleep index (ZQ)", "").length()>0) {
                present = true;
                dates.removeFirst();
                return nextDate();
            }
        }

        if (!present) {
            newMeasures ++;
            // Build the URL to retrieve the stats for date
            QString url = appsettings->cvalue(context->athlete->cyclist, GC_ZEOURL, "http://app-pro.myzeo.com:8080").toString() + base_api_url + "getSleepStatsForDate" + "?key=" + api_key + "&date=" + dateStr;
            QNetworkRequest request = QNetworkRequest(QUrl(url));
            request.setRawHeader("Authorization", "Basic " + usernameAndPasswordEncoded.toLatin1());
            request.setRawHeader("Referer" , "http://www.goldencheetah.org");
            request.setRawHeader("Accept" , "application/json");

            QNetworkReply *reply = nam->get(request);

            if (reply->error() != QNetworkReply::NoError) {
                QMessageBox::warning(context->mainWindow, tr("Zeo Data Download"), reply->errorString());
            } else
                return true;
        }
    }

    return false;
}
Exemplo n.º 5
0
void
GcBubble::setText(QString filename)
{
        SummaryMetrics metrics = parent->metricDB->getAllMetricsFor(filename);
	
        useMetricUnits = mainWindow->useMetricUnits;
    

        //
        // Workout code
        //
        QString wcode = metrics.getText("Workout Code", "");
        if (wcode != "") {
            topleft->setText(wcode);
            topleft->show();
        } else {
            topleft->hide();
        }


        //
        // Sport
        //
        QString sport = metrics.getText("Sport", "");
        if (sport != "") {
            topright->setText(sport);
            topright->show();
        } else {
            topright->hide();
        }

        swim->hide();
        run->hide();
        bike->hide();

        // icons instead of text?
        if (sport == "Bike") { bike->show(); topright->hide(); }
        if (sport == "Swim") { swim->show(); topright->hide(); }
        if (sport == "Run") { run->show(); topright->hide(); }

        //
        // Ride Date
        // 
        QDateTime rideDate = metrics.getRideDate();
        topmiddle->setText(rideDate.toString("MMM d, yyyy")); // same format as ride list
        topmiddle2->setText(rideDate.toString("h:mm AP"));

        // Metrics 1,2,3,4
        m1->setText(QTime(0,0,0,0).addSecs(metrics.getForSymbol("workout_time")).toString("hh:mm:ss")); //duration
        
	if (useMetricUnits) { 
	  m3->setText(QString("%1 km").arg(metrics.getForSymbol("total_distance"), 0, 'f', 2));
	  } else {
	  m3->setText(QString("%1 mi").arg(metrics.getForSymbol("total_distance")*MILES_PER_KM, 0, 'f', 2));
	  } //distance

        m2->setText(QString("%1 TSS").arg(metrics.getForSymbol("coggan_tss"), 0, 'f', 0));
        m4->setText(QString("%1 IF").arg(metrics.getForSymbol("coggan_if"), 0, 'f', 3));

        // Icons
        QString data = metrics.getText("Data", "");

        if (data.contains("P")) power->show();
        else power->hide();
        if (data.contains("S")) speed->show();
        else speed->hide();
        if (data.contains("H")) hr->show();
        else hr->hide();
        if (data.contains("C")) cad->show();
        else cad->hide();
        if (data.contains("N")) torque->show();
        else torque->hide();
        if (data.contains("A")) alt->show();
        else alt->hide();
        if (data.contains("G")) gps->show();
        else gps->hide();
        if (data.contains("E")) temp->show();
        else temp->hide();
        if (data.contains("W")) wind->show();
        else wind->hide();
}
Exemplo n.º 6
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;
}