How to use the thingtalk.Builtin function in thingtalk

To help you get started, we’ve selected a few thingtalk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stanford-oval / almond-dialog-agent / lib / dialogs / entity_lookup.js View on Github external
candidates.sort((l1, l2) => {
            let current = { y: currentLocation.value.lat, x: currentLocation.value.lon };
            l1 = { y: l1.lat, x: l1.lon };
            l2 = { y: l2.lat, x: l2.lon };
            return ThingTalk.Builtin.distance(l1, current) - ThingTalk.Builtin.distance(l2, current);
        });
    }
github stanford-oval / thingengine-core / lib / apps / exec_wrapper.js View on Github external
_findInCache(fnid, params) {
        const fn = this._functions[fnid];

        for (let cached of this._execCache) {
            let [kind, channel, cachedparams, result] = cached;
            if (kind === fn.selector.kind && channel === fn.channel &&
                ThingTalk.Builtin.equality(cachedparams, params))
                return result;
        }
        return null;
    }
    clearGetCache() {
github stanford-oval / thingengine-core / lib / tiers / protocol.js View on Github external
marshal(value) {
        if (value === null || value === undefined)
            return null;
        if (value instanceof Array)
            return value.map(ValueProto.marshal);
        else if (value instanceof ThingTalk.Builtin.Entity)
            return { tag: 'entity', v: value.value, d: value.display };
        else if (value instanceof ThingTalk.Builtin.Currency)
            return { tag: 'currency', v: value.value, c: value.code };
        else if (value instanceof ThingTalk.Builtin.Location)
            return { tag: 'loc', x: value.x, y: value.y, d: value.display };
        else if (value instanceof ThingTalk.Builtin.Time)
            return { tag: 'time', h: value.hour, m: value.minute, s: value.second };
        else if (value instanceof Date)
            return { tag: 'date', v: value.getTime() };
        else
            return value;
    },
github stanford-oval / thingengine-core / lib / tiers / protocol.js View on Github external
unmarshal(value) {
        if (value === null || value === undefined)
            return null;
        if (value instanceof Array) {
            return value.map(ValueProto.unmarshal);
        } else {
            switch (value.tag) {
            case 'date':
                return new Date(value.v);
            case 'currency':
                return new ThingTalk.Builtin.Currency(value.v, value.c);
            case 'entity':
                return new ThingTalk.Builtin.Entity(value.v, value.d);
            case 'loc':
                return new ThingTalk.Builtin.Location(value.y, value.x, value.d);
            case 'time':
                return new ThingTalk.Builtin.Time(value.h, value.m, value.s);
            default:
                return value;
            }
        }
    }
};
github stanford-oval / thingengine-core / lib / devices / modules / generic.js View on Github external
function extractOne(result) {
                        let extracted = {};
                        for (let arg of block.args) {
                            if (arg.is_input)
                                continue;
                            if (arg.json_key)
                                extracted[arg.name] = get(result, arg.json_key);
                            else
                                extracted[arg.name] = result[arg.name];
                            if (arg.type === 'Date')
                                extracted[arg.name] = new Date(extracted[arg.name]);
                            else if (arg.type === 'Currency' && typeof extracted[arg.name] === 'number')
                                extracted[arg.name] = new ThingTalk.Builtin.Currency(extracted[arg.name], 'usd');
                            else if (arg.type === 'Currency' && typeof extracted[arg.name] === 'string')
                                extracted[arg.name] = new ThingTalk.Builtin.Currency(parseFloat(extracted[arg.name]), 'usd');
                        }
                        return extracted;
                    }