Skip to content

Commit

Permalink
Avoid crashes when Python APIs are called from User Metrics
Browse files Browse the repository at this point in the history
There is no perspective involved in this case.
  • Loading branch information
amtriathlon committed Jul 12, 2021
1 parent c29a776 commit 8e38632
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Python/SIP/Bindings.cpp
Expand Up @@ -584,7 +584,7 @@ Bindings::activities(QString filter) const
FilterSet fs;
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
if (python->perspective) fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));

// did call contain any filters?
if (filter != "") {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ Bindings::seasonMetrics(bool all, DateRange range, QString filter) const
FilterSet fs;
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
if (python->perspective) fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));

// did call contain a filter?
if (filter != "") {
Expand Down Expand Up @@ -1383,7 +1383,7 @@ Bindings::seasonIntervals(DateRange range, QString type) const
FilterSet fs;
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
if (python->perspective) fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
specification.setFilterSet(fs);

// we need to count intervals that are in range...
Expand Down Expand Up @@ -1821,7 +1821,7 @@ Bindings::metrics(QString metric, bool all, QString filter) const
FilterSet fs;
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
if (python->perspective) fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));

// did call contain a filter?
if (filter != "") {
Expand Down Expand Up @@ -1988,8 +1988,13 @@ Bindings::seasonMeanmax(bool all, DateRange range, QString filter) const
if (all) range = DateRange(QDate(1900,01,01), QDate(2100,01,01));

// did call contain any filters?
QStringList filelist=python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000)));
bool filt=python->perspective->isFiltered();
QStringList filelist;
bool filt=false;

if (python->perspective) {
filelist = python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000)));
filt = python->perspective->isFiltered();
}

// if not empty write a filter
if (filter != "") {
Expand Down Expand Up @@ -2218,7 +2223,7 @@ Bindings::seasonMeasures(bool all, QString group) const
fields[i] = PyList_New(size);

unsigned int index = 0;
for(int k=0; k < size; k++) {
for(unsigned int k=0; k < size; k++) {

// day today
if (start.addDays(k) >= range.from && start.addDays(k) <= range.to) {
Expand Down Expand Up @@ -2407,7 +2412,7 @@ Bindings::seasonPeaks(bool all, DateRange range, QString filter, QList<RideFile:
FilterSet fs;
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
if (python->perspective) fs.addFilter(python->perspective->isFiltered(), python->perspective->filterlist(DateRange(QDate(1,1,1970),QDate(31,12,3000))));
specification.setFilterSet(fs);

// did call contain any filters?
Expand Down

1 comment on commit 8e38632

@liversedge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ale, am distracted on the data table overview item

Please sign in to comment.