Transformer - Scoped, Global

Manipulate time-series data to prepare the data for evaluation and analysis.

The Transformer class can be used in scoped and global server scripts. When using the Transformer class, use the sn_clotho namespace identifier.

The general use case is to determine the period to be evaluated, select the records from the table with the metric field, define the type of transform to run, and then execute the transform.
// create the start and end time
       var start = new GlideDateTime();
	start.addSeconds(-1 * 60 * 60); 
	var end = new GlideDateTime();
	
	//mb_demo_drone is a table with metric fields. 
	var drones = new GlideRecord("mb_demo_drone");
	drones.addQuery("model", "Kingfisher Phantom");
	drones.query();

	//build a transform that returns a simple average
	var builder = new sn_clotho.Transformer(drones);
	builder.metric("mb_demo_mt_rem_battery").avg().label("Original");

	//execute transform and return result for visualization
	var result = builder.execute(start,end);

This class is part of the MetricBase application.

Scoped Transformer - execute(GlideDateTime start, GlideDateTime end)

Run the transform.

Use the metric() and groupBy() methods before calling execute(). The execute() method can only be called once for each Transformer object.

Actions performed as part of the transform do not change the data in the MetricBase database.

Table 1. Parameters
Name Type Description
start GlideDateTime The beginning of the period to be evaluated.
end GlideDateTime The end of the period to be evaluated.
Table 2. Returns
Type Description
TransformResult The transformed data.
var minutesAgoStart = 60;
	var end = new GlideDateTime();
	var start = new GlideDateTime(end);
	start.addSeconds(-1 * 60 * minutesAgoStart);
	
	// query subject records
	var grDrone = new GlideRecord('mb_demo_drone');
	grDrone.query();
	
	// building transform; get the average transforms of a metric, grouping by model
	var transformer = new sn_clotho.Transformer(grDrone);
	transformer.groupBy("fleet").metric("mb_demo_mt_altitude").avg().label('avg - %g:fleet:');

	// execute and return result for visualization
	var tfrmResult = transformer.execute(start, end);

Scoped Transformer - groupBy(String field)

Specify a field to be used to group the data.

If you are going to use the groupBy() method, it must be called before the execute() method.

Table 3. Parameters
Name Type Description
field String A field in the table to be used to group the transform results.
Table 4. Returns
Type Description
TransformPart A TransformPart object that can be used to specify the transform characteristics.
var transformer = new sn_clotho.Transformer(grDrone);
	var trnsfrm = transformer.groupBy("fleet");

Scoped Transformer - metric(String metricName)

Specify the metric field to be used in the transform.

You can specify multiple metrics to be used in the transform. The metric() method cannot be called after the execute() method is called.

Table 5. Parameters
Name Type Description
metricName String Name of the metric field.
Table 6. Returns
Type Description
TransformPart A TransformPart object that can be used to specify the transform characteristics.
var transformer = new sn_clotho.Transformer(grDrone);
var trnsfrm = transformer.metric("mb_demo_mt_altitude");

Scoped Transformer - transformer( GlideRecord sourceRecords)

Create a Transformer object.

Table 7. Parameters
Name Type Description
sourceRecords GlideRecord Contains the records for which metrics are to be evaluated. Can be one record or many.
//where drones is a GlideRecord created from a table with a metric field
	var builder = new sn_clotho.Transformer(drones);