import {VM} from 'vm2'
import SensorData from './SensorData'

export default class Calibrator {
	calibrate (data, cb) {
		if ( ! (data instanceof SensorData)) return cb('Invalid SensorData given.')

		var meta = data.getMetadata()

		meta.getAttributes().forEach(function (attr) {
			attr.getProperties().forEach(function (prop) {
				if (prop.name !== 'calibrate') return

				var vm = new VM({
					timeout: 1000,
					sandbox: {
						val: data.getValue(attr.getName())
					},
				})
				var value = vm.run('(' + decodeURI(prop.value) + ')(val)')
				data.setValue(attr.getName(), value)
			})
		})

		cb()
	}
}

@@ -425,16 +425,34 @@
 dbox: %7B%0A
+%09%09%09%09%09%09Math: Math,%0A
 %09%09%09%09%09%09va
@@ -548,16 +548,27 @@
 op.value
+.toString()
 ) + ')(v

Add Math to calibrator VM and allow use of functions (not only function strings).