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;
}
Exemple #2
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();
}