mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-13 12:42:20 +00:00
R Use List not Pairlist (Part 2 of 2)
.. completes the updates to RTool.cpp .. as predicted by forming the pmc data.frame via an S3 list instead of a pair list the merge() function works properly and column names are retained.
This commit is contained in:
176
src/R/RTool.cpp
176
src/R/RTool.cpp
@@ -1779,13 +1779,12 @@ RTool::dfForRideFileCache(RideFileCache *cache)
|
|||||||
|
|
||||||
// we return a list of series vectors
|
// we return a list of series vectors
|
||||||
SEXP ans;
|
SEXP ans;
|
||||||
PROTECT(ans = Rf_allocList(seriescount));
|
PROTECT(ans = Rf_allocVector(VECSXP, seriescount));
|
||||||
|
|
||||||
// we collect the names as we go
|
// we collect the names as we go
|
||||||
SEXP names;
|
SEXP names;
|
||||||
PROTECT(names = Rf_allocVector(STRSXP, seriescount)); // names attribute (column names)
|
PROTECT(names = Rf_allocVector(STRSXP, seriescount)); // names attribute (column names)
|
||||||
int next=0;
|
int next=0;
|
||||||
SEXP nextS = ans;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Now we need to add vectors to the ans list...
|
// Now we need to add vectors to the ans list...
|
||||||
@@ -1809,8 +1808,7 @@ RTool::dfForRideFileCache(RideFileCache *cache)
|
|||||||
for(int j=0; j<values.count(); j++) REAL(vector)[j] = values[j];
|
for(int j=0; j<values.count(); j++) REAL(vector)[j] = values[j];
|
||||||
|
|
||||||
// add to the list
|
// add to the list
|
||||||
SETCAR(nextS, vector);
|
SET_VECTOR_ELT(ans, next, vector);
|
||||||
nextS = CDR(nextS);
|
|
||||||
|
|
||||||
// give it a name
|
// give it a name
|
||||||
SET_STRING_ELT(names, next, Rf_mkChar(RideFile::seriesName(series, true).toLatin1().constData()));
|
SET_STRING_ELT(names, next, Rf_mkChar(RideFile::seriesName(series, true).toLatin1().constData()));
|
||||||
@@ -1892,10 +1890,8 @@ RTool::seasonPeaks(SEXP pAll, SEXP pFilter, SEXP pCompare, SEXP pSeries, SEXP pD
|
|||||||
|
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(count));
|
PROTECT(list=Rf_allocVector(VECSXP, count));
|
||||||
|
int index=0;
|
||||||
// start at the front
|
|
||||||
SEXP nextS = list;
|
|
||||||
|
|
||||||
// a named list with data.frame 'metrics' and color 'color'
|
// a named list with data.frame 'metrics' and color 'color'
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
@@ -1911,26 +1907,23 @@ RTool::seasonPeaks(SEXP pAll, SEXP pFilter, SEXP pCompare, SEXP pSeries, SEXP pD
|
|||||||
if (p.isChecked()) {
|
if (p.isChecked()) {
|
||||||
|
|
||||||
// create a named list
|
// create a named list
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForDateRangePeaks(all, DateRange(p.start, p.end), pFilter, series, durations);
|
SEXP df = rtool->dfForDateRangePeaks(all, DateRange(p.start, p.end), pFilter, series, durations);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(nextS, namedlist);
|
SET_VECTOR_ELT(list, index++, namedlist);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
UNPROTECT(2);
|
UNPROTECT(2);
|
||||||
}
|
}
|
||||||
@@ -1943,7 +1936,7 @@ RTool::seasonPeaks(SEXP pAll, SEXP pFilter, SEXP pCompare, SEXP pSeries, SEXP pD
|
|||||||
|
|
||||||
// otherwise return the current metrics in a compare list
|
// otherwise return the current metrics in a compare list
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(1));
|
PROTECT(list=Rf_allocVector(VECSXP, 1));
|
||||||
|
|
||||||
// names
|
// names
|
||||||
SEXP names;
|
SEXP names;
|
||||||
@@ -1953,26 +1946,24 @@ RTool::seasonPeaks(SEXP pAll, SEXP pFilter, SEXP pCompare, SEXP pSeries, SEXP pD
|
|||||||
|
|
||||||
// named list of metrics and color
|
// named list of metrics and color
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the metrics
|
// add the metrics
|
||||||
DateRange range = rtool->context->currentDateRange();
|
DateRange range = rtool->context->currentDateRange();
|
||||||
SEXP df = rtool->dfForDateRangePeaks(all, range, pFilter, series, durations);
|
SEXP df = rtool->dfForDateRangePeaks(all, range, pFilter, series, durations);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(list, namedlist);
|
SET_VECTOR_ELT(list, 0, namedlist);
|
||||||
UNPROTECT(4);
|
UNPROTECT(4);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -1996,8 +1987,8 @@ RTool::dfForDateRangePeaks(bool all, DateRange range, SEXP filter, QList<RideFil
|
|||||||
// so how many vectors in the frame ? +1 is the datetime of the peak
|
// so how many vectors in the frame ? +1 is the datetime of the peak
|
||||||
int listsize=series.count() * durations.count() + 1;
|
int listsize=series.count() * durations.count() + 1;
|
||||||
SEXP df;
|
SEXP df;
|
||||||
PROTECT(df=Rf_allocList(listsize));
|
PROTECT(df=Rf_allocVector(VECSXP, listsize));
|
||||||
SEXP nextS=df;
|
int dfindex=0;
|
||||||
|
|
||||||
// and each one needs a name
|
// and each one needs a name
|
||||||
SEXP names;
|
SEXP names;
|
||||||
@@ -2064,8 +2055,7 @@ RTool::dfForDateRangePeaks(bool all, DateRange range, SEXP filter, QList<RideFil
|
|||||||
Rf_classgets(dates,clas);
|
Rf_classgets(dates,clas);
|
||||||
Rf_setAttrib(dates, Rf_install("tzone"), Rf_mkString("UTC"));
|
Rf_setAttrib(dates, Rf_install("tzone"), Rf_mkString("UTC"));
|
||||||
|
|
||||||
SETCAR(nextS, dates);
|
SET_VECTOR_ELT(df, dfindex++, dates);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
foreach(RideFile::SeriesType pseries, series) {
|
foreach(RideFile::SeriesType pseries, series) {
|
||||||
|
|
||||||
@@ -2097,8 +2087,7 @@ RTool::dfForDateRangePeaks(bool all, DateRange range, SEXP filter, QList<RideFil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add named vector to the list
|
// add named vector to the list
|
||||||
SETCAR(nextS, vector);
|
SET_VECTOR_ELT(df, dfindex++, vector);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
|
|
||||||
@@ -2148,10 +2137,8 @@ RTool::seasonMeanmax(SEXP pAll, SEXP pFilter, SEXP pCompare)
|
|||||||
|
|
||||||
// cool we can return a list of meanaxes to compare
|
// cool we can return a list of meanaxes to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(count));
|
PROTECT(list=Rf_allocVector(VECSXP, count));
|
||||||
|
int lindex=0;
|
||||||
// start at the front
|
|
||||||
SEXP nextS = list;
|
|
||||||
|
|
||||||
// a named list with data.frame 'metrics' and color 'color'
|
// a named list with data.frame 'metrics' and color 'color'
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
@@ -2167,26 +2154,23 @@ RTool::seasonMeanmax(SEXP pAll, SEXP pFilter, SEXP pCompare)
|
|||||||
if (p.isChecked()) {
|
if (p.isChecked()) {
|
||||||
|
|
||||||
// create a named list
|
// create a named list
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForDateRangeMeanmax(all, DateRange(p.start, p.end), pFilter);
|
SEXP df = rtool->dfForDateRangeMeanmax(all, DateRange(p.start, p.end), pFilter);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(nextS, namedlist);
|
SET_VECTOR_ELT(list, lindex++, namedlist);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
UNPROTECT(2);
|
UNPROTECT(2);
|
||||||
}
|
}
|
||||||
@@ -2199,7 +2183,7 @@ RTool::seasonMeanmax(SEXP pAll, SEXP pFilter, SEXP pCompare)
|
|||||||
|
|
||||||
// otherwise return the current season meanmax in a compare list
|
// otherwise return the current season meanmax in a compare list
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(1));
|
PROTECT(list=Rf_allocVector(VECSXP, 1));
|
||||||
|
|
||||||
// names
|
// names
|
||||||
SEXP names;
|
SEXP names;
|
||||||
@@ -2209,26 +2193,24 @@ RTool::seasonMeanmax(SEXP pAll, SEXP pFilter, SEXP pCompare)
|
|||||||
|
|
||||||
// named list of metrics and color
|
// named list of metrics and color
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the meanmaxes
|
// add the meanmaxes
|
||||||
DateRange range = rtool->context->currentDateRange();
|
DateRange range = rtool->context->currentDateRange();
|
||||||
SEXP df = rtool->dfForDateRangeMeanmax(all, range, pFilter);
|
SEXP df = rtool->dfForDateRangeMeanmax(all, range, pFilter);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(list, namedlist);
|
SET_VECTOR_ELT(list, 0, namedlist);
|
||||||
UNPROTECT(4);
|
UNPROTECT(4);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -2269,10 +2251,8 @@ RTool::activityMeanmax(SEXP pCompare)
|
|||||||
|
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(count));
|
PROTECT(list=Rf_allocVector(VECSXP, count));
|
||||||
|
int lindex=0;
|
||||||
// start at the front
|
|
||||||
SEXP nextS = list;
|
|
||||||
|
|
||||||
// a named list with data.frame 'activity' and color 'color'
|
// a named list with data.frame 'activity' and color 'color'
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
@@ -2288,26 +2268,23 @@ RTool::activityMeanmax(SEXP pCompare)
|
|||||||
if (p.isChecked()) {
|
if (p.isChecked()) {
|
||||||
|
|
||||||
// create a named list
|
// create a named list
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForActivityMeanmax(p.rideItem);
|
SEXP df = rtool->dfForActivityMeanmax(p.rideItem);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(nextS, namedlist);
|
SET_VECTOR_ELT(list, lindex++, namedlist);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
UNPROTECT(2);
|
UNPROTECT(2);
|
||||||
}
|
}
|
||||||
@@ -2321,7 +2298,7 @@ RTool::activityMeanmax(SEXP pCompare)
|
|||||||
// just return a list of one ride
|
// just return a list of one ride
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(1));
|
PROTECT(list=Rf_allocVector(VECSXP, 1));
|
||||||
|
|
||||||
// names
|
// names
|
||||||
SEXP names;
|
SEXP names;
|
||||||
@@ -2331,25 +2308,23 @@ RTool::activityMeanmax(SEXP pCompare)
|
|||||||
|
|
||||||
// named list of activity and color
|
// named list of activity and color
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForActivityMeanmax(rtool->context->currentRideItem());
|
SEXP df = rtool->dfForActivityMeanmax(rtool->context->currentRideItem());
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(list, namedlist);
|
SET_VECTOR_ELT(list, 0, namedlist);
|
||||||
UNPROTECT(4);
|
UNPROTECT(4);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -2392,10 +2367,8 @@ RTool::activityMetrics(SEXP pCompare)
|
|||||||
|
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(count));
|
PROTECT(list=Rf_allocVector(VECSXP, count));
|
||||||
|
int lindex=0;
|
||||||
// start at the front
|
|
||||||
SEXP nextS = list;
|
|
||||||
|
|
||||||
// a named list with data.frame 'activity' and color 'color'
|
// a named list with data.frame 'activity' and color 'color'
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
@@ -2411,26 +2384,23 @@ RTool::activityMetrics(SEXP pCompare)
|
|||||||
if (p.isChecked()) {
|
if (p.isChecked()) {
|
||||||
|
|
||||||
// create a named list
|
// create a named list
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForRideItem(p.rideItem);
|
SEXP df = rtool->dfForRideItem(p.rideItem);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(nextS, namedlist);
|
SET_VECTOR_ELT(list, lindex++, namedlist);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
UNPROTECT(2);
|
UNPROTECT(2);
|
||||||
}
|
}
|
||||||
@@ -2444,7 +2414,7 @@ RTool::activityMetrics(SEXP pCompare)
|
|||||||
// just return a list of one ride
|
// just return a list of one ride
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(1));
|
PROTECT(list=Rf_allocVector(VECSXP, 1));
|
||||||
|
|
||||||
// names
|
// names
|
||||||
SEXP names;
|
SEXP names;
|
||||||
@@ -2454,25 +2424,23 @@ RTool::activityMetrics(SEXP pCompare)
|
|||||||
|
|
||||||
// named list of activity and color
|
// named list of activity and color
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForRideItem(rtool->context->currentRideItem());
|
SEXP df = rtool->dfForRideItem(rtool->context->currentRideItem());
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(list, namedlist);
|
SET_VECTOR_ELT(list, 0, namedlist);
|
||||||
UNPROTECT(4);
|
UNPROTECT(4);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -2542,8 +2510,7 @@ RTool::pmc(SEXP pAll, SEXP pMetric)
|
|||||||
SEXP ans, names;
|
SEXP ans, names;
|
||||||
|
|
||||||
// date, stress, lts, sts, sb, rr
|
// date, stress, lts, sts, sb, rr
|
||||||
PROTECT(ans=Rf_allocList(6));
|
PROTECT(ans=Rf_allocVector(VECSXP, 6));
|
||||||
SEXP nextS = ans;
|
|
||||||
|
|
||||||
// set ther names
|
// set ther names
|
||||||
PROTECT(names = Rf_allocVector(STRSXP, 6));
|
PROTECT(names = Rf_allocVector(STRSXP, 6));
|
||||||
@@ -2566,7 +2533,7 @@ RTool::pmc(SEXP pAll, SEXP pMetric)
|
|||||||
Rf_classgets(date,dclas);
|
Rf_classgets(date,dclas);
|
||||||
|
|
||||||
// add to the data.frame
|
// add to the data.frame
|
||||||
SETCAR(nextS, date); nextS=CDR(nextS);
|
SET_VECTOR_ELT(ans, 0, date);
|
||||||
|
|
||||||
// PMC DATA
|
// PMC DATA
|
||||||
|
|
||||||
@@ -2607,11 +2574,11 @@ RTool::pmc(SEXP pAll, SEXP pMetric)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add to the list
|
// add to the list
|
||||||
SETCAR(nextS, stress); nextS = CDR(nextS);
|
SET_VECTOR_ELT(ans, 1, stress);
|
||||||
SETCAR(nextS, lts); nextS = CDR(nextS);
|
SET_VECTOR_ELT(ans, 2, lts);
|
||||||
SETCAR(nextS, sts); nextS = CDR(nextS);
|
SET_VECTOR_ELT(ans, 3, sts);
|
||||||
SETCAR(nextS, sb); nextS = CDR(nextS);
|
SET_VECTOR_ELT(ans, 4, sb);
|
||||||
SETCAR(nextS, rr); nextS = CDR(nextS);
|
SET_VECTOR_ELT(ans, 5, rr);
|
||||||
|
|
||||||
SEXP rownames;
|
SEXP rownames;
|
||||||
PROTECT(rownames = Rf_allocVector(STRSXP, size));
|
PROTECT(rownames = Rf_allocVector(STRSXP, size));
|
||||||
@@ -2656,10 +2623,8 @@ RTool::activityWBal(SEXP pCompare)
|
|||||||
|
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(count));
|
PROTECT(list=Rf_allocVector(VECSXP, count));
|
||||||
|
int lindex=0;
|
||||||
// start at the front
|
|
||||||
SEXP nextS = list;
|
|
||||||
|
|
||||||
// a named list with data.frame 'activity' and color 'color'
|
// a named list with data.frame 'activity' and color 'color'
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
@@ -2675,26 +2640,23 @@ RTool::activityWBal(SEXP pCompare)
|
|||||||
if (p.isChecked()) {
|
if (p.isChecked()) {
|
||||||
|
|
||||||
// create a named list
|
// create a named list
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
SEXP df = rtool->dfForActivityWBal(p.rideItem->ride());
|
SEXP df = rtool->dfForActivityWBal(p.rideItem->ride());
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
SET_STRING_ELT(color, 0, Rf_mkChar(p.color.name().toLatin1().constData()));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(nextS, namedlist);
|
SET_VECTOR_ELT(list, lindex++, namedlist);
|
||||||
nextS=CDR(nextS);
|
|
||||||
|
|
||||||
UNPROTECT(2);
|
UNPROTECT(2);
|
||||||
}
|
}
|
||||||
@@ -2708,7 +2670,7 @@ RTool::activityWBal(SEXP pCompare)
|
|||||||
// just return a list of one ride
|
// just return a list of one ride
|
||||||
// cool we can return a list of intervals to compare
|
// cool we can return a list of intervals to compare
|
||||||
SEXP list;
|
SEXP list;
|
||||||
PROTECT(list=Rf_allocList(1));
|
PROTECT(list=Rf_allocVector(VECSXP, 1));
|
||||||
|
|
||||||
// names
|
// names
|
||||||
SEXP names;
|
SEXP names;
|
||||||
@@ -2718,27 +2680,25 @@ RTool::activityWBal(SEXP pCompare)
|
|||||||
|
|
||||||
// named list of activity and color
|
// named list of activity and color
|
||||||
SEXP namedlist;
|
SEXP namedlist;
|
||||||
PROTECT(namedlist=Rf_allocList(2));
|
PROTECT(namedlist=Rf_allocVector(VECSXP, 2));
|
||||||
SEXP offset = namedlist;
|
|
||||||
|
|
||||||
// add the ride
|
// add the ride
|
||||||
RideFile *f = const_cast<RideItem*>(rtool->context->currentRideItem())->ride();
|
RideFile *f = const_cast<RideItem*>(rtool->context->currentRideItem())->ride();
|
||||||
f->recalculateDerivedSeries();
|
f->recalculateDerivedSeries();
|
||||||
SEXP df = rtool->dfForActivityWBal(f);
|
SEXP df = rtool->dfForActivityWBal(f);
|
||||||
SETCAR(offset, df);
|
SET_VECTOR_ELT(namedlist, 0, df);
|
||||||
offset=CDR(offset);
|
|
||||||
|
|
||||||
// add the color
|
// add the color
|
||||||
SEXP color;
|
SEXP color;
|
||||||
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
PROTECT(color=Rf_allocVector(STRSXP, 1));
|
||||||
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
SET_STRING_ELT(color, 0, Rf_mkChar("#FF00FF"));
|
||||||
SETCAR(offset, color);
|
SET_VECTOR_ELT(namedlist, 1, color);
|
||||||
|
|
||||||
// name them
|
// name them
|
||||||
Rf_namesgets(namedlist, names);
|
Rf_namesgets(namedlist, names);
|
||||||
|
|
||||||
// add to back and move on
|
// add to back and move on
|
||||||
SETCAR(list, namedlist);
|
SET_VECTOR_ELT(list, 0, namedlist);
|
||||||
UNPROTECT(4);
|
UNPROTECT(4);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"heightFactor":"2",
|
"heightFactor":"2",
|
||||||
"style":"0",
|
"style":"0",
|
||||||
"resizable":"0",
|
"resizable":"0",
|
||||||
"script":"##\n## TSB v IF with TSS\n##\n## How fresh were we and how hard did we go\n## and how much stress did we elicit.\n## A more meaningful way of reviewing the\n## PMC data in terms of managing load\/intensity\n\nGC.page(width=800, height=600)\n\n## get data\ncompares <- GC.season.metrics(compare=TRUE)\n\n## all pmc data\npmc <- GC.season.pmc(all=TRUE, metric=\"TSS\")\n\n# bigger margins please\npar(mar=c(6,6,6,6))\n\nplot(x=c(-30), y=c(0), \n ylim=c(0.6,1.1), xlim=c(-60,+60),\n xlab=\"\", main=\"\", ylab=\"\")\n\n## grid lines\ngrid(col=\"#404040\", lty=\"solid\", lwd=1)\n\n## title\ntitle(main=\"\", \n xlab=\"TSB\",\n ylab=\"IF\")\n\n## abline\nabline(h=0.85, slope=0, lty=\"dashed\", col=\"white\")\nabline(v=0, slope=1, lty=\"dashed\", col=\"white\")\n\nfor (compare in compares) {\n\n # combine pmc and metric data\n z <- merge(compare$metrics, pmc, by=\"date\")\n\n # area of circle should be proportional\n radius <- sqrt( z$Duration\/ 3.1415927 )\n\n # plot using ride colors if not comparing\n # or only one date range selected\n if (length(compares) == 1) {\n\n # make transparent for overlapping\n colors <- adjustcolor(z$color, 0.6)\n\n symbols(z$\"4\", z$IF, \n circles=radius,\n inches=0.4,\n add=TRUE,\n bg=colors,fg=colors,\n xlab=\"\", ylab=\"\")\n } else {\n\n # make transparent for overlapping\n color <- adjustcolor(compare$color, 0.6)\n\n symbols(z$\"4\", z$IF, \n circles=radius,\n inches=0.4,\n add=TRUE,\n bg=color,\n fg=color,\n xlab=\"\", ylab=\"\")\n\n\n }\n\n # labels for each bubble\n ##text(z$\"4\", z$IF, z$Workout_Code, col=\"gray\", cex=0.5)\n}\n\n## name the quadrants\ntext(-30,0.6, \"Maintain\", col=\"darkgray\", cex=1)\ntext(30,1.09, \"Race\", col=\"darkgray\", cex=1)\ntext(-30,1.09, \"Overload\", col=\"darkgray\", cex=1)\ntext(30,0.6, \"Junk\", col=\"darkgray\", cex=1) ",
|
"script":"##\n## TSB v IF with TSS\n##\n## How fresh were we and how hard did we go\n## and how much stress did we elicit.\n## A more meaningful way of reviewing the\n## PMC data in terms of managing load\/intensity\n\nGC.page(width=800, height=600)\n\n## get data\ncompares <- GC.season.metrics(compare=TRUE)\n\n## all pmc data\npmc <- GC.season.pmc(all=TRUE, metric=\"cTSS\")\n\n# bigger margins please\npar(mar=c(6,6,6,6))\n\nplot(x=c(-30), y=c(0), \n ylim=c(0.6,1.1), xlim=c(-60,+60),\n xlab=\"\", main=\"\", ylab=\"\")\n\n## grid lines\ngrid(col=\"#404040\", lty=\"solid\", lwd=1)\n\n## title\ntitle(main=\"\", \n xlab=\"TSB\",\n ylab=\"IF\")\n\n## abline\nabline(h=0.85, slope=0, lty=\"dashed\", col=\"white\")\nabline(v=0, slope=1, lty=\"dashed\", col=\"white\")\n\nfor (compare in compares) {\n\n # combine pmc and metric data\n z <- merge(compare$metrics, pmc, by=\"date\")\n\n # area of circle should be proportional\n radius <- sqrt( z$cTSS\/ 3.1415927 )\n\n # plot using ride colors if not comparing\n # or only one date range selected\n if (length(compares) == 1) {\n\n # make transparent for overlapping\n colors <- adjustcolor(z$color, 0.6)\n\n symbols(z$sb, z$IF, \n circles=radius,\n inches=0.4,\n add=TRUE,\n bg=colors,fg=colors,\n xlab=\"\", ylab=\"\")\n } else {\n\n # make transparent for overlapping\n color <- adjustcolor(compare$color, 0.6)\n\n symbols(z$sb, z$IF, \n circles=radius,\n inches=0.4,\n add=TRUE,\n bg=color,\n fg=color,\n xlab=\"\", ylab=\"\")\n\n\n }\n\n # labels for each bubble\n ##text(z$\"4\", z$IF, z$Workout_Code, col=\"gray\", cex=0.5)\n}\n\n## name the quadrants\ntext(-30,0.6, \"Maintain\", col=\"darkgray\", cex=1)\ntext(30,1.09, \"Race\", col=\"darkgray\", cex=1)\ntext(-30,1.09, \"Overload\", col=\"darkgray\", cex=1)\ntext(30,0.6, \"Junk\", col=\"darkgray\", cex=1) ",
|
||||||
"state":" ",
|
"state":" ",
|
||||||
"showConsole":"0",
|
"showConsole":"0",
|
||||||
"__LAST__":"1",
|
"__LAST__":"1",
|
||||||
|
|||||||
Reference in New Issue
Block a user