RTransform()

Transforms an array of values with timestamps to an array of values with equidistant timestamps and optionally calculates transformation quality indicators.

Synopsis

int RTransform( int order, int intervalStartTime, time t1, time t2, float interval, const dyn_float values, const dyn_time times, int returnType, dyn_anytype& transValues, dyn_time& transTimes, bool qual=FALSE, float& qualAvgValInt, float& qualMAE, float& qualNMAE);

Parameters

Parameter Description
order Method of averaging - 0 .. step, 1 .. average
intervalStartTime Alignment of result timestamps (0 .. start of interval, 1 .. middle of interval, 2 .. end of interval)
t1 Start time of target values
t2 End time of target values
interval Target interval duration in seconds.
values Array of values to be transformed
times Array of value timestamps to be transformed
returnType Data type to be returned
transValues Return array of transformed values
transTimes Return array of transformed value timestamps
qual true .. Transformation quality indicators will be calculated
qualAvgValInt Average value interval quality - see chapter Data mining Wizard - Session
qualMAE MAE quality - see chapter Data mining Wizard - Session
qualNMAE NMAE quality - see chapter Data mining Wizard - Session

Return Value

The function returns 0 if it was successfully executed.

Description

Transforms an array of values with timestamps to an array of values with equidistant timestamps and optionally calculates transformation quality indicators.

Example

Transforms an array of values with timestamps to an array of values with equidistant timestamps and calculates transformation quality indicators.

#uses "CtrlR"
main()
{
  dyn_float df1 = makeDynFloat(31,31,33,32,34,33,32,35,29,34,38,40,37,38,36,36,36,39,38,40,35,32,34,32,34,29,29,28,31,28,30,34,33,28,31,32,33,33,33,35,36,36,40,38,40,37,40,38,40,38);
  dyn_float df2 = makeDynFloat(401,381,382,392,406,372,361,405,392,399,350,342,346,354,304,345,320,317,356,323,386,406,405,396,400,401,365,400,391,398,362,368,363,373,389,370,406,386,402,367,379,380,406,389,374,379,399,406,377,407);
  dyn_float df3 = makeDynFloat(89,85,90,90,99,88,83,102,81,97,95,98,92,96,78,89,83,89,97,93,97,93,99,91,97,83,76,80,87,80,78,90,86,75,86,85,96,91,95,92,98,98,116,106,107,100,114,111,108,111);
  dyn_float df4 = makeDynFloat(63,97,73,73,75,75,80,93,96,77,86,81,85,83,74,68,73,63,86,60,85,93,90,79,79,68,81,66,65,95,96,71,72,81,73,63,84,75,67,77,73,85,100,95,74,71,97,98,67,63);
  dyn_float df5 = makeDynFloat(4,10,10,-4,8,8,-3,3,8,9,6,7,0,3,10,8,3,9,10,8,9,-3,6,9,1,3,6,-4,0,-2,-2,7,6,3,-2,6,8,8,0,3,-3,2,3,10,6,1,4,4,2,8);
  dyn_float df6 = makeDynFloat(35,32,34,34,38,34,33,36,31,30,37,39,39,34,33,39,30,33,37,35,44,40,41,41,43,44,44,40,42,45,37,30,30,33,33,35,36,39,36,34,34,30,32,30,30,32,31,34,35,38);
  int order = 1;
  int intervalStartTime = 1; /*Alignment of result timestamps (0 .. start of interval, 1 .. middle of interval, 2 .. end of interval)*/
  time start_time; //Start time of target values
  time end_time; //End time of target values
  float interval; //Target interval duration
  dyn_float values = df1; //Array of values to be transformed
  dyn_time times; //TODO generate dynamically
  dyn_float transValues; //Return array of transformed values
  dyn_time transTimes; //Return array of transformed value
  timestamps
  bool qual = TRUE; //true .. Transformation quality indicators will be calculated
  float qualAvgValInt; //Average value interval quality - see chapter Data mining Wizard - Session
  float qualMAE; //MAE quality - see chapter Data mining Wizard - Session
  float qualNMAE; //NMAE quality - see chapter Data mining Wizard - Session
  //generate timestamps
  setRandomTime(start_time);
  DebugN(start_time);
  int val_len = dynlen(values);
  times[1] = start_time;
  for(int i=2; i <= val_len; i++)
  {
    int offset = rand() % 10000; //offset in seconds
    times[i] = times[i-1] + offset;
  }
  DebugN(values);
  DebugN(times);
  end_time = times[val_len];
  interval = 5000;
  int rc = RTransform(order, intervalStartTime, start_time, end_time, interval, values, times, getType(df1[1]), transValues, transTimes, qual, qualAvgValInt, qualMAE, qualNMAE);
  //Function call RTransform
  DebugN("Return value:", "Transformed values:", transValues, "Transformed times:", transTimes, qualAvgValInt, qualMAE, qualNMAE );
  //Debug transformed values
}
void setRandomTime(time& t) //generate timestamps
{
  int y = 2016;
  int m = 1;
  int d = 1;
  int h = rand() % 24;
  int min = rand() % 60;
  int sec = rand() % 60;
  setTime(t, y, m, d, h, min, sec);
}

Assignment

R Functions

Availability

R Control Extension

See also

R Control Extension Functions