Example #1
0
it("should make test number 4", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Heat' store. The size of the window is 3 records.
 var aggr = {
    name: 'Delay',
    type: 'recordBuffer',
    size: 3
 };
 base.store("Heat").addStreamAggr(aggr);
 base.close();

});
Example #2
0
it("should make test number 3", function () {
 
 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The size of the window is 2 seconds (2000ms).
 var aggr = {
    name: 'TimeSeriesAggr',
    type: 'timeSeriesWinBuf',
    store: 'Heat',
    timestamp: 'Time',
    value: 'Celcius',
    winsize: 2000
 };
 base.store("Heat").addStreamAggr(aggr); 
 base.close();

});
Example #3
0
it("should make test number 26", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'Signals',
	        fields: [
	            { name: 'BeepLoudness', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series stream aggregator that gets the values from the 'BeepLoudness' field and
	 // the timestamp from the 'Time' field. The window size should be 10 seconds.
	 var ts = {
	    name: 'SignalBeep',
	    type: 'timeSeriesWinBuf',
	    store: 'Signals',
	    timestamp: 'Time',
	    value: 'BeepLoudness',
	    winsize: 10000
	 };
	 var signalBeep = base.store('Signals').addStreamAggr(ts);
	 // add some records to the store
	 base.store('Signals').push({ BeepLoudness: 10, Time: '2015-07-21T12:30:30.0' });
	 base.store('Signals').push({ BeepLoudness: 25, Time: '2015-07-21T12:30:31.0' });
	 base.store('Signals').push({ BeepLoudness: 20, Time: '2015-07-21T12:30:32.0' });
	 // get the timestamp vector of signalBeep
	 var vec = signalBeep.getTimestampVector(); // returns vector [13081955430000, 13081955431000, 13081955432000]
	 base.close();
	
});
Example #4
0
it("should make test number 8", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Students",
        fields: [
            { name: "Id", type: "float" },
            { name: "TimeOfGraduation", type: "datetime" }
        ]
    }]
 });

 // create a new time series tick stream aggregator for the 'Students' store, that takes the values from the 'Id' field
 // and the timestamp from the 'TimeOfGraduation' field.
 var tick = {
    name: 'TimeSeriesTickAggr',
    type: 'timeSeriesTick',
    store: 'Students',
    timestamp: 'TimeOfGraduation',
    value: 'Id',
 };
 var timeSeriesTick = base.store("Students").addStreamAggr(tick);
 base.close();

});
it("should make test number 35", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
          mode: 'createClean',
          schema: [{
            name: 'Docs',
            fields: [
              { name: 'Time', type: 'datetime' },
              { name: 'Text', type: 'string' }
            ]
          }]
     });
     store = base.store('Docs');
	 // the following aggregate maintains a window buffer (1000 milliseconds) with no delay
	 // and contains a categorical feature extractor. The extractor maps records in the buffer
	 // to sparse vectors (indicator vectors for growing set of categories). Each record that
	 // enters the buffer updates the feature extractor (potentially introduces a new category,
	 // which increases the dimensionality).
	 var aggr = {
          type: 'timeSeriesWinBufFeatureSpace',
          store: 'Docs',
          timestamp: 'Time',
          featureSpace: {
            type: "categorical",
            source: "Docs",
            field: "Text"
          },
          winsize: 1000
     };
	 var streamAggregate = store.addStreamAggr(aggr);
	 store.push({ Time: '2015-06-10T14:13:32.0', Text: 'a' });
	 store.push({ Time: '2015-06-10T14:13:33.0', Text: 'b' });
	 store.push({ Time: '2015-06-10T14:13:34.0', Text: 'c' });
	 // we have three dimensions, where "a" -> [1,0,0], "b" -> [0,1,0], "c" -> [0,0,1]
	 // the first record just fell out of the buffer, the third record just entered the buffer
	 // and buffer currently contains the second and the third record.
	 // In case of the feature space based window buffer, the vectors of just-in, just-out and in-the-buffer
	 // values correspond to vectors of sparse vectors = sparse matrices.
	 streamAggregate.getInValueVector().print(); // one column, one nonzero element at index 2
	 // = [
     // 2 0 1.000000
     // ]
	 streamAggregate.getOutValueVector().print(); // one column, one nonzero element at index 0
	 // = [
	 // 0 0 1.000000
	 // ]
	 streamAggregate.getValueVector().print(); // two column vectors, each with one nonzero element
	 // = [
	 // 1 0 1.000000
	 // 2 1 1.000000
	 // ]
	 
	 base.close();
	
});
Example #6
0
it("should make test number 12", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "WaterConsumption", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The size of the window is 1 day.
 var celcius = {
    name: 'CelciusAggr',
    type: 'timeSeriesWinBuf',
    store: 'Heat',
    timestamp: 'Time',
    value: 'Celcius',
    winsize: 86400000
 }; base.store("Heat").addStreamAggr(celcius);

 // create a new time series stream aggregator for the 'Heat' store, that takes the values from the 'WaterConsumption' field
 // and the timestamp from the 'Time' field. The size of the window is 1 day.
 var water = {
    name: 'WaterAggr',
    type: 'timeSeriesWinBuf',
    store: 'Heat',
    timestamp: 'Time',
    value: 'WaterConsumption',
    winsize: 86400000
 }; base.store("Heat").addStreamAggr(water);

 // add a covariance aggregator, that is connected with the 'CelciusAggr' and 'WaterAggr' stream aggregators
 var covariance = {
    name: 'covAggr',
    type: 'covariance',
    store: 'Heat',
    inAggrX: 'CelciusAggr',
    inAggrY: 'WaterAggr'
 };
 var covarianceAggr = base.store("Heat").addStreamAggr(covariance);
 base.close();

});
Example #7
0
    it('should pass', function () {

        var base = new qm.Base({
            mode: 'createClean',
            schema: [
              {
                  name: 'People',
                  fields: [{ name: 'name', type: 'string', primary: true }],
                  joins: [{ name: 'friends', 'type': 'index', 'store': 'People' }]
              }
            ]
        });
        var id1 = base.store('People').push({ name: "John" });
        var id2 = base.store('People').push({ name: "Mary" });
        var id3 = base.store('People').push({ name: "Jim" });

        base.store('People')[id1].$addJoin('friends', id2, 7);
        base.store('People')[id1].$addJoin('friends', id3, 8);

        base.store('People')[id2].$addJoin('friends', base.store('People')[id1], 9);
        base.store('People')[id2].$addJoin('friends', base.store('People')[id2], 3); // narcissism or healthy self-image?

        assert(base.store('People')[id1].friends.length == 2);
        assert(base.store('People')[id1].friends[0].name == "Mary");
        assert(base.store('People')[id1].friends[0].$fq == 7);
        assert(base.store('People')[id1].friends[1].name == "Jim");
        assert(base.store('People')[id1].friends[1].$fq == 8);

        assert(base.store('People')[id2].friends.length == 2);
        assert(base.store('People')[id2].friends[0].name == "John");
        assert(base.store('People')[id2].friends[0].$fq == 9);
        assert(base.store('People')[id2].friends[1].name == "Mary");
        assert(base.store('People')[id2].friends[1].$fq == 3);

        // check that filterByField handles index-joins

        var rs_all = base.store('People')
            .allRecords
            .filterByField("friends", id2, id2); // return all that have Mary as friend => John, Mary

        //console.log(rs_all.length);
        assert(rs_all.length == 2);
        assert(rs_all[0].$id == id1);
        assert(rs_all[0].name == "John");
        assert(rs_all[1].$id == id2);
        assert(rs_all[1].name == "Mary");

        base.close();
    })
it("should make test number 8", function () {

 var qm = require('qminer');
 var base = new qm.Base({
 	mode: 'createClean',
 	schema: [{
 		name: 'Docs',
 		fields: [
 			{ name: 'Time', type: 'datetime' },
 			{ name: 'Text', type: 'string' }
 		]
 	}]
 });
 var store = base.store('Docs');

 var aggr = {
 	name: 'featureSpaceWindow',
 	type: 'timeSeriesWinBufFeatureSpace',
 	store: 'Docs',
 	timestamp: 'Time',
 	featureSpace: {
 		type: "categorical",
 		source: "Docs",
 		field: "Text"
 	},
 	winsize: 1000
 };
 var sa = store.addStreamAggr(aggr);

 var aggr2 = {
 	name: 'sparseVectorSum',
 	type: 'winBufSpVecSum',
 	store: 'Docs',
 	inAggr: 'featureSpaceWindow'
 };
 var sa2 = store.addStreamAggr(aggr2);

 store.push({ Time: '2015-06-10T14:13:32.0', Text: 'a' }); // 0
 store.push({ Time: '2015-06-10T14:13:33.0', Text: 'b' }); // 1
 store.push({ Time: '2015-06-10T14:14:34.0', Text: 'c' }); // 2
 store.push({ Time: '2015-06-10T14:15:35.0', Text: 'd' }); // 3
 store.push({ Time: '2015-06-10T14:15:36.0', Text: 'e' }); // 4
 store.push({ Time: '2015-06-10T14:15:37.0', Text: 'f' }); // 5

 var valVec2 = sa2.getValueVector(); // [0, 0, 0, 0, 1, 1] - only vectors 4 and 5 remain in window

 base.close();

});
Example #9
0
it("should make test number 2", function () {

 // import qm module
 var qm = require('qminer');
 // create a simple base containing one store
 var base = new qm.Base({
    mode: "createClean",
    schema: [{
        name: "People",
        fields: [
            { name: "Name", type: "string" },
            { name: "Gendre", type: "string" },
        ]
    },
    {
        name: "Laser",
        fields: [
            { name: "Time", type: "datetime" },
            { name: "WaveLength", type: "float" }
        ]
    }]
 });

 // create a new stream aggregator for 'People' store, get the length of the record name (with the function object)
 var aggr = new qm.StreamAggr(base, new function () {
    var length = 0;
    this.name = 'nameLength',
    this.onAdd = function (rec) {
        length = rec.Name.length;
    };
    this.saveJson = function (limit) {
        return { val: length };
    }
 }, "People");

 // create a new time series window buffer stream aggregator for 'Laser' store (with the JSON object)
 var wavelength = {
     name: "WaveLengthLaser",
     type: "timeSeriesWinBuf",
     store: "Laser",
     timestamp: "Time",
     value: "WaveLength",
     winsize: 10000
 }
 var sa = base.store("Laser").addStreamAggr(wavelength);
 base.close();

});
Example #10
0
it("should make test number 15", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Cars",
        fields: [
            { name: "NumberOfCars", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    },
    {
        name: "Temperature",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    },
    {
        name: "Merged",
        fields: [
            { name: "NumberOfCars", type: "float" },
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });
 // create a new merger stream aggregator that mergers the records of the 'Cars' and 'Temperature' stores.
 // The records are interpolated linearly and stored in the 'Merged' store.
 var mer = {
    name: 'MergerAggr',
    type: 'stmerger',
    outStore: 'Merged',
    createStore: false,
    timestamp: 'Time',
    fields: [
        { source: 'Cars', inField: 'NumberOfCars', outField: 'NumberOfCars', interpolation: 'linear', timestamp: 'Time' },
        { source: 'Temperature', inField: 'Celcius', outField: 'Celcius', interpolation: 'linear', timestamp: 'Time' }
    ]
 };
 var merger = new qm.StreamAggr(base, mer);
 base.close();

});
Example #11
0
it("should make test number 17", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The size of the window is 4 weeks.
 var timeser = {
    name: 'TimeSeriesBuffer',
    type: 'timeSeriesWinBuf',
    store: 'Heat',
    timestamp: 'Time',
    value: 'Celcius',
    winsize: 2419200000 // 4 weeks
 };
 var timeSeries = base.store("Heat").addStreamAggr(timeser);

 // add a slotted-histogram aggregator, that is connected with the 'TimeSeriesAggr' aggregator
 // it will present accumulated histogram for the last 2 hours (window) of the week (period) for the last 4 weeks (see aggregate above)
 var aggrJson = {
    name: 'Histogram',
    type: 'onlineSlottedHistogram',
    store: 'Heat',
    inAggr: 'TimeSeriesBuffer',
    period: 604800000, // 1 week
    window: 7200000, // 2h
    bins: 5, // 5 possible clusters
    granularity: 300000  // 5 min
 };
 var hist = base.store("Heat").addStreamAggr(aggrJson);
 base.close();

});
Example #12
0
it("should make test number 16", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The size of the window is 1 day.
 var timeser = {
    name: 'TimeSeriesBuffer',
    type: 'timeSeriesWinBuf',
    store: 'Heat',
    timestamp: 'Time',
    value: 'Celcius',
    winsize: 86400000 // one day in miliseconds
 };
 var timeSeries = base.store("Heat").addStreamAggr(timeser);

 // add a histogram aggregator, that is connected with the 'TimeSeriesAggr' aggregator
 var aggrJson = {
    name: 'Histogram',
    type: 'onlineHistogram',
    store: 'Heat',
    inAggr: 'TimeSeriesBuffer',
    lowerBound: 0,
    upperBound: 10,
    bins: 5,
    addNegInf: false,
    addPosInf: false
 };
 var hist = base.store("Heat").addStreamAggr(aggrJson);
 base.close();

});
Example #13
0
it("should make test number 19", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'Grades',
	        fields: [
	            { name: 'Grade', type: 'int' },
	            { name: 'Procents', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a new time series stream aggregator which takes the values from the 'Procents' field 
	 // and the timestamp from the 'Time' field. The size of the window is 1 year.
	 var ts = {
	    name: 'GradesAggr',
	    type: 'timeSeriesWinBuf',
	    store: 'Grades',
	    timestamp: 'Time',
	    value: 'Procents',
	    winsize: 31536000000 
	 };
	 var timeSeries = base.store('Grades').addStreamAggr(ts);
	 // create a new moving average stream aggregator that takes the values from the 
	 // 'GradesAggr' stream aggregator
	 var ma = {
	    name: 'AverageGrade',
	    type: 'ma',
	    store: 'Grades',
	    inAggr: 'GradesAggr'
	 }
	 var averageGrade = base.store('Grades').addStreamAggr(ma);
	 // add some grades in the 'Grades' store
	 base.store("Grades").push({ Grade: 7, Procents: 65, Time: '2014-11-23T10:00:00.0' });
	 base.store("Grades").push({ Grade: 9, Procents: 88, Time: '2014-12-20T12:00:00.0' });
	 base.store("Grades").push({ Grade: 8, Procents: 70, Time: '2015-02-03T10:00:00.0' });
	 // get the average grade procents by using the getFloat method
	 var average = averageGrade.getFloat(); // returns 74 + 1/3
	 base.close();
	
});
Example #14
0
it("should make test number 10", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series tick stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The size of the window should be 1 hour.
 var timeser = {
    name: 'TimeSeriesAggr',
    type: 'timeSeriesTick',
    store: 'Heat',
    timestamp: 'Time',
    value: 'Celcius',
    winsize: 3600000
 };
 var timeSeries = base.store("Heat").addStreamAggr(timeser);

 // add an exponentional moving average aggregator, that is connected with the 'TimeSeriesAggr' aggregator.
 // It should interpolate with the previous value, the decay should be 3 seconds and the initWindow should be 2 seconds.
 var ema = {
    name: 'emaAggr',
    type: 'ema',
    store: 'Heat',
    inAggr: 'TimeSeriesAggr',
    emaType: 'previous',
    interval: 3000,
    initWindow: 2000
 };
 var expoMovingAverage = base.store("Heat").addStreamAggr(ema);
 base.close();

});
Example #15
0
it("should make test number 20", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'GameCollection',
	        fields: [
	            { name: 'GameName', type: 'string' },
	            { name: 'Price', type: 'float' },
	            { name: 'ReleaseDate', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a new time series stream aggregator which takes the values from the 'Price' field
	 // and the timestamps from the 'ReleaseDate' field. The window size should be 1 month.
	 var ts = {
	    name: 'GameSeries',
	    type: 'timeSeriesWinBuf',
	    store: 'GameCollection',
	    timestamp: 'ReleaseDate',
	    value: 'Price',
	    winsize: 2678400000
	 };
	 var timeSeries = base.store('GameCollection').addStreamAggr(ts);
	 // create a new sum stream aggregator
	 var sum = {
	    name: 'SumPrice',
	    type: 'winBufSum',
	    store: 'GameCollection',
	    inAggr: 'GameSeries'
	 };
	 var priceSum = base.store('GameCollection').addStreamAggr(sum);
	 // put some records in the store
	 base.store('GameCollection').push({ GameName: 'Tetris', Price: 0, ReleaseDate: '1984-06-06T00:00:00.0' });
	 base.store('GameCollection').push({ GameName: 'Super Mario Bros.', Price: 100, ReleaseDate: '1985-09-13T00:00:00.0' });
	 base.store('GameCollection').push({ GameName: 'The Legend of Zelda', Price: 90, ReleaseDate: '1986-02-21T00:00:00.0 '});
	 // get the timestamp of the last bought game by using getTimestamp
	 var date = priceSum.getTimestamp(); // returns 12153801600000 (the miliseconds since 1601-01-01T00:00:00.0)
	 base.close();
	
});
Example #16
0
it("should make test number 14", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    },
    {
        name: "interpolatedValues",
        fields: [
            { name: "Value", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });
 // create a new resampler stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The interpolated values are stored in the 'interpolatedValues' store.
 // The interpolation should be linear and the interval should be 2 seconds.
 var res = {
    name: 'resamplerAggr',
    type: 'resampler',
    store: 'Heat',
    outStore: 'interpolatedValues',
    timestamp: 'Time',
    fields: [{
        name: 'Celcius',
        interpolator: 'linear'
    }],
    createStore: false,
    interval: 2000
 };
 var resampler = base.store("Heat").addStreamAggr(res);
 base.close();

});
    it('should allow query with eact value over linear index', function () {
        var base = new qm.Base({ mode: 'createClean' });
        base.createStore({
            "name": store_name,
            "fields": [
                { "name": "title", "type": "string", "store" : "cache" },
                { "name": "ts", "type": "datetime", "store": "cache" },
                { "name": "is_child", "type": "byte", "store" : "cache", "default": 0 }
            ],
            "joins": [
                { "name": "children", "type": "index", "store": store_name, "storage_location" : "cache" },
                { "name": "parent", "type": "field", "store": store_name, "inverse": "children", "storage_location" : "cache" }
            ],
            "keys": [
                { "field": "title", "type": "text" },
                { "field": "ts", "type": "linear" },
                { "field": "is_child", "type": "linear" }
            ]
        });
        var store = base.store(store_name);
            
        var id1 = store.push({ title : "test title 1", ts : (new Date()).getTime(), is_child: 0 });
        var id2 = store.push({ title : "test title 2", ts : (new Date()).getTime(), is_child: 1 });

        var query = {
            $from : store_name,
            $limit : 50,
            $sort : { ts : 0 },
            is_child : 0
        };

        var rs = base.search(query);
        assert.equal(rs.length, 1);			
        assert.equal(rs[0].$id, id1);
        
        query.is_child = 1;
        rs = base.search(query);
        assert.equal(rs.length, 1);			
        assert.equal(rs[0].$id, id2);

        base.close();
    })
Example #18
0
    describe('Testing timeWindow (size: 2h)', function () { 
                // generate store with window 3
        base = new qm.Base({ mode: 'createClean' });
        base.createStore({
            "name": "TestStore",
            "fields": [
                { "name": "DateTime", "type": "datetime" },
                { "name": "Measurement", "type": "float" }
            ],
            timeWindow: {
                duration: 2,
                unit: "hour",
                field: "DateTime"
            }
        });

        // push 5 records into created store
        for (var i = 0; i < 5; i++) {
            var rec = {
                "DateTime": new Date(new Date().getTime() + i * 60 * 60 * 1001).toISOString(),
                "Measurement": i
            };
            base.store("TestStore").push(rec);
        }

        // clean base with garbage collector
        var before = base.store("TestStore").allRecords.length;
        base.garbageCollect();
        var after =  base.store("TestStore").allRecords.length;

        // test number of records in store before garbage cleanup
        it('store should contain 5 records before .garbageCollect()', function () {
            assert.equal(5, before);
        });

        // test number of records in store after garbage cleanup
        it('store should contain 2 records after .garbageCollect()', function () {
            assert.equal(2, after);
        });

        base.close();
    });
Example #19
0
	it('should survive', function () {
	

var base1 = new qm.Base({
    mode: 'createClean',
    schema: [
      {
          name: 'People',
          fields: [{ name: 'name', type: 'string', null: true }],
      }
    ],
    dbPath: './db1'
});

var store1 = base1.store("People");
store1.add({ name: "Jan" });
store1.add({ name: null });
assert(store1.length == 2);
base1.close();
})});
Example #20
0
it("should make test number 5", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Income",
        fields: [
            { name: "Amount", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Income' store, that takes the values from the 'Amount' field
 // and the timestamp from the 'Time' field. The size of the window should 1 week.
 var timeser = {
    name: 'TimeSeriesAggr',
    type: 'timeSeriesWinBuf',
    store: 'Income',
    timestamp: 'Time',
    value: 'Amount',
    winsize: 604800000 // 7 days in miliseconds
 };
 var timeSeries = base.store("Income").addStreamAggr(timeser);

 // add a sum aggregator, that is connected with the 'TimeSeriesAggr' aggregator
 var sum = {
    name: 'SumAggr',
    type: 'winBufSum',
    store: 'Heat',
    inAggr: 'TimeSeriesAggr'
 };
 var sumAggr = base.store("Income").addStreamAggr(sum);
 base.close();

});
Example #21
0
it("should make test number 9", function () {

 // import the qm module
 var qm = require('qminer');
 // create a base with a simple store
 var base = new qm.Base({
    mode: "createClean",
    schema: [
    {
        name: "Heat",
        fields: [
            { name: "Celcius", type: "float" },
            { name: "Time", type: "datetime" }
        ]
    }]
 });

 // create a new time series stream aggregator for the 'Heat' store, that takes the values from the 'Celcius' field
 // and the timestamp from the 'Time' field. The size of the window should be 1 day.
 var timeser = {
    name: 'TimeSeriesAggr',
    type: 'timeSeriesWinBuf',
    store: 'Heat',
    timestamp: 'Time',
    value: 'Celcius',
    winsize: 86400000
 };
 var timeSeries = base.store("Heat").addStreamAggr(timeser);

 // add a moving average aggregator, that is connected with the 'TimeSeriesAggr' aggregator
 var ma = {
    name: 'movingAverageAggr',
    type: 'ma',
    store: 'Heat',
    inAggr: 'TimeSeriesAggr'
 };
 var movingAverage = base.store("Heat").addStreamAggr(ma);
 base.close();

});
Example #22
0
it("should make test number 24", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'Medicine',
	        fields: [
	            { name: 'NumberOfPills', type: 'float' },
	            { name: 'Time', type: 'datetime' }
            ]
	    }]
	 });
	 // create a time series stream aggregator that takes the values from the 'NumberOfPills' field
	 // and the timestamp from the 'Time' field. The window size should be 1 week.
	 var ts = {
	    name: 'WeekPills',
	    type: 'timeSeriesWinBuf',
	    store: 'Medicine',
	    timestamp: 'Time',
	    value: 'NumberOfPills',
	    winsize: 604800000
	 };
	 var weekly = base.store('Medicine').addStreamAggr(ts);
	 // add some records in the store
	 base.store('Medicine').push({ NumberOfPills: 4, Time: '2015-07-21T09:00:00.0' });
	 base.store('Medicine').push({ NumberOfPills: 5, Time: '2015-07-21T19:00:00.0' });
	 base.store('Medicine').push({ NumberOfPills: 4, Time: '2015-07-22T09:00:00.0' });
	 base.store('Medicine').push({ NumberOfPills: 5, Time: '2015-07-22T19:00:00.0' });
	 base.store('Medicine').push({ NumberOfPills: 4, Time: '2015-07-23T09:00:00.0' });
	 base.store('Medicine').push({ NumberOfPills: 6, Time: '2015-07-23T19:00:00.0' });
	 base.store('Medicine').push({ NumberOfPills: 4, Time: '2015-07-24T09:00:00.0' });
	 // get the length of the timestamp vector
	 var length = weekly.getTimestampLength(); // returns 7
	 base.close();
	
});
Example #23
0
it("should make test number 32", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'Noise',
	        fields: [
	            { name: 'Decibels', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series stream aggregator that takes the values from the 'Decibels' field
	 // and timestamps from the 'Time' fields. The window size should be 1 second.
	 var ts = {
	    name: 'Music',
	    type: 'timeSeriesWinBuf',
	    store: 'Noise',
	    timestamp: 'Time',
	    value: 'Decibels',
	    winsize: 1000
	 };
	 var music = base.store('Noise').addStreamAggr(ts);
	 // add some records in the store
	 base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:00.0' });
	 base.store('Noise').push({ Decibels: 55, Time: '2015-07-21T14:43:00.200' });
	 base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:00.400' });
	 base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:00.600' });
	 base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:00.800' });
	 base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:01.0' });
	 base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:01.2' });
	 // get the timestamps that just left the window buffer by adding the last record
	 var last = music.getOutTimestampVector(); // returns [13081963380000]
	 base.close();
	
});
Example #24
0
it("should make test number 31", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'F1',
	        fields: [
	            { name: 'Driver', type: 'string' },
	            { name: 'Speed', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series stream aggregator that gets the values from the 'Speed' field
	 // and the timestamp from the 'Time' field. The window size should be 5 minutes.
	 var ts = {
	    name: 'Sensor',
	    type: 'timeSeriesWinBuf',
	    store: 'F1',
	    timestamp: 'Time',
	    value: 'Speed',
	    winsize: 300000
	 };
	 var sensor = base.store('F1').addStreamAggr(ts);
	 // add some records to the store
	 base.store('F1').push({ Driver: 'Sebastian Vettel', Speed: 203.4, Time: '2015-07-19T09:32:01.0' });
	 base.store('F1').push({ Driver: 'Thomas "Tommy" Angelo', Speed: 152.8, Time: '2015-07-19T09:35:23.0' });
	 base.store('F1').push({ Driver: 'Mark Ham', Speed: 189.5, Time: '2015-07-19T09:38:43.0' });
	 base.store('F1').push({ Driver: 'Speedy Gonzales', Speed: 171.4, Time: '2015-07-19T09:40:32.0' });
	 // get the values, that have got out of the window buffer.
	 // because the window size is 5 seconds, the last value that have left the buffer is 152.8
	 var left = sensor.getOutFloatVector(); // returns [152.8]
	 base.close();
	
});
Example #25
0
		it('Should throw an exception', function (done) {
			try {
				base.close();
				var base1 = new qm.Base({
					mode: 'open',
					dbPath: DB_PATH
				});
				
				
				var store = base1.createStore({
			        "name": "People1",
			        "fields": [
			            { "name": ILLEGAL_NAME, "type": "string", "primary": true },
			            { "name": "Gender", "type": "string", "shortstring": true }
			        ]
			    });
				base1.close();
				done(new Error('Was able to create a store with an illegal name!'));
			} catch (e) {
				base1.close();
				done();
			}
		});
Example #26
0
it("should make test number 25", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'Route66',
	        fields: [
	            { name: 'NumberOfCars', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series stream aggregator that takes the values from the 'NumberOfCars' field
	 // and the timestamps from the 'Time' field. The window size should be 1 day.
	 var ts = {
	    name: 'Traffic',
	    type: 'timeSeriesWinBuf',
	    store: 'Route66',
	    timestamp: 'Time',
	    value: 'NumberOfCars',
	    winsize: 86400000
	 };
	 var traffic = base.store('Route66').addStreamAggr(ts);
	 // add some records in the store
	 base.store('Route66').push({ NumberOfCars: 100, Time: '2015-06-15T06:00:00.0' });
	 base.store('Route66').push({ NumberOfCars: 88, Time: '2015-06-15T:10:00.0' });
	 base.store('Route66').push({ NumberOfCars: 60, Time: '2015-06-15T13:00:00.0' });
	 base.store('Route66').push({ NumberOfCars: 90, Time: '2015-06-15T18:00:00.0' });
	 base.store('Route66').push({ NumberOfCars: 110, Time: '2015-06-16T00:00:00.0' });
	 // get the third timestamp in the buffer
	 var time = traffic.getTimestampAt(2); // returns 13078864800000
	 base.close();
	
});
Example #27
0
it("should make test number 23", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'Hospital',
	        fields: [
	            { name: 'NumberOfPatients', type: 'float' },
	            { name: 'Date', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a new time series stream aggregator that takes the values from the 'NumberOfPatients' field
	 // and the timestamp from the 'Date' field. The window size should be 1 week.
	 var ts = {
	    name: 'WeekPatients',
	    type: 'timeSeriesWinBuf',
	    store: 'Hospital',
	    timestamp: 'Date',
	    value: 'NumberOfPatients',
	    winsize: 604800000
	 };
	 var weekPatients = base.store('Hospital').addStreamAggr(ts);
	 // add some records in the store
	 base.store('Hospital').push({ NumberOfPatients: 50, Date: '2015-05-20T00:00:00.0' });
	 base.store('Hospital').push({ NumberOfPatients: 56, Date: '2015-05-21T00:00:00.0' });
	 base.store('Hospital').push({ NumberOfPatients: 120, Date: '2015-05-22T00:00:00.0' });
	 base.store('Hospital').push({ NumberOfPatients: 40, Date: '2015-05-23T00:00:00.0' });
	 // get the values that are in the time series window buffer as a vector
	 var values = weekPatients.getFloatVector(); // returns the vector [50, 56, 120, 40]
	 base.close();
	
});
Example #28
0
it("should make test number 22", function () {
 
	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'MusicSale',
	        fields: [
	            { name: 'NumberOfAlbums', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series containing the 'NumberOfAlbums' values and getting the timestamp from the 'Time' field.
	 // The window size should be 1 week.
	 var ts = {
	    name: 'Sales',
	    type: 'timeSeriesWinBuf',
	    store: 'MusicSale',
	    timestamp: 'Time',
	    value: 'NumberOfAlbums',
	    winsize: 604800000
	 };
	 var weekSales = base.store('MusicSale').addStreamAggr(ts);
	 // add some records in the store
	 base.store('MusicSale').push({ NumberOfAlbums: 10, Time: '2015-03-15T00:00:00.0' });
	 base.store('MusicSale').push({ NumberOfAlbums: 15, Time: '2015-03-18T00:00:00.0' });
	 base.store('MusicSale').push({ NumberOfAlbums: 30, Time: '2015-03-19T00:00:00.0' });
	 base.store('MusicSale').push({ NumberOfAlbums: 45, Time: '2015-03-20T00:00:00.0' });
	 // get the second value of the value vector 
	 var albums = weekSales.getFloatAt(1); // returns 15
	 base.close();
	
});
Example #29
0
it("should make test number 21", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'IceCreams',
	        fields: [
	            { name: 'Type', type: 'string' },
	            { name: 'Price', type: 'float' },
	            { name: 'TimeOfConsumption', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series stream aggregator, that takes values from the 'Price' field and the timestamp
	 //  from the 'TimeOfConsumation' field of 'IceCream' store. The window size should be 1 day.
	 var ts = {
	    name: 'IcePrice',
	    type: 'timeSeriesWinBuf',
	    store: 'IceCreams',
	    timestamp: 'TimeOfConsumption',
	    value: 'Price',
	    winsize: 86400000
	 };
	 var icePrice = base.store('IceCreams').addStreamAggr(ts);
	 // add some ice creams in the store
	 base.store('IceCreams').push({ Type: 'Chocholate', Price: 5, TimeOfConsumption: '2015-07-21T09:00:00.0' });
	 base.store('IceCreams').push({ Type: 'Blue Sky', Price: 3, TimeOfConsumption: '2015-07-21T14:13:00.0' });
	 base.store('IceCreams').push({ Type: 'Stracciatella', Price: 5, TimeOfConsumption: '2015-07-21T21:05:00.0' });
	 // get the number of ice creams consumed by using getFloatLength method
	 var numberOfIceCreamsEaten = icePrice.getFloatLength(); // returns 3
	 base.close();
	
});
Example #30
0
it("should make test number 28", function () {

	 // import qm module
	 var qm = require('qminer');
	 // create a simple base containing one store
	 var base = new qm.Base({
	    mode: 'createClean',
	    schema: [{
	        name: 'F1',
	        fields: [
	            { name: 'Driver', type: 'string' },
	            { name: 'Speed', type: 'float' },
	            { name: 'Time', type: 'datetime' }
	        ]
	    }]
	 });
	 // create a time series stream aggregator that gets the values from the 'Speed' field
	 // and the timestamp from the 'Time' field. The window size should be 5 minutes.
	 var ts = {
	    name: 'Sensor',
	    type: 'timeSeriesWinBuf',
	    store: 'F1',
	    timestamp: 'Time',
	    value: 'Speed',
	    winsize: 300000
	 };
	 var sensor = base.store('F1').addStreamAggr(ts);
	 // add some records to the store
	 base.store('F1').push({ Driver: 'Sebastian Vettel', Speed: 203.4, Time: '2015-07-19T09:32:01.0' });
	 base.store('F1').push({ Driver: 'Thomas "Tommy" Angelo', Speed: 152.8, Time: '2015-07-19T09:35:23.0' });
	 base.store('F1').push({ Driver: 'Mark Ham', Speed: 189.5, Time: '2015-07-19T09:38:43.0' });
	 // get the last timestamp that was added in the window buffer
	 var time = sensor.getInTimestamp(); // returns 13081772323000
	 base.close();
	
});