Code coverage report for src/encdef.js

Statements: 86.96% (80 / 92)      Branches: 78.48% (62 / 79)      Functions: 76.92% (10 / 13)      Lines: 86.81% (79 / 91)      Ignored: none     

All files » src/ » encdef.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144  1 1 1 1 1 613 613 613 23   590     590 228 228   362 74   288 26     262     1   1           1   1       1   1 2 2       2 27 27 1 1   1 1     2 14 14           2       2   1   1 1054   1   1 719 1304 245   474   1   1 169     1   1 362     1 213   1   1 149   1   1     1   1 1 784   1   1   123 123 123 123 27 27   96 8 8     96 29   67     1    
// utility for field
var consts_1 = require('./consts');
var util = require('./util');
var time = require('./compiler/time');
var schema = require('./schema/schema');
function fieldRef(field, opt) {
    opt = opt || {};
    var f = (opt.datum ? 'datum.' : '') + (opt.prefn || ''), name = field.name;
    if (isCount(field)) {
        return f + 'count';
    }
    else Iif (opt.fn) {
        return f + opt.fn + '_' + name;
    }
    else if (!opt.nofn && field.bin) {
        var bin_suffix = opt.bin_suffix || '_start';
        return f + 'bin_' + name + bin_suffix;
    }
    else if (!opt.nofn && !opt.noAggregate && field.aggregate) {
        return f + field.aggregate + '_' + name;
    }
    else if (!opt.nofn && field.timeUnit) {
        return f + field.timeUnit + '_' + name;
    }
    else {
        return f + name;
    }
}
exports.fieldRef = fieldRef;
;
function shorthand(f) {
    return (f.aggregate ? f.aggregate + consts_1.Shorthand.Func : '') +
        (f.timeUnit ? f.timeUnit + consts_1.Shorthand.Func : '') +
        (f.bin ? 'bin' + consts_1.Shorthand.Func : '') +
        (f.name || '') + consts_1.Shorthand.Type + f.type;
}
exports.shorthand = shorthand;
;
function shorthands(fields, delim) {
    delim = delim || consts_1.Shorthand.Delim;
    return fields.map(shorthand).join(delim);
}
exports.shorthands = shorthands;
;
function fromShorthand(shorthand) {
    var split = shorthand.split(consts_1.Shorthand.Type), i;
    var o = {
        name: split[0].trim(),
        type: split[1].trim()
    };
    for (i in schema.aggregate.enum) {
        var a = schema.aggregate.enum[i];
        if (o.name.indexOf(a + '_') === 0) {
            o.name = o.name.substr(a.length + 1);
            Iif (a == 'count' && o.name.length === 0)
                o.name = '*';
            o.aggregate = a;
            break;
        }
    }
    for (i in schema.timeUnits) {
        var tu = schema.timeUnits[i];
        Iif (o.name && o.name.indexOf(tu + '_') === 0) {
            o.name = o.name.substr(o.name.length + 1);
            o.timeUnit = tu;
            break;
        }
    }
    Iif (o.name && o.name.indexOf('bin_') === 0) {
        o.name = o.name.substr(4);
        o.bin = true;
    }
    return o;
}
exports.fromShorthand = fromShorthand;
;
function isType(fieldDef, type) {
    return fieldDef.type === type;
}
exports.isType = isType;
;
function isTypes(fieldDef, types) {
    for (var t = 0; t < types.length; t++) {
        if (fieldDef.type === types[t])
            return true;
    }
    return false;
}
exports.isTypes = isTypes;
;
function isOrdinalScale(field) {
    return isTypes(field, [consts_1.Type.N, consts_1.Type.O]) ||
        (isType(field, consts_1.Type.T) && field.timeUnit && time.isOrdinalFn(field.timeUnit));
}
exports.isOrdinalScale = isOrdinalScale;
;
function isFieldDimension(field) {
    return isTypes(field, [consts_1.Type.N, consts_1.Type.O]) || !!field.bin ||
        (isType(field, consts_1.Type.T) && !!field.timeUnit);
}
function isDimension(field) {
    return field && isFieldDimension(field);
}
exports.isDimension = isDimension;
;
function isMeasure(field) {
    return field && !isFieldDimension(field);
}
exports.isMeasure = isMeasure;
;
function count() {
    return { name: '*', aggregate: 'count', type: consts_1.Type.Q, displayName: exports.COUNT_DISPLAYNAME };
}
exports.count = count;
;
exports.COUNT_DISPLAYNAME = 'Number of Records';
function isCount(field) {
    return field.aggregate === 'count';
}
exports.isCount = isCount;
;
function cardinality(field, stats, filterNull) {
    // FIXME need to take filter into account
    if (filterNull === void 0) { filterNull = {}; }
    var stat = stats[field.name];
    var type = field.type;
    if (field.bin) {
        var bins = util.getbins(stat, field.bin.maxbins || schema.MAXBINS_DEFAULT);
        return (bins.stop - bins.start) / bins.step;
    }
    if (isType(field, consts_1.Type.T)) {
        var cardinality = time.cardinality(field, stats, filterNull, type);
        Iif (cardinality !== null)
            return cardinality;
    }
    if (field.aggregate) {
        return 1;
    }
    return stat.distinct -
        (stat.missing > 0 && filterNull[type] ? 1 : 0);
}
exports.cardinality = cardinality;
;
//# sourceMappingURL=encdef.js.map