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]
This commit is contained in:
Alejandro Martinez
2023-03-05 16:26:25 -03:00
committed by GitHub
parent 42c43c7689
commit 67136b3cdf
11 changed files with 178 additions and 102 deletions

View File

@@ -1,5 +1,6 @@
#include "FixPyDataProcessor.h"
#include "FixPyRunner.h"
#include "Athlete.h"
// Config widget used by the Preferences/Options config panes
class FixPyDataProcessorConfig : public DataProcessorConfig
@@ -24,7 +25,17 @@ bool FixPyDataProcessor::postProcess(RideFile *rideFile, DataProcessorConfig *se
QString errText;
bool useNewThread = op != "PYTHON";
Context* context = (rideFile) ? rideFile->context : nullptr;
FixPyRunner pyRunner(context, rideFile, useNewThread);
RideItem* rideItem = nullptr;
if (context && rideFile) {
// get RideItem from RideFile for Python functions using it
foreach(RideItem *item, context->athlete->rideCache->rides()) {
if (item->dateTime == rideFile->startTime()) {
rideItem = item;
break;
}
}
}
FixPyRunner pyRunner(context, rideFile, rideItem, useNewThread);
return pyRunner.run(pyScript->source, pyScript->iniKey, errText) == 0;
}