Socket
Socket
Sign inDemoInstall

mapd-crossfilter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.2.0

.prettierrc.json

11

package.json
{
"name": "mapd-crossfilter",
"version": "1.0.0",
"version": "1.2.0",
"license": "Apache-2.0",

@@ -14,9 +14,11 @@ "description": "Fast multidimensional filtering for coordinated views.",

"test": "nyc npm run test:unit --",
"test:unit": "mocha --require test/config.js test/"
"test:unit": "mocha --require test/config.js --timeout 4000 test/",
"format": "prettier --write '{src,test}/**/*.js'",
"format:check": "prettier --debug-check --list-different '{src,test}/**/*.js'"
},
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.24.1",
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.2",
"babel-loader": "^6.4.1",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",

@@ -30,2 +32,3 @@ "babel-preset-stage-0": "^6.24.1",

"nyc": "^10.3.0",
"prettier": "1.10.2",
"webpack": "^3.10.0"

@@ -32,0 +35,0 @@ },

@@ -0,1 +1,2 @@

const MS_IN_SECS = 0.001
const SEC = 1

@@ -12,2 +13,3 @@ const MIN_IN_SECS = 60

export const TIME_LABEL_TO_SECS = {
millisecond: MS_IN_SECS,
second: SEC,

@@ -24,11 +26,3 @@ minute: MIN_IN_SECS,

export const DAYS = [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
];
export const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

@@ -47,5 +41,5 @@ export const MONTHS = [

"Nov",
"Dec",
];
"Dec"
]
export const QUARTERS = ["Q1", "Q2", "Q3", "Q4"];
export const QUARTERS = ["Q1", "Q2", "Q3", "Q4"]

@@ -1,37 +0,46 @@

import {TIME_LABEL_TO_SECS, TIME_SPANS} from "../constants";
import { TIME_LABEL_TO_SECS, TIME_SPANS } from "../constants"
export function unBinResults(queryBinParams, results) {
var numRows = results.length;
var numRows = results.length
for (var b = 0; b < queryBinParams.length; b++) {
if (queryBinParams[b] === null) continue;
if (queryBinParams[b] === null) continue
const queryBinParam = queryBinParams[b];
const { numBins, binBounds, extract } = queryBinParam;
const keyName = "key" + b.toString();
const queryBinParam = queryBinParams[b]
const { numBins, binBounds, extract } = queryBinParam
const keyName = "key" + b.toString()
if (binBounds[0] instanceof Date && binBounds[1] instanceof Date) {
// jscs:disable
const binBoundsMsMinMax = [binBounds[0].getTime(), binBounds[1].getTime()];
const timeBin = queryBinParam.timeBin;
const binBoundsMsMinMax = [binBounds[0].getTime(), binBounds[1].getTime()]
const timeBin = queryBinParam.timeBin
if (extract) {
for (var r = 0; r < numRows; ++r) {
const result = results[r][keyName];
if (result === null) { continue }
results[r][keyName] = [{
value: result,
timeBin,
isExtract: true,
extractUnit: timeBin,
}, ];
const result = results[r][keyName]
if (result === null) {
continue
}
results[r][keyName] = [
{
value: result,
timeBin,
isExtract: true,
extractUnit: timeBin
}
]
}
// jscs:enable
// jscs:enable
} else {
const intervalMs = TIME_LABEL_TO_SECS[timeBin] * 1000;
const intervalMs = TIME_LABEL_TO_SECS[timeBin] * 1000
for (var r = 0; r < numRows; ++r) {
const result = results[r][keyName];
if (result === null) { continue }
const result = results[r][keyName]
if (result === null) {
continue
}
// jscs:disable
const minValue = result instanceof Date ? result : new Date(binBoundsMsMinMax[0] + result * intervalMs)
const minValue =
result instanceof Date
? result
: new Date(binBoundsMsMinMax[0] + result * intervalMs)
const min = {

@@ -41,4 +50,4 @@ value: minValue,

isBin: true,
binUnit: timeBin,
};
binUnit: timeBin
}

@@ -50,16 +59,18 @@ const maxValue = new Date(minValue.getTime() + intervalMs - 1)

isBin: true,
binUnit: timeBin,
};
binUnit: timeBin
}
// jscs:enable
results[r][keyName] = [min, max];
results[r][keyName] = [min, max]
}
}
} else {
var unitsPerBin = (binBounds[1] - binBounds[0]) / numBins;
var unitsPerBin = (binBounds[1] - binBounds[0]) / numBins
for (var r = 0; r < numRows; ++r) {
if (results[r][keyName] === null) { continue }
const min = (results[r][keyName] * unitsPerBin) + binBounds[0];
const max = min + unitsPerBin;
results[r][keyName] = [min, max];
if (results[r][keyName] === null) {
continue
}
const min = results[r][keyName] * unitsPerBin + binBounds[0]
const max = min + unitsPerBin
results[r][keyName] = [min, max]
}

@@ -69,3 +80,3 @@ }

return results;
return results
}

@@ -1,10 +0,10 @@

import {formGroupSizeQuery} from "./query";
import {createQueryTask, runQueryTask} from "./task";
import { formGroupSizeQuery } from "./query"
import { createQueryTask, runQueryTask } from "./task"
/* istanbul ignore next */
export function mapResultToArray(queryResult, dimArrayAsArg) {
return dimArrayAsArg.map(function (v, d) {
var varName = "n" + d.toString();
return queryResult[varName];
});
return dimArrayAsArg.map(function(v, d) {
var varName = "n" + d.toString()
return queryResult[varName]
})
}

@@ -15,24 +15,24 @@

return function sizeAsyncWithState(state, ignoreFilters, callback) {
var query = formGroupSizeQuery(writeFilter, state, ignoreFilters);
var task = createQueryTask(queryTask, query);
var query = formGroupSizeQuery(writeFilter, state, ignoreFilters)
var task = createQueryTask(queryTask, query)
if (!state.multiDim) {
runQueryTask(task, function (error, result) {
runQueryTask(task, function(error, result) {
if (error) {
callback(error);
callback(error)
} else {
callback(null, result[0].n);
callback(null, result[0].n)
}
});
})
} else {
runQueryTask(task, function (error, result) {
runQueryTask(task, function(error, result) {
if (error) {
callback(error);
callback(error)
} else {
var queryResult = result[0];
var multiResult = mapResultToArray(queryResult, state.dimArray);
callback(null, multiResult);
var queryResult = result[0]
var multiResult = mapResultToArray(queryResult, state.dimArray)
callback(null, multiResult)
}
});
})
}
};
}
}

@@ -43,12 +43,12 @@

return function sizeSyncWithState(state, ignoreFilters) {
var query = formGroupSizeQuery(writeFilter, state, ignoreFilters);
var task = createQueryTask(queryTask, query);
var query = formGroupSizeQuery(writeFilter, state, ignoreFilters)
var task = createQueryTask(queryTask, query)
if (!state.multiDim) {
var result = runQueryTask(task);
return result[0].n;
var result = runQueryTask(task)
return result[0].n
} else {
var queryResult = runQueryTask(task);
return mapResultToArray(queryResult, state.dimArray);
var queryResult = runQueryTask(task)
return mapResultToArray(queryResult, state.dimArray)
}
};
}
}
export function formGroupSizeQuery(writeFilter, state, ignoreFilters) {
var query = "SELECT ";
var query = "SELECT "
for (var d = 0; d < state.dimArray.length; d++) {
if (d > 0) {
query += ",";
query += ","
}
query += "APPROX_COUNT_DISTINCT(" + state.dimArray[d] + ") AS n";
query += "APPROX_COUNT_DISTINCT(" + state.dimArray[d] + ") AS n"
if (state.multiDim) {
query += d.toString();
query += d.toString()
}
}
query += " FROM " + state._tablesStmt;
query += " FROM " + state._tablesStmt
if (!ignoreFilters) {
// freeze bin state so they don"t change out from under us
var queryBinParams = Array.isArray(state._binParams) ? [].concat(state._binParams) : [];
var queryBinParams = Array.isArray(state._binParams)
? [].concat(state._binParams)
: []
if (!queryBinParams.length) {
queryBinParams = null;
queryBinParams = null
}
var filterQuery = writeFilter(queryBinParams);
var filterQuery = writeFilter(queryBinParams)
if (filterQuery != "") {
query += " WHERE " + filterQuery;
query += " WHERE " + filterQuery
}
if (state._joinStmt !== null) {
if (filterQuery === "") {
query += " WHERE ";
query += " WHERE "
} else {
query += " AND ";
query += " AND "
}
query += state._joinStmt;
query += state._joinStmt
}
} else {
if (state._joinStmt !== null) {
query += " WHERE " + state._joinStmt;
query += " WHERE " + state._joinStmt
}
}
return query;
return query
}
export function createQueryTask(method, query, options) {
return function (callback) {
return method(query, options, callback);
};
return function(callback) {
return method(query, options, callback)
}
}

@@ -9,11 +9,11 @@

if (callback) {
task(callback);
task(callback)
} else {
try {
var result = task();
return result;
var result = task()
return result
} catch (e) {
throw e;
throw e
}
}
}

@@ -1,5 +0,9 @@

import chai, {expect} from 'chai'
import {formatDateResult, formatExtractResult, unBinResults} from '../src/modules/binning'
import chai, { expect } from "chai"
import {
formatDateResult,
formatExtractResult,
unBinResults
} from "../src/modules/binning"
function unBinTime (range) {
function unBinTime(range) {
return range.map(date => ({

@@ -11,19 +15,19 @@ alias: date,

describe('Binning Module', () => {
describe("Binning Module", () => {
describe("unBinResults", () => {
it("skips over null queryBinParams", () => {
const binParams = [
{numBins: 12, binBounds: [0, 1350]},
{ numBins: 12, binBounds: [0, 1350] },
null,
{numBins: 7, binBounds: [2, 19]}
{ numBins: 7, binBounds: [2, 19] }
]
const results = [
{key0: 0, val: 4507041},
{key0: 1, val: 1875013},
{key0: 2, val: 425687}
{ key0: 0, val: 4507041 },
{ key0: 1, val: 1875013 },
{ key0: 2, val: 425687 }
]
expect(unBinResults(binParams, results)).to.deep.equal([
{key0: [0, 112.5], key2: [NaN, NaN], val: 4507041},
{key0: [112.5, 225], key2: [NaN, NaN], val: 1875013},
{key0: [225, 337.5], key2: [NaN, NaN], val: 425687}
{ key0: [0, 112.5], key2: [NaN, NaN], val: 4507041 },
{ key0: [112.5, 225], key2: [NaN, NaN], val: 1875013 },
{ key0: [225, 337.5], key2: [NaN, NaN], val: 425687 }
])

@@ -33,15 +37,17 @@ })

it("returns list of [min] for date queryBounds when results are date-times", () => {
const binParams = [{
numBins: 4,
binBounds: [new Date("1/1/16"), new Date("1/4/16")]
}]
const binParams = [
{
numBins: 4,
binBounds: [new Date("1/1/16"), new Date("1/4/16")]
}
]
const results = [
{key0: new Date("1/1/16"), val: 4507041},
{key0: new Date("1/2/16"), val: 1875013},
{key0: new Date("1/3/16"), val: 425687}
{ key0: new Date("1/1/16"), val: 4507041 },
{ key0: new Date("1/2/16"), val: 1875013 },
{ key0: new Date("1/3/16"), val: 425687 }
]
const unbinnedResults = unBinResults(binParams, results)
const aliases = unbinnedResults.map(({key0}) => key0[0].alias)
const values = unbinnedResults.map(({key0}) => key0[0].value)
const vals = unbinnedResults.map(({val}) => val)
const aliases = unbinnedResults.map(({ key0 }) => key0[0].alias)
const values = unbinnedResults.map(({ key0 }) => key0[0].value)
const vals = unbinnedResults.map(({ val }) => val)

@@ -54,23 +60,21 @@ expect(values).to.deep.equal([

expect(vals).to.deep.equal([
4507041,
1875013,
425687
])
expect(vals).to.deep.equal([4507041, 1875013, 425687])
})
it("returns list of [min, max] for date queryBounds when results are numerical", () => {
const binParams = [{
numBins: 25,
binBounds: [new Date("1/1/16"), new Date("1/4/16")],
timeBin: "day"
}]
const binParams = [
{
numBins: 25,
binBounds: [new Date("1/1/16"), new Date("1/4/16")],
timeBin: "day"
}
]
const results = [
{key0: 0, val: 4507041},
{key0: 1, val: 1875013},
{key0: 2, val: 425687}
{ key0: 0, val: 4507041 },
{ key0: 1, val: 1875013 },
{ key0: 2, val: 425687 }
]
const unbinnedResults = unBinResults(binParams, results)
const aliases = unbinnedResults.map(({key0}) => key0[0].alias)
const values = unbinnedResults.map(({key0}) => key0[0].value)
const vals = unbinnedResults.map(({val}) => val)
const aliases = unbinnedResults.map(({ key0 }) => key0[0].alias)
const values = unbinnedResults.map(({ key0 }) => key0[0].value)
const vals = unbinnedResults.map(({ val }) => val)

@@ -83,7 +87,3 @@ expect(values).to.deep.equal([

expect(vals).to.deep.equal([
4507041,
1875013,
425687
])
expect(vals).to.deep.equal([4507041, 1875013, 425687])
})

@@ -94,8 +94,5 @@

{
"numBins": 12,
"binBounds": [
0,
1350
],
"timeBin": null
numBins: 12,
binBounds: [0, 1350],
timeBin: null
}

@@ -105,44 +102,44 @@ ]

{
"key0": 0,
"val": 4507041
key0: 0,
val: 4507041
},
{
"key0": 1,
"val": 1875013
key0: 1,
val: 1875013
},
{
"key0": 2,
"val": 425687
key0: 2,
val: 425687
},
{
"key0": 3,
"val": 41650
key0: 3,
val: 41650
},
{
"key0": 4,
"val": 5021
key0: 4,
val: 5021
},
{
"key0": 5,
"val": 608
key0: 5,
val: 608
},
{
"key0": 6,
"val": 3
key0: 6,
val: 3
},
{
"key0": 7,
"val": 2
key0: 7,
val: 2
},
{
"key0": 9,
"val": 1
key0: 9,
val: 1
},
{
"key0": 10,
"val": 1
key0: 10,
val: 1
},
{
"key0": 8,
"val": 1
key0: 8,
val: 1
}

@@ -152,96 +149,65 @@ ]

{
"key0": [
0,
112.5
],
"val": 4507041
key0: [0, 112.5],
val: 4507041
},
{
"key0": [
112.5,
225
],
"val": 1875013
key0: [112.5, 225],
val: 1875013
},
{
"key0": [
225,
337.5
],
"val": 425687
key0: [225, 337.5],
val: 425687
},
{
"key0": [
337.5,
450
],
"val": 41650
key0: [337.5, 450],
val: 41650
},
{
"key0": [
450,
562.5
],
"val": 5021
key0: [450, 562.5],
val: 5021
},
{
"key0": [
562.5,
675
],
"val": 608
key0: [562.5, 675],
val: 608
},
{
"key0": [
675,
787.5
],
"val": 3
key0: [675, 787.5],
val: 3
},
{
"key0": [
787.5,
900
],
"val": 2
key0: [787.5, 900],
val: 2
},
{
"key0": [
1012.5,
1125
],
"val": 1
key0: [1012.5, 1125],
val: 1
},
{
"key0": [
1125,
1237.5
],
"val": 1
key0: [1125, 1237.5],
val: 1
},
{
"key0": [
900,
1012.5
],
"val": 1
key0: [900, 1012.5],
val: 1
}
])
})
it('should handle when bin param is extract', () => {
const binParams = [{
numBins: 4,
binBounds: [new Date("1/1/16"), new Date("1/4/16")],
extract: true,
timeBin: "day"
}]
it("should handle when bin param is extract", () => {
const binParams = [
{
numBins: 4,
binBounds: [new Date("1/1/16"), new Date("1/4/16")],
extract: true,
timeBin: "day"
}
]
const results = [
{key0: 1, val: 4507041},
{key0: 2, val: 1875013},
{key0: 3, val: 425687}
{ key0: 1, val: 4507041 },
{ key0: 2, val: 1875013 },
{ key0: 3, val: 425687 }
]
expect(unBinResults(binParams, results).map(a => a.key0)).to.deep.equal([
[ { value: 1, extractUnit: 'day', isExtract: true, timeBin: 'day' } ],
[ { value: 2, extractUnit: 'day', isExtract: true, timeBin: 'day'} ],
[ { value: 3, extractUnit: 'day', isExtract: true, timeBin: 'day'} ]
[{ value: 1, extractUnit: "day", isExtract: true, timeBin: "day" }],
[{ value: 2, extractUnit: "day", isExtract: true, timeBin: "day" }],
[{ value: 3, extractUnit: "day", isExtract: true, timeBin: "day" }]
])

@@ -248,0 +214,0 @@ })

@@ -1,48 +0,36 @@

import chai, {expect} from 'chai'
import {sizeAsyncWithEffects, sizeSyncWithEffects} from '../src/modules/group'
import spies from 'chai-spies'
import chai, { expect } from "chai"
import { sizeAsyncWithEffects, sizeSyncWithEffects } from "../src/modules/group"
import spies from "chai-spies"
chai.use(spies)
const noop = () => {}
describe('group module', () => {
describe('sizeAsyncWithEffects', () => {
it('should return a function', () => {
expect(typeof sizeAsyncWithEffects()).to.equal('function')
describe("group module", () => {
describe("sizeAsyncWithEffects", () => {
it("should return a function", () => {
expect(typeof sizeAsyncWithEffects()).to.equal("function")
})
describe('when multiDim', () => {
describe('and when result is error', () => {
it('should call callback with error', () => {
})
describe("when multiDim", () => {
describe("and when result is error", () => {
it("should call callback with error", () => {})
})
describe('and when result is success', () => {
it('should call callback with result', () => {
})
describe("and when result is success", () => {
it("should call callback with result", () => {})
})
})
describe('when not multiDim', () => {
describe('when result is error', () => {
it('should call callback with error', () => {
})
describe("when not multiDim", () => {
describe("when result is error", () => {
it("should call callback with error", () => {})
})
describe('when result is success', () => {
it('should call callback with result', () => {
})
describe("when result is success", () => {
it("should call callback with result", () => {})
})
})
})
describe('sizeSyncWithEffects', () => {
it('should return a function', () => {
expect(typeof sizeSyncWithEffects()).to.equal('function')
describe("sizeSyncWithEffects", () => {
it("should return a function", () => {
expect(typeof sizeSyncWithEffects()).to.equal("function")
})
describe('when multiDim', () => {
})
describe('when not multiDim', () => {
})
describe("when multiDim", () => {})
describe("when not multiDim", () => {})
})
})

@@ -1,10 +0,10 @@

import chai, {expect} from 'chai'
import {createQueryTask, runQueryTask} from '../src/modules/task'
import spies from 'chai-spies'
import chai, { expect } from "chai"
import { createQueryTask, runQueryTask } from "../src/modules/task"
import spies from "chai-spies"
const noop = () => {}
chai.use(spies)
describe('task module', () => {
describe('createQueryTask function', () => {
const query = 'test'
describe("task module", () => {
describe("createQueryTask function", () => {
const query = "test"
const options = { queryId: -1 }

@@ -15,7 +15,7 @@ const method = chai.spy()

it('should return a function', () => {
expect(typeof thunk).to.equal('function')
it("should return a function", () => {
expect(typeof thunk).to.equal("function")
})
it('should run the passed in method with the callback and query', () => {
it("should run the passed in method with the callback and query", () => {
thunk(callback)

@@ -26,5 +26,5 @@ expect(method).to.have.been.called.with(query, options, callback)

describe('runQueryTask function', () => {
describe('with callback', () => {
it('should run task with callback as argument', () => {
describe("runQueryTask function", () => {
describe("with callback", () => {
it("should run task with callback as argument", () => {
const task = chai.spy()

@@ -36,10 +36,10 @@ const callback = noop

})
describe('without callback', () => {
it('should run the task and reutrn the result', () => {
const result = 'test'
describe("without callback", () => {
it("should run the task and reutrn the result", () => {
const result = "test"
expect(runQueryTask(() => result)).to.equal(result)
})
it('should throw an error if the task errors out', () => {
const error = 'Error'
it("should throw an error if the task errors out", () => {
const error = "Error"
try {

@@ -46,0 +46,0 @@ runQueryTask(() => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc