When name="" it returns XData names
When name is one of the names for the activity it returns valuenames
To dinamically obtain names/series for activityXdata and activityXdataSeries
Carry RideItem, Specification and Metrics to consider the cases when
the script is part of a UserMetric or an LTMPlot formula
Python series, activityWbal and activityXdata honor RideItem and Specification
Python activityMetrics honors ScriptContext RideItem and Metrics
Python activityMeanMax honors ScriptContext RideItem
Force recomputation of metrics just in case Python Scripts were used before
.. allow the user to embed a python script into a datafilter.
.. this is primarily to enable the use of python when writing
user metrics.
.. the syntax is basically "%%python script %%" and it is
evaluated as an expresssion so the results can be assigned
to a variable or returned as a value.
.. additionally GC.result(double) has been added to the python
API to enable a return value to be set by the script.
.. since Python is really sensitive about white space its going
to be best practice to embed python scripts without honoring
any of the data filter spacing, for example:
{
value {
t <-
%%python
GC.result(100)
%%;
}
}
.. is likely to be a sensible way to use this.
.. also notice how the ; is needed after the expression. This
is because %%python ... %% is a numeric expression with the
same semantics as "1 + 2"
Similar to series but used to retrieve an XData series, like the R
activity.xdata counterpart, for example: GC.xdataseries("SWIM", "STROKES")
NB: I reserved xdata(name) to retrive a whole group of series by name
with its own sampling, not implemented in this commit.
A more efficient way to obtain a metric series for a large number
of activities, it can be converted to numpy array without copy:
import numpy as np
nparray = np.asarray(GC.metrics("Average_Power", True, "isRun=0 && isSwim=0")
.. instead of an opengl canvas lets start with a Web canvas.
.. we might have options to use QtCharts or OpenGL later.
.. not working - committed to save WIP.
.. With german translation activated GC.activity() complains about
some utf-8 decoding stuff and returns error.
First I thought came from the real activity json file, but it's
from translation: Altitude -> Höhenmeter.
Is it necessary to use toLatin1() in goldencheetah.sip? With
toUtf8() it works and you get delta symbols instead of question marks.
.. With R the series names are always in english and use a naming
convention derived from the R trackR package -- we now follow the
same in Python bindings to ensure charts created in one locale
will continue to work in another.
.. start of API to work with ride data, exposing the raw
sample data via the buffer protocol python api and SIP
.. adds utility functions that will ultimately be wrapped
inside a python class/function:
GC.series(n) - return series data as a python array
GC.seriesName(n) - return string describing series data
GC.seriesLast() - returns int for last series type
GC.seriesPresent(n) - returns True if series in ride
.. example of using these functions in python to create a
dict object collecting all available data:
activity = {}
for x in range(0, GC.seriesLast()):
if (GC.seriesPresent(x)):
activity[GC.seriesName(x)] = GC.series(x)
.. simple examples, lots of generated code changes which is
not very helpful.
.. but the only files that were edited by hand are goldencheetah.sip
Bindings.h and Bindings.cpp
Basic proof of concept for CPP binding using SIP but with
our own type conversion (to avoid overhead of SIP lib/deploy).
Its far from perfect but will serve as a starting point.
.. needed to fixup type conversion in goldencheetah.sip to
convert returning QString as PyUnicode
.. needed to fixup passing context when multi-threaded
.. needed to fixup Bindings.h/cpp to offer new API
.. Using SIP thats used in PyQt et al we have a module
called `goldencheetah' which includes bindings.
Currently there is only a single method `getValue()'
that returns 1. It's to get the basic plumbing in place.
src/Python/SIP contains all the files related to the
module. The cpp files are generated by the `sip' utility
which will need to be available if you want to work on the
bindings. Run make -f Makefile.hack to regenerate the cpp
files if you edit them.
I prefer to distribute the generated files at this point
whilst development occurs. We may change that at a later
date.
.. Please note that the gcconfig.pri.in file has changed as
we now include the python include path rather than set a
macro for the include directive (See PYTHONINCLUDES in
gcconfig.pri.in)
.. lastly, to test this is working in a python chart console:
> print(GC.getValue())
1
>