diff --git a/src/Python/SIP/Bindings.cpp b/src/Python/SIP/Bindings.cpp index 0efe92161..e69966614 100644 --- a/src/Python/SIP/Bindings.cpp +++ b/src/Python/SIP/Bindings.cpp @@ -7,6 +7,7 @@ #include "Colors.h" #include "RideCache.h" #include "DataFilter.h" +#include "PMCData.h" #include "Bindings.h" @@ -687,6 +688,108 @@ Bindings::rideFileCacheMeanmax(RideFileCache* cache) const return ans; } +PyObject* +Bindings::pmc(bool all, QString metric) const +{ + Context *context = python->contexts.value(threadid()); + + // return a dict with PMC data for all or the current season + // XXX uses the default half-life + if (context) { + + // import datetime if necessary + if (PyDateTimeAPI == NULL) PyDateTime_IMPORT; + + // get the currently selected date range + DateRange range(context->currentDateRange()); + + // convert the name to a symbol, if not found just leave as it is + const RideMetricFactory &factory = RideMetricFactory::instance(); + for (int i=0; ispecialFields.internalName(factory.rideMetric(symbol)->name()); + name.replace(" ","_"); + + if (name == metric) { + metric = symbol; + break; + } + } + + // create the data + PMCData pmcData(context, Specification(), metric); + + // how many entries ? + unsigned int size = all ? pmcData.days() : range.from.daysTo(range.to) + 1; + // returning a dict with + // date, stress, lts, sts, sb, rr + PyObject* ans = PyDict_New(); + + // DATE - 1 a day from start + PyObject* datelist = PyList_New(size); + QDate start = all ? pmcData.start() : range.from; + for(unsigned int k=0; k= range.from && start.addDays(k) <= range.to) { + + PyList_SET_ITEM(stress, index, PyFloat_FromDouble(pmcData.stress()[k])); + PyList_SET_ITEM(lts, index, PyFloat_FromDouble(pmcData.lts()[k])); + PyList_SET_ITEM(sts, index, PyFloat_FromDouble(pmcData.sts()[k])); + PyList_SET_ITEM(sb, index, PyFloat_FromDouble(pmcData.sb()[k])); + PyList_SET_ITEM(rr, index, PyFloat_FromDouble(pmcData.rr()[k])); + index++; + } + } + } + + // add to the dict + PyDict_SetItemString(ans, "stress", stress); + PyDict_SetItemString(ans, "lts", lts); + PyDict_SetItemString(ans, "sts", sts); + PyDict_SetItemString(ans, "sb", sb); + PyDict_SetItemString(ans, "rr", rr); + + // return it + return ans; + } + + // nothing to return + return NULL; +} + int Bindings::webpage(QString url) const { diff --git a/src/Python/SIP/Bindings.h b/src/Python/SIP/Bindings.h index f4397e63a..9ae0ea119 100644 --- a/src/Python/SIP/Bindings.h +++ b/src/Python/SIP/Bindings.h @@ -37,6 +37,7 @@ class Bindings { PyObject* activityMetrics(bool compare=false) const; PyObject* seasonMetrics(bool all=false, QString filter=QString(), bool compare=false) const; PythonDataSeries *metrics(QString metric, bool all=false, QString filter=QString()) const; + PyObject* pmc(bool all=false, QString metric=QString("TSS")) const; // working with meanmax data PyObject* activityMeanmax(bool compare=false) const; diff --git a/src/Python/SIP/goldencheetah.sip b/src/Python/SIP/goldencheetah.sip index a43596892..2e14bf462 100644 --- a/src/Python/SIP/goldencheetah.sip +++ b/src/Python/SIP/goldencheetah.sip @@ -126,6 +126,7 @@ public: PyObject* activityMetrics(bool compare=false) /TransferBack/; PyObject* seasonMetrics(bool all=false, QString filter=QString(), bool compare=false) /TransferBack/; PythonDataSeries *metrics(QString metric, bool all=false, QString filter=QString()) /TransferBack/; + PyObject* pmc(bool all=false, QString metric=QString("TSS")) /TransferBack/; // working with meanmax data PyObject* activityMeanmax(bool compare=false) /TransferBack/; diff --git a/src/Python/SIP/sipAPIgoldencheetah.h b/src/Python/SIP/sipAPIgoldencheetah.h index 77529dfb9..4a2692111 100644 --- a/src/Python/SIP/sipAPIgoldencheetah.h +++ b/src/Python/SIP/sipAPIgoldencheetah.h @@ -65,8 +65,10 @@ #define sipName_type &sipStrings_goldencheetah[248] #define sipNameNr_url 253 #define sipName_url &sipStrings_goldencheetah[253] -#define sipNameNr_all 257 -#define sipName_all &sipStrings_goldencheetah[257] +#define sipNameNr_pmc 257 +#define sipName_pmc &sipStrings_goldencheetah[257] +#define sipNameNr_all 261 +#define sipName_all &sipStrings_goldencheetah[261] #define sipMalloc sipAPI_goldencheetah->api_malloc #define sipFree sipAPI_goldencheetah->api_free diff --git a/src/Python/SIP/sipgoldencheetahBindings.cpp b/src/Python/SIP/sipgoldencheetahBindings.cpp index a23f7cca5..2c02d468c 100644 --- a/src/Python/SIP/sipgoldencheetahBindings.cpp +++ b/src/Python/SIP/sipgoldencheetahBindings.cpp @@ -339,6 +339,41 @@ static PyObject *meth_Bindings_metrics(PyObject *sipSelf, PyObject *sipArgs, PyO } +extern "C" {static PyObject *meth_Bindings_pmc(PyObject *, PyObject *, PyObject *);} +static PyObject *meth_Bindings_pmc(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds) +{ + PyObject *sipParseErr = NULL; + + { + bool a0 = 0; + ::QString a1def = QString("TSS"); + ::QString* a1 = &a1def; + int a1State = 0; + ::Bindings *sipCpp; + + static const char *sipKwdList[] = { + sipName_all, + sipName_metric, + }; + + if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "B|bJ1", &sipSelf, sipType_Bindings, &sipCpp, &a0, sipType_QString,&a1, &a1State)) + { + PyObject * sipRes; + + sipRes = sipCpp->pmc(a0,*a1); + sipReleaseType(a1,sipType_QString,a1State); + + return sipRes; + } + } + + /* Raise an exception if the arguments couldn't be parsed. */ + sipNoMethod(sipParseErr, sipName_Bindings, sipName_pmc, NULL); + + return NULL; +} + + extern "C" {static PyObject *meth_Bindings_activityMeanmax(PyObject *, PyObject *, PyObject *);} static PyObject *meth_Bindings_activityMeanmax(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds) { @@ -512,6 +547,7 @@ static PyMethodDef methods_Bindings[] = { {SIP_MLNAME_CAST(sipName_athlete), meth_Bindings_athlete, METH_VARARGS, NULL}, {SIP_MLNAME_CAST(sipName_build), meth_Bindings_build, METH_VARARGS, NULL}, {SIP_MLNAME_CAST(sipName_metrics), (PyCFunction)meth_Bindings_metrics, METH_VARARGS|METH_KEYWORDS, NULL}, + {SIP_MLNAME_CAST(sipName_pmc), (PyCFunction)meth_Bindings_pmc, METH_VARARGS|METH_KEYWORDS, NULL}, {SIP_MLNAME_CAST(sipName_seasonMeanmax), (PyCFunction)meth_Bindings_seasonMeanmax, METH_VARARGS|METH_KEYWORDS, NULL}, {SIP_MLNAME_CAST(sipName_seasonMetrics), (PyCFunction)meth_Bindings_seasonMetrics, METH_VARARGS|METH_KEYWORDS, NULL}, {SIP_MLNAME_CAST(sipName_series), (PyCFunction)meth_Bindings_series, METH_VARARGS|METH_KEYWORDS, NULL}, @@ -537,7 +573,7 @@ sipClassTypeDef sipTypeDef_goldencheetah_Bindings = { { sipNameNr_Bindings, {0, 0, 1}, - 14, methods_Bindings, + 15, methods_Bindings, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, diff --git a/src/Python/SIP/sipgoldencheetahcmodule.cpp b/src/Python/SIP/sipgoldencheetahcmodule.cpp index 68fd129f7..5911db661 100644 --- a/src/Python/SIP/sipgoldencheetahcmodule.cpp +++ b/src/Python/SIP/sipgoldencheetahcmodule.cpp @@ -41,6 +41,7 @@ const char sipStrings_goldencheetah[] = { 'b', 'u', 'i', 'l', 'd', 0, 't', 'y', 'p', 'e', 0, 'u', 'r', 'l', 0, + 'p', 'm', 'c', 0, 'a', 'l', 'l', 0, };