Commit Graph

48 Commits

Author SHA1 Message Date
Alejandro Martinez
bd367e607a Add planned/expected PMC to R/Python APIs
Part 2 of #4652
2025-07-11 16:06:48 -03:00
Alejandro Martinez
2a2eafe926 Python API - Add deleteXDataSeries and deleteXData
For completeness as requested in the users forum:
GC.deleteXDataSeries(xdata, series) to remove existing XData series
GC.deleteXData(xdata) to remove existing XData
They invoke the corresponding RideFileCommand methods.
2024-12-06 15:31:27 -03:00
Alejandro Martinez
1ecc6f9ec9 Python - Add compare support to activity series (#4349)
All activity functions working with data series,
both standard and xdata, now include an optional
compareindex=-1 parameter.
When compare mode is enabled compareindex parameter
is used as an index to get data for the corresponding
compare item, be an activity or an interval.
Sample chart contributed by Marcen at the users forum
Fixes #4346
2023-04-11 18:06:39 -03:00
Alejandro Martinez
67136b3cdf Enable Python DPs use Metadata in automatic mode (#4336)
Data Processors running on import are applied before the activity
is added to RideCache and metrics are computed, this behavior is
by design, likely to optimize resource usage on bulk import.
So activityMetrics API is not available; a new getTag API was
added for this case and setTag/delTag/hasTag changed to work
in this context too.
When the Python fix is executed on activities already in the cache
either via Edit menu, Filters or other Python Fix changes are
notified via the corresponding RideItem.
Fixes #4095
[publish binaries]
2023-03-05 16:26:25 -03:00
Alejandro Martinez
32b1f0f7d1 Enable language independent filter by interval type
R and Python API: add GC.intervalType(type=1) function to get the
localized interval description to be used as parameter for intervals.
Formulas: return the enumerator for intervals function while intervalstrings
continue to return localized type description.
Fixes #4114
2022-01-27 11:08:32 -03:00
Alejandro Martinez
9315b301d7 Add setTag/delTag/hasTag to Python API
For Metadata handling in Python Data Processors, similar to set/unset/isset
in formulas, but no metric overrides for now.
- setTag(name, value[, activity])
- delTag(name[, activity])
- hasTag(name[, activity])
All return boolean success indicator and activity is optional,
defaulting to current activity.
setTag and delTag are enabled only in Python Data Processors, mark
the activiy as modified and notify metadata has changed on success.
Fixes #3639
2021-05-17 19:32:41 -03:00
Mark Liversedge
3bf2f13764 Generic Chart Click-thru 1 of 2
.. Enable click through from the data points on a generic chart
   when on trends view.

.. This commit includes the 'addCurve' bindings to pass the
   activity filenames from R, Python and the User Chart.

.. It also includes a new DataFilter function 'filename' to
   get a vector of strings that are the filenames for the
   activities in the selected date range (or the filename
   for the currently selected activity).

.. The second commit will include the interaction code for
   GenericPlot to click-thru a selection.
2020-07-17 13:37:06 +01:00
Mark Liversedge
df2d436a02 User, R and Python Chart fill curves
.. add ability to plot filled curves.
2020-06-10 19:59:21 +01:00
Mark Liversedge
fc02b8a38b GenericChart Data Labels
.. allow data labels for points on the chart, added to User, R and
   Python chart addCurve() etc.

.. NOTE: opengl painting ignores this setting so should be disabled
         for data series that want labels. We do not do this
         automatically, but might consider that later.
2020-03-20 08:06:56 +00:00
Mark Liversedge
71690f32a7 Generic Chart Python Label Annotation - Part 2b of 2
.. GC.annotate(type="label", series="Power", label="CP=222") added to
   the python chart to add a label to the legend for displaying things
   like parameter estimates.

.. it does feel like annotations will need to be thought thru and likely
   result in a GenericAnnotation class. But lets cross that bridge
   when we get there.

.. Label annotations are enough to get started and are now present in
   User, R and Python charts.
2020-03-20 07:16:52 +00:00
Mark Liversedge
3f9774b2c2 Generic Chart Series - show on legend
.. you can now configure if a series is shown on the legend, this is
   for lines or curves that are there for illustration but do not
   need to be displayed in the legend / hovered.
2020-03-15 18:43:11 +00:00
Mark Liversedge
ce955e01a5 Add QChart to Python Chart (4a of 5)
.. added GenericChart which manages a collection of plots, so
   you can plot multiple series stacked (like in AllPlot).

.. additionally added option to set layout vertical or
   horizontal, since its useful to layout scatter plots
   horizontally where time series will be largely vertical.

.. at this point the code is slightly refactored to add
   GenericChart between PythonChart and GenericPlots.

.. will shortly add code to support managing multiple plots
   in layouts and adapting if settings change (.e.g the
   python script is edited, settings are changed).
2020-03-02 10:39:58 +00:00
Mark Liversedge
e83c9e8bb3 GenericPlot legend placement and line styles
.. updated to support different linestyles and also legend can
   now be placed above, below, left or right of the chart and
   orientated to list series vertically or horizontally.

.. the vertical legend is a bit ugly as nothing lines up, will
   fix up separately.
2020-03-01 17:37:07 +00:00
Mark Liversedge
1b3792d4a8 Add QChart to Python Chart (2b of 5)
Basics now in place to plot line, scatter, pie and bar
charts. This commit finishes off the final bit of part
2, adding axes control.

A new GC api, GC.setAxis(..) has been added allowing
fine grained control on the axes added automatically.

They reference axes by name, based upon the xaxis and yaxis
parameters passed to the GC.setCurve(..) function.

GC.setAxis(..) should be called /after/ the curves are
added since it will not create axes in advance.
2020-02-11 17:41:46 +00:00
Mark Liversedge
54dc089705 Add QChart to Python Chart (2a of 5)
Added Pie and Bar charts with some rudimentary axes
being created automatically.

Need to follow up with mechanism to work with axes from
within the python script, likely needs a new binding.
2020-02-10 19:19:28 +00:00
Mark Liversedge
b4eb1191fd Add QChart to Python Chart (1 of 5)
Updating the python chart to render via a Qt Chart in addition
to the existing web page rendering.

Five aspects are planned:
1. Add QT chart option, basic rendering of Line+Scatter (this commit)
2. Add legend and axes, support for Pie and Bar charts
3. Add interactivity / hover etc
4. Add options for annotations and markers
5. Add more advanced charts and chart objects

There is an example in the tests folder, but at this point the
chart is very basic, but the main plumbing is in place.
2020-02-10 11:57:42 +00:00
riccioclista
9f1187390f Python data processors (#2951)
* Initial implementation of Python data processors
* Add RideEditor to PyFIx script editor
* Enable write-access to activity data for python fixes
* Add GC.deleteActivitySample method
* Add GC.deleteSeries method
* Check for python fix for changes before close
* Build python fixes menu dynamically
* Make python fixes first class data processors
* Add GC.postProcess method
* Check GC_WANT_PYTHON and "Enable Python" setting for python fixes
* Add GC.createXDataSeries method
* Clean up ScriptContext ctor mess
* Support editing xdata series
* PDP: Implement xdata append/remove methods
2019-12-19 22:05:51 -03:00
Ale Martinez
5c9a233e96 Changed Python XData access points for consistency
xdataNames, xdataSeries and xdata refer to low level functions
activityXdata is a wrapper to obtain XData series by name without interpolation
activity includes all XData series interpolated
2018-05-05 13:09:02 -03:00
Ale Martinez
119b889cb4 Add activityXdataNames(name="", activity=None)
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
2018-05-02 21:02:32 -03:00
Ale Martinez
ead2650f15 Add Python activityXdataSeries(name, series, activity)
To retrieve XData series without resampling, series can be
"secs", "km" or a valuename for the requested XData name.
Fixes #2847
2018-05-02 19:40:57 -03:00
Ale Martinez
5ea8903edc Add Python activityIntervals
Python half of #2848
2018-04-27 21:09:35 -03:00
Mark Liversedge
49d78e6c7b Remove TrainingPeaks Trademarks
.. renaming the 3 metrics they trademarked in 2013:

   TSS => BikeStress
   IF => BikeIntensity
   NP => IsoPower

.. this will break data filters, user formula and
   R and Python charts.

.. in the next commit will add user metrics to ensure
   backward compatibility.
2018-02-17 11:12:50 +00:00
Mark Liversedge
8e3a170d94 DataFilter Embed Python Scripts
.. 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"
2018-01-29 10:03:41 +00:00
Alejandro Martinez
8a3db53a90 Rename some Python entry points to match the wiki
zones => athleteZones
wbal => activityWbal
xdataseries => activityXdata
pmc => seasonPmc
measures => seasonMeasures
2018-01-23 17:56:24 -03:00
Alejandro Martinez
0c4ffcf93f Add Python seasonPeaks(series, duration, all=False, filter="", compare=False)
Similar to R season.peaks but for one series/duration at a time
2018-01-23 17:24:11 -03:00
Alejandro Martinez
b293d5374b Add Python seasonIntervals(type="", compare=False)
Get metrics for intervals in a season, similar to
R GC.season.intervals
2018-01-22 21:46:23 -03:00
Alejandro Martinez
9d00f78e4c Add Python zones(date, sport)
To retrieve athletes zones info, similar to R athlete.zones,
just returning a dict instead of a data frame
2018-01-20 15:05:34 -03:00
Alejandro Martinez
9e193c7e9f Changed Python athlete to return a dict
Similar to the R counterpart it includes name, home, dob,
weight, height and gender
2018-01-19 20:41:21 -03:00
Alejandro Martinez
90a18303c4 Add Python xdataseries(name, series, join="repeat", activity=None)
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.
2018-01-18 15:41:48 -03:00
Alejandro Martinez
6df60d819b Add Python wbal similar to series
Optional parameter is activity datetime, current activity if not provided.
2018-01-17 14:55:16 -03:00
Alejandro Martinez
cc2f56c7a3 Python season(all=False, compare=False)
Similar to R season(), retuns a dict with name, from, to and color lists.
2017-12-21 15:19:14 -03:00
Alejandro Martinez
5d94ce2167 Python activity, series and seriesPresent optional datetime parameter
It can be used to get data from other than current selected activiy,
identified by datetime, s.t. the items returned by activities(filter)
2017-12-18 20:55:42 -03:00
Alejandro Martinez
6b7d1b794c Python activities(filter="")
Returns a list of DateTime for activities passing the filter
2017-12-17 17:57:55 -03:00
Alejandro Martinez
f47607d725 Python measures(all=False, group="Body")
Similar to R measures returning a dict with a list for each
measure field in the requested group (Body or Hrv).
2017-12-17 13:00:17 -03:00
Alejandro Martinez
bbfc4e44fe Python pmc(all=False, metric="TSS")
Similar to R pmc, returns a dict with a list for: date, stress, lts, sts, sb, rr
2017-12-17 11:28:16 -03:00
Alejandro Martinez
1aa1ab41d1 Python activityMeanmax and seasonMeanmax
Both return a dict with a list for each supported series from cache
Next step is to support compare mode
2017-12-16 17:43:03 -03:00
Alejandro Martinez
be73ab9749 Enable keyword arguments in Python wrappers generated by SIP
For example:
>>> GC.metrics("Pace", filter="isRun<>0")
is equivalent to:
>>> GC.metrics("Pace", False, "isRun<>0")
as expected by Python users
2017-12-15 19:42:25 -03:00
Alejandro Martinez
ae6d00103e Python metrics(metric, all, filter)
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")
2017-12-15 11:56:55 -03:00
Alejandro Martinez
eae7f1d9ed Add Python seasonMetrics(all, filter, compare)
Similar to R API season.metrics
2017-12-14 17:30:32 -03:00
Alejandro Martinez
a3e23fd6de Enabled compare for Python activiyMetrics
activityMetrics(True) returns a list of 2 element tuples with
metrics&metadata dict as first element and color name as second one.
2017-12-12 21:29:39 -03:00
Alejandro Martinez
a15bcfc102 Python activityMetrics
Returns a Python dict with metrics and metadata fields.
It doesn't implement compare mode yet.
2017-12-12 08:35:06 -03:00
Mark Liversedge
7eb926b33a Python Web Display
.. 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.
2017-12-11 18:58:59 +00:00
Mark Liversedge
a7981ff302 Python fixup ConvertTo_QString
.. missing in original code. will be needed for APIs that
   want to pass names etc to C++ from Python.
2017-12-11 12:32:33 +00:00
Alejandro Martinez
b3680c0dd1 Enabled sequence behavior on PythonDataSeries
Adding __getitem__ makes it to behave like a sequence enabling indexing
and iteration,for example:
s = GC.series(6)
print(s[0], s[-1])
for v in s: print(s)
l = list(s)
print(l.count(0))
2017-12-09 20:36:03 -03:00
Mark Liversedge
2a5fcfe5db Python DataSeries functions
.. 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)
2017-12-09 16:50:29 +00:00
Mark Liversedge
3a534e1ff4 Python GC.build() and GC.version()
.. 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
2017-12-05 19:23:38 +00:00
Mark Liversedge
db3d119f7d Python GC.athlete()
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
2017-12-04 15:20:43 +00:00
Mark Liversedge
00144effd8 Python Module Framework
.. 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
   >
2017-12-02 16:33:54 +00:00