Skip to content

Commit

Permalink
fix: performance issue with toJSON() (#130)
Browse files Browse the repository at this point in the history
* fix: performance issue with toJSON()

This change also fixes:
 - test setup that wasn't working anymore
 - syntax errors in a couple of the tests
 - removes the old website build for now because it's reported as a vulnerability (we should try to figure this out in the typescript master branch)

* Bump node version used by travis
  • Loading branch information
pjm17971 authored Jan 14, 2019
1 parent 02281b1 commit 77ec65c
Show file tree
Hide file tree
Showing 8 changed files with 2,653 additions and 5,948 deletions.
9 changes: 7 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"presets": ["es2015", "stage-0"]
}
"presets": ["es2015", "stage-0"],
"env": {
"test": {
"presets": [["env", { "modules": "commonjs" }]]
}
}
}
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
sudo: false
language: node_js
node_js:
- "5.6.0"
- "10.15.0"
notifications:
email: false
email: false
before_install:
- export TZ=America/Los_Angeles
script:
npm test -- --coverage
script: npm test -- --coverage
after_script:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

# Pond.js

---

[![Build status](https://api.travis-ci.org/esnet/pond.png)](https://travis-ci.org/esnet/pond) [![npm version](https://badge.fury.io/js/pondjs.svg)](https://badge.fury.io/js/pondjs)

----
---

Pond.js is a library built on top of [immutable.js](https://facebook.github.io/immutable-js/) to provide time-based data structures, serialization and processing within our tools.

Expand All @@ -23,7 +22,7 @@ The result might be as simple as comparing two time ranges:

```js
const timerange = timerange1.intersection(timerange2);
timerange.asRelativeString(); // "a few seconds ago to a month ago"
timerange.asRelativeString(); // "a few seconds ago to a month ago"
```

Or simply getting the average value in a timeseries:
Expand All @@ -36,7 +35,7 @@ Or quickly performing aggregations on a timeseries:

```js
const timeseries = new TimeSeries(weatherData);
const dailyAvg = timeseries.fixedWindowRollup("1d", {value: avg});
const dailyAvg = timeseries.fixedWindowRollup("1d", { value: avg });
```

Or much higher level batch or stream processing using the Pipeline API:
Expand All @@ -45,43 +44,47 @@ Or much higher level batch or stream processing using the Pipeline API:
const p = Pipeline()
.from(timeseries)
.take(10)
.groupBy(e => e.value() > 65 ? "high" : "low")
.groupBy(e => (e.value() > 65 ? "high" : "low"))
.emitOn("flush")
.to(CollectionOut, (collection, windowKey, groupByKey) => {
result[groupByKey] = collection;
}, true);
.to(
CollectionOut,
(collection, windowKey, groupByKey) => {
result[groupByKey] = collection;
},
true
);
```

## What does it do?

Pond has three main goals:

1. **Data Structures** - Provide a robust set of time-related data structures, built on Immutable.js
2. **Serialization** - Provide serialization of these structures for transmission across the wire
3. **Processing** - Provide processing operations to work with those structures
1. **Data Structures** - Provide a robust set of time-related data structures, built on Immutable.js
2. **Serialization** - Provide serialization of these structures for transmission across the wire
3. **Processing** - Provide processing operations to work with those structures

Here is a summary of what is provided:

* **TimeRange** - a begin and end time, packaged together
* **Index** - A time range denoted by a string, for example "5m-1234" is a specific 5 minute time range, or "2014-09" is September 2014
* **TimeEvent** - A timestamp and a data object packaged together
* **IndexedEvents** - An Index and a data object packaged together. e.g. 1hr max value
* **TimeRangeEvents** - A TimeRange and a data object packaged together. e.g. outage event occurred from 9:10am until 10:15am
- **TimeRange** - a begin and end time, packaged together
- **Index** - A time range denoted by a string, for example "5m-1234" is a specific 5 minute time range, or "2014-09" is September 2014
- **TimeEvent** - A timestamp and a data object packaged together
- **IndexedEvents** - An Index and a data object packaged together. e.g. 1hr max value
- **TimeRangeEvents** - A TimeRange and a data object packaged together. e.g. outage event occurred from 9:10am until 10:15am

And forming together collections of events:

* **Collection** - A bag of events, with a helpful set of methods for operating on those events
* **TimeSeries** - An ordered Collection of Events and associated meta data, along with operations to roll-up, aggregate, break apart and recombine TimeSeries.
- **Collection** - A bag of events, with a helpful set of methods for operating on those events
- **TimeSeries** - An ordered Collection of Events and associated meta data, along with operations to roll-up, aggregate, break apart and recombine TimeSeries.

And then high level processing via pipelines:

* **Pipeline** - Stream or batch style processing of events to build more complex processing operations, either on fixed TimeSeries or incoming realtime data. Supports windowing, grouping and aggregation.
- **Pipeline** - Stream or batch style processing of events to build more complex processing operations, either on fixed TimeSeries or incoming realtime data. Supports windowing, grouping and aggregation.

# Typescript support

As of version 0.8.6 Pond ships with Typescript declarations.

In addition, the project is also being rewritten in Typescript, which will probably eventually lead to a v1.0 version as the API will have significant differences. You can track the progress of that work in [Issue #65](https://github.com/esnet/pond/issues/65).
In addition, the project has been rewritten in Typescript, currently v1.0 alpha. This version is not compatible with react-timeseries-charts at this time.

# Contributing

Expand All @@ -91,15 +94,14 @@ The library has a large and growing Jest test suite. To run the tests interactiv

npm test


# License

This code is distributed under a BSD style license, see the LICENSE file for complete information.

# Copyright

ESnet Timeseries Library ("Pond.js"), Copyright (c) 2015-2017, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
If you have questions about your rights to use or distribute this software, please contact Berkeley Lab's Innovation & Partnerships Office at IPO@lbl.gov.
NOTICE. This software is owned by the U.S. Department of Energy. As such, the U.S. Government has been granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software to reproduce, prepare derivative works, and perform publicly and display publicly. Beginning five (5) years after the date permission to assert copyright is obtained from the U.S. Department of Energy, and subject to any subsequent five (5) year renewals, the U.S. Government is granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.
ESnet Timeseries Library ("Pond.js"), Copyright (c) 2015-2018, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.

If you have questions about your rights to use or distribute this software, please contact Berkeley Lab's Innovation & Partnerships Office at IPO@lbl.gov.

NOTICE. This software is owned by the U.S. Department of Energy. As such, the U.S. Government has been granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software to reproduce, prepare derivative works, and perform publicly and display publicly. Beginning five (5) years after the date permission to assert copyright is obtained from the U.S. Department of Energy, and subject to any subsequent five (5) year renewals, the U.S. Government is granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.
48 changes: 25 additions & 23 deletions lib/lib/timeseries.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@ var TimeSeries = function () {
return;
}

var columnList = this.columns();

var columns = void 0;
if (e instanceof _timeevent2.default) {
columns = ["time"].concat((0, _toConsumableArray3.default)(this.columns()));
columns = ["time"].concat((0, _toConsumableArray3.default)(columnList));
} else if (e instanceof _timerangeevent2.default) {
columns = ["timerange"].concat((0, _toConsumableArray3.default)(this.columns()));
columns = ["timerange"].concat((0, _toConsumableArray3.default)(columnList));
} else if (e instanceof _indexedevent2.default) {
columns = ["index"].concat((0, _toConsumableArray3.default)(this.columns()));
columns = ["index"].concat((0, _toConsumableArray3.default)(columnList));
}

var points = [];
Expand All @@ -339,7 +341,7 @@ var TimeSeries = function () {
for (var _iterator = (0, _getIterator3.default)(this._collection.events()), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _e = _step.value;

points.push(_e.toPoint(this.columns()));
points.push(_e.toPoint(columnList));
}
} catch (err) {
_didIteratorError = true;
Expand Down Expand Up @@ -1390,7 +1392,7 @@ var TimeSeries = function () {
* ```
* will aggregate both "in" and "out" using the average aggregation
* function and return the result as in_avg and out_avg.
*
*
* Note that each aggregation function, such as `avg()` also can take a
* filter function to apply before the aggregation. A set of filter functions
* exists to do common data cleanup such as removing bad values. For example:
Expand Down Expand Up @@ -1623,12 +1625,12 @@ var TimeSeries = function () {
* STATIC
*/
/**
* Defines the event type contained in this TimeSeries. The default here
* is to use the supplied type (time, timerange or index) to build either
* a TimeEvent, TimeRangeEvent or IndexedEvent. However, you can also
* subclass the TimeSeries and reimplement this to return another event
* type.
*/
* Defines the event type contained in this TimeSeries. The default here
* is to use the supplied type (time, timerange or index) to build either
* a TimeEvent, TimeRangeEvent or IndexedEvent. However, you can also
* subclass the TimeSeries and reimplement this to return another event
* type.
*/

}], [{
key: "event",
Expand All @@ -1646,12 +1648,12 @@ var TimeSeries = function () {
}

/**
* Static function to compare two TimeSeries to each other. If the TimeSeries
* are of the same instance as each other then equals will return true.
* @param {TimeSeries} series1
* @param {TimeSeries} series2
* @return {bool} result
*/
* Static function to compare two TimeSeries to each other. If the TimeSeries
* are of the same instance as each other then equals will return true.
* @param {TimeSeries} series1
* @param {TimeSeries} series2
* @return {bool} result
*/

}, {
key: "equal",
Expand All @@ -1660,12 +1662,12 @@ var TimeSeries = function () {
}

/**
* Static function to compare two TimeSeries to each other. If the TimeSeries
* are of the same value as each other then equals will return true.
* @param {TimeSeries} series1
* @param {TimeSeries} series2
* @return {bool} result
*/
* Static function to compare two TimeSeries to each other. If the TimeSeries
* are of the same value as each other then equals will return true.
* @param {TimeSeries} series1
* @param {TimeSeries} series2
* @return {bool} result
*/

}, {
key: "is",
Expand Down
91 changes: 34 additions & 57 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,36 @@
{
"name": "pondjs",
"version": "0.8.9",
"main": "lib/entry",
"types": "src/index.d.ts",
"description": "A timeseries library build on top of immutable.js",
"homepage": "http://software.es.net/pond",
"scripts": {
"lint": "eslint src website/modules/*.jsx",
"test": "react-scripts test",
"docs": "rm -f /src/website/docs/* && node ./scripts/renderdocs.js",
"build": ". ./scripts/build.sh",
"start-website": "react-scripts start",
"build-website": "echo \"*** Building website\n\" && rm -rf docs && react-scripts build && mv build docs"
},
"pre-commit": [
"build"
],
"license": "BSD-3-Clause-LBNL",
"dependencies": {
"babel-polyfill": "^6.9.1",
"babel-runtime": "^6.5.0",
"immutable": "^3.6.4",
"immutable-devtools": "0.0.4",
"moment": "^2.9.0",
"underscore": "^1.8.2"
},
"devDependencies": {
"anybar-webpack": "^1.2.0",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^6.0.0",
"babel-plugin-transform-runtime": "^6.7.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"collect-json": "^1.0.8",
"coveralls": "^2.11.12",
"dmd": "^1.4.2",
"eslint": "^1.10.0",
"eslint-config-esnet": "^0.1.0",
"eslint-plugin-babel": "^2.1.1",
"eslint-plugin-react": "^3.9.0",
"history": "^2.0.2",
"jsdoc": "^3.4.0",
"jsdoc-to-markdown": "^1.3.4",
"pre-commit": "^1.1.2",
"raw-loader": "^0.5.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-markdown": "^1.0.5",
"react-router": "^2.2.4",
"react-scripts": "0.4.1",
"scroll-behavior": "^0.3.0"
},
"keywords": [
"timeseries",
"immutable"
]
"name": "pondjs",
"version": "0.8.9",
"main": "lib/entry",
"types": "src/index.d.ts",
"description": "A timeseries library build on top of immutable.js",
"homepage": "http://software.es.net/pond",
"scripts": {
"test": "jest --testEnvironment node ",
"build": ". ./scripts/build.sh"
},
"license": "BSD-3-Clause-LBNL",
"dependencies": {
"babel-polyfill": "^6.9.1",
"babel-runtime": "^6.5.0",
"immutable": "^3.6.4",
"immutable-devtools": "0.0.4",
"moment": "^2.9.0",
"underscore": "^1.8.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.23.1",
"babel-jest": "^22.4.3",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.3.3",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"jest": "^22.0.0",
"pre-commit": "^1.2.2"
},
"keywords": [
"timeseries",
"immutable"
]
}
Loading

0 comments on commit 77ec65c

Please sign in to comment.