Permalink
Browse files

Expose an API for adding new functions

  • Loading branch information...
1 parent 3890b29 commit 5650eba0ed88d23259d5eb4f9c2fd2e1c5e19793 @rashidkpc rashidkpc committed Jul 15, 2016
Showing with 29 additions and 8 deletions.
  1. +7 −7 FUNCTIONS.md
  2. +21 −0 init.js
  3. +1 −1 package.json
View
@@ -11,7 +11,7 @@ Argument | Accepts | Description
--- | --- | ---
metric | *string* | Graphite metric to pull, eg _test-data.users.*.data
offset | *string* | Offset the series retrieval by a date expression. Eg -1M to make events from one month ago appear as if they are happening now
-fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale
+fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale,
#### .quandl()
Pull data from quandl.com using the quandl code. Stick your free API key in timelion.json. API is rate limited without a key
@@ -21,7 +21,7 @@ Argument | Accepts | Description
code | *string* | The quandl code to plot. You can find these on quandl.com.
position | *number* | Some quandl sources return multiple series, which one should I use? 1 based index.
offset | *string* | Offset the series retrieval by a date expression. Eg -1M to make events from one month ago appear as if they are happening now
-fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale
+fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale,
#### .static()
Draws a single value across the chart
@@ -31,7 +31,7 @@ Argument | Accepts | Description
value | *number/string* | The single value to to display, you can also pass several values and I will interpolate them evenly across your time range.
label | *string* | A quick way to set the label for the series. You could also use the .label() function
offset | *string* | Offset the series retrieval by a date expression. Eg -1M to make events from one month ago appear as if they are happening now
-fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale
+fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale,
#### .worldbank_indicators()
Pull data from http://data.worldbank.org/ using the country name and indicator. The worldbank provides mostly yearly data, and often has no data for the current year. Try offset=-1y if you get no data for recent time ranges.
@@ -41,7 +41,7 @@ Argument | Accepts | Description
country | *string* | Worldbank country identifier. Usually the country's 2 letter code
indicator | *string* | The indicator code to use. You'll have to look this up on data.worldbank.org. Often pretty obtuse. Eg SP.POP.TOTL is population
offset | *string* | Offset the series retrieval by a date expression. Eg -1M to make events from one month ago appear as if they are happening now
-fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale
+fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale,
#### .worldbank()
Pull data from http://data.worldbank.org/ using path to series. The worldbank provides mostly yearly data, and often has no data for the current year. Try offset=-1y if you get no data for recent time ranges.
@@ -50,7 +50,7 @@ Argument | Accepts | Description
--- | --- | ---
code | *string* | Worldbank API path. This is usually everything after the domain, before the querystring. Eg: /en/countries/ind;chn/indicators/DPANUSSPF.
offset | *string* | Offset the series retrieval by a date expression. Eg -1M to make events from one month ago appear as if they are happening now
-fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale
+fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale,
#### .es()
Pull data from an elasticsearch instance
@@ -65,7 +65,7 @@ timefield | *string* | Field of type "date" to use for x-axis
kibana | *boolean* | Respect filters on Kibana dashboards. Only has an effect when using on Kibana dashboards
interval | *string* | **DO NOT USE THIS**. Its fun for debugging fit functions, but you really should use the interval picker
offset | *string* | Offset the series retrieval by a date expression. Eg -1M to make events from one month ago appear as if they are happening now
-fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale
+fit | *string* | Algorithm to use for fitting series to the target time span and interval. Available: average, carry, nearest, none, scale,
### Chainable functions
Chainable functions can not start a chain. Somewhere before them must be a data source function. Chainable functions modify the data output directly from a data source, or from another chainable function that has a data source somewhere before it.
@@ -129,7 +129,7 @@ Fills null values using a defined fit function
Argument | Accepts | Description
--- | --- | ---
-mode | *string* | The algorithm to use for fitting the series to the target. One of: average, carry, nearest, none, scale
+mode | *string* | The algorithm to use for fitting the series to the target. One of: average, carry, nearest, none, scale,
#### .hide()
Hide the series by default
View
@@ -1,8 +1,29 @@
+var _ = require('lodash');
+var processFunctionDefinition = require('./server/lib/process_function_definition');
+
module.exports = function (server) {
//var config = server.config();
require('./server/routes/run.js')(server);
require('./server/routes/functions.js')(server);
require('./server/routes/validate_es.js')(server);
+ var functions = require('./server/lib/load_functions')('series_functions');
+
+ function addFunction(func) {
+ _.assign(functions, processFunctionDefinition(func));
+ }
+
+ function getFunction(name) {
+ if (!functions[name]) throw new Error ('No such function: ' + name);
+ return functions[name];
+ }
+
+ server.plugins.timelion = {
+ functions: functions,
+ addFunction: addFunction,
+ getFunction: getFunction
+ };
+
+
};
View
@@ -1,6 +1,6 @@
{
"name": "timelion",
- "version": "0.1.369",
+ "version": "0.1.370",
"kibanas": [
"5.0.0-alpha2",
"5.0.0-alpha3",

0 comments on commit 5650eba

Please sign in to comment.