Skip to content

Instantly share code, notes, and snippets.

@bergquist
Last active March 3, 2016 15:45
Show Gist options
  • Save bergquist/bc4aa5baface3cffa109 to your computer and use it in GitHub Desktop.
Save bergquist/bc4aa5baface3cffa109 to your computer and use it in GitHub Desktop.
generic backend example
var express = require('express');
var bodyParser = require('body-parser');
var _ = require('lodash');
var app = express();
app.use(bodyParser.json());
var timeserie = [
{"target": "upper_25", "datapoints": [[3.0, 1450754160], [2.0, 1450754220], [1.0, 1450754280], [0.0, 1450754340], [1.0, 1450754400], [1.0, 1450754460], [1.0, 1450754520], [1.0, 1450754580], [1.0, 1450754640], [1.0, 1450754700], [2.0, 1450754760], [1.0, 1450754820], [165.0, 1450754880], [5.0, 1450754940], [1.0, 1450755000], [1.0, 1450755060], [5.0, 1450755120], [2.0, 1450755180], [2.0, 1450755240], [1.0, 1450755300], [1.0, 1450755360], [7.0, 1450755420], [4.0, 1450755480], [1.0, 1450755540], [7.0, 1450755600], [7.0, 1450755660], [1.0, 1450755720], [2.0, 1450755780], [1.0, 1450755840], [1.0, 1450755900], [2.0, 1450755960], [1.0, 1450756020], [1.0, 1450756080], [2.0, 1450756140], [1.0, 1450756200], [7.0, 1450756260], [2.0, 1450756320], [2.0, 1450756380], [1.0, 1450756440], [8.0, 1450756500], [7.0, 1450756560], [1.0, 1450756620], [2.0, 1450756680], [2.0, 1450756740], [2.0, 1450756800], [2.0, 1450756860], [18.0, 1450756920], [1.0, 1450756980], [1.0, 1450757040], [1.0, 1450757100], [1.0, 1450757160], [6.0, 1450757220], [2.0, 1450757280], [1.0, 1450757340], [2.0, 1450757400], [2.0, 1450757460], [1.0, 1450757520], [1.0, 1450757580], [1.0, 1450757640], [1.0, 1450757700], [1.0, 1450757760], [1.0, 1450757820], [15.0, 1450757880], [5.0, 1450757940], [2.0, 1450758000], [1.0, 1450758060], [1.0, 1450758120], [1.0, 1450758180], [1.0, 1450758240], [1.0, 1450758300], [1.0, 1450758360], [1.0, 1450758420], [1.0, 1450758480], [1.0, 1450758540], [1.0, 1450758600], [2.0, 1450758660], [1.0, 1450758720], [2.0, 1450758780], [1.0, 1450758840], [1.0, 1450758900], [1.0, 1450758960], [1.0, 1450759020], [1.0, 1450759080], [1.0, 1450759140], [8.0, 1450759200], [1.0, 1450759260], [2.0, 1450759320], [1.0, 1450759380], [1.0, 1450759440], [1.0, 1450759500], [2.0, 1450759560], [2.0, 1450759620], [1.0, 1450759680], [1.0, 1450759740], [2.0, 1450759800], [1.0, 1450759860], [1.0, 1450759920], [1.0, 1450759980], [1.0, 1450760040], [2.0, 1450760100], [9.0, 1450760160], [1.0, 1450760220], [2.0, 1450760280], [1.0, 1450760340], [0.0, 1450760400], [1.0, 1450760460], [1.0, 1450760520], [1.0, 1450760580], [2.0, 1450760640], [1.0, 1450760700], [2.0, 1450760760], [1.0, 1450760820], [3.0, 1450760880], [3.0, 1450760940], [1.0, 1450761000], [1.0, 1450761060], [1.0, 1450761120], [1.0, 1450761180], [1.0, 1450761240], [1.0, 1450761300], [1.0, 1450761360], [1.0, 1450761420], [1.0, 1450761480], [1.0, 1450761540], [2.0, 1450761600], [1.0, 1450761660], [1.0, 1450761720], [1.0, 1450761780], [1.0, 1450761840], [1.0, 1450761900], [1.0, 1450761960], [2.0, 1450762020], [2.0, 1450762080], [1.0, 1450762140], [2.0, 1450762200], [1.0, 1450762260], [1.0, 1450762320], [8.0, 1450762380], [1.0, 1450762440], [2.0, 1450762500], [1.0, 1450762560], [2.0, 1450762620], [1.0, 1450762680], [1.0, 1450762740], [1.0, 1450762800], [1.0, 1450762860], [1.0, 1450762920], [1.0, 1450762980], [1.0, 1450763040], [1.0, 1450763100], [1.0, 1450763160], [1.0, 1450763220], [1.0, 1450763280], [2.0, 1450763340], [1.0, 1450763400], [1.0, 1450763460], [1.0, 1450763520], [1.0, 1450763580], [2.0, 1450763640], [1.0, 1450763700], [1.0, 1450763760], [2.0, 1450763820], [1.0, 1450763880], [1.0, 1450763940], [1.0, 1450764000], [1.0, 1450764060], [2.0, 1450764120], [2.0, 1450764180], [5.0, 1450764240], [2.0, 1450764300], [1.0, 1450764360], [2.0, 1450764420], [1.0, 1450764480], [2.0, 1450764540], [1.0, 1450764600], [2.0, 1450764660], [1.0, 1450764720], [1.0, 1450764780], [1.0, 1450764840], [2.0, 1450764900], [1.0, 1450764960], [1.0, 1450765020], [1.0, 1450765080], [1.0, 1450765140], [1.0, 1450765200], [1.0, 1450765260], [2.0, 1450765320], [1.0, 1450765380], [1.0, 1450765440], [1.0, 1450765500], [1.0, 1450765560], [1.0, 1450765620], [1.0, 1450765680], [1.0, 1450765740], [1.0, 1450765800], [1.0, 1450765860], [1.0, 1450765920], [1.0, 1450765980], [1.0, 1450766040], [1.0, 1450766100], [3.0, 1450766160], [1.0, 1450766220], [1.0, 1450766280], [18.0, 1450766340], [1.0, 1450766400]]},
{"target": "upper_50", "datapoints": [[130.0, 1450754160], [24.0, 1450754220], [4.0, 1450754280], [1.0, 1450754340], [4.0, 1450754400], [36.0, 1450754460], [30.0, 1450754520], [2.0, 1450754580], [6.0, 1450754640], [186.0, 1450754700], [9.0, 1450754760], [114.0, 1450754820], [288.0, 1450754880], [112.0, 1450754940], [2.0, 1450755000], [5.0, 1450755060], [9.0, 1450755120], [6.0, 1450755180], [149.0, 1450755240], [49.0, 1450755300], [2.0, 1450755360], [238.0, 1450755420], [8.0, 1450755480], [7.0, 1450755540], [267.0, 1450755600], [152.0, 1450755660], [2.0, 1450755720], [18.0, 1450755780], [15.0, 1450755840], [7.0, 1450755900], [3.0, 1450755960], [7.0, 1450756020], [9.0, 1450756080], [219.0, 1450756140], [5.0, 1450756200], [211.0, 1450756260], [6.0, 1450756320], [5.0, 1450756380], [6.0, 1450756440], [49.0, 1450756500], [133.0, 1450756560], [13.0, 1450756620], [8.0, 1450756680], [4.0, 1450756740], [19.0, 1450756800], [137.0, 1450756860], [98.0, 1450756920], [13.0, 1450756980], [282.0, 1450757040], [9.0, 1450757100], [2.0, 1450757160], [83.0, 1450757220], [70.0, 1450757280], [9.0, 1450757340], [76.0, 1450757400], [28.0, 1450757460], [11.0, 1450757520], [33.0, 1450757580], [4.0, 1450757640], [8.0, 1450757700], [6.0, 1450757760], [56.0, 1450757820], [259.0, 1450757880], [370.0, 1450757940], [2.0, 1450758000], [306.0, 1450758060], [45.0, 1450758120], [3.0, 1450758180], [5.0, 1450758240], [1.0, 1450758300], [13.0, 1450758360], [1.0, 1450758420], [55.0, 1450758480], [6.0, 1450758540], [2.0, 1450758600], [90.0, 1450758660], [3.0, 1450758720], [14.0, 1450758780], [15.0, 1450758840], [3.0, 1450758900], [7.0, 1450758960], [6.0, 1450759020], [7.0, 1450759080], [2.0, 1450759140], [43.0, 1450759200], [2.0, 1450759260], [61.0, 1450759320], [20.0, 1450759380], [12.0, 1450759440], [84.0, 1450759500], [49.0, 1450759560], [47.0, 1450759620], [112.0, 1450759680], [40.0, 1450759740], [214.0, 1450759800], [6.0, 1450759860], [2.0, 1450759920], [6.0, 1450759980], [11.0, 1450760040], [106.0, 1450760100], [450.0, 1450760160], [5.0, 1450760220], [7.0, 1450760280], [32.0, 1450760340], [293.0, 1450760400], [8.0, 1450760460], [58.0, 1450760520], [13.0, 1450760580], [86.0, 1450760640], [11.0, 1450760700], [77.0, 1450760760], [21.0, 1450760820], [32.0, 1450760880], [53.0, 1450760940], [11.0, 1450761000], [14.0, 1450761060], [10.0, 1450761120], [5.0, 1450761180], [21.0, 1450761240], [9.0, 1450761300], [245.0, 1450761360], [27.0, 1450761420], [62.0, 1450761480], [8.0, 1450761540], [21.0, 1450761600], [53.0, 1450761660], [13.0, 1450761720], [3.0, 1450761780], [14.0, 1450761840], [9.0, 1450761900], [5.0, 1450761960], [156.0, 1450762020], [9.0, 1450762080], [6.0, 1450762140], [8.0, 1450762200], [24.0, 1450762260], [3.0, 1450762320], [356.0, 1450762380], [42.0, 1450762440], [79.0, 1450762500], [8.0, 1450762560], [211.0, 1450762620], [6.0, 1450762680], [3.0, 1450762740], [3.0, 1450762800], [20.0, 1450762860], [3.0, 1450762920], [2.0, 1450762980], [4.0, 1450763040], [7.0, 1450763100], [7.0, 1450763160], [34.0, 1450763220], [8.0, 1450763280], [14.0, 1450763340], [7.0, 1450763400], [4.0, 1450763460], [14.0, 1450763520], [74.0, 1450763580], [251.0, 1450763640], [5.0, 1450763700], [91.0, 1450763760], [30.0, 1450763820], [28.0, 1450763880], [6.0, 1450763940], [79.0, 1450764000], [17.0, 1450764060], [174.0, 1450764120], [189.0, 1450764180], [120.0, 1450764240], [184.0, 1450764300], [188.0, 1450764360], [250.0, 1450764420], [3.0, 1450764480], [87.0, 1450764540], [17.0, 1450764600], [244.0, 1450764660], [65.0, 1450764720], [8.0, 1450764780], [56.0, 1450764840], [25.0, 1450764900], [5.0, 1450764960], [57.0, 1450765020], [16.0, 1450765080], [38.0, 1450765140], [13.0, 1450765200], [28.0, 1450765260], [91.0, 1450765320], [95.0, 1450765380], [8.0, 1450765440], [61.0, 1450765500], [11.0, 1450765560], [19.0, 1450765620], [5.0, 1450765680], [102.0, 1450765740], [82.0, 1450765800], [133.0, 1450765860], [178.0, 1450765920], [46.0, 1450765980], [68.0, 1450766040], [8.0, 1450766100], [200.0, 1450766160], [128.0, 1450766220], [222.0, 1450766280], [334.0, 1450766340], [153.0, 1450766400]]},
{"target": "upper_75", "datapoints": [[622.0, 1450754160], [365.0, 1450754220], [42.0, 1450754280], [240.0, 1450754340], [401.0, 1450754400], [364.0, 1450754460], [325.0, 1450754520], [6.0, 1450754580], [267.0, 1450754640], [302.0, 1450754700], [123.0, 1450754760], [290.0, 1450754820], [326.0, 1450754880], [322.0, 1450754940], [539.0, 1450755000], [149.0, 1450755060], [18.0, 1450755120], [10.0, 1450755180], [643.0, 1450755240], [256.0, 1450755300], [13.0, 1450755360], [455.0, 1450755420], [341.0, 1450755480], [394.0, 1450755540], [662.0, 1450755600], [244.0, 1450755660], [213.0, 1450755720], [274.0, 1450755780], [466.0, 1450755840], [247.0, 1450755900], [11.0, 1450755960], [178.0, 1450756020], [291.0, 1450756080], [1039.0, 1450756140], [84.0, 1450756200], [384.0, 1450756260], [339.0, 1450756320], [266.0, 1450756380], [22.0, 1450756440], [384.0, 1450756500], [701.0, 1450756560], [549.0, 1450756620], [13.0, 1450756680], [279.0, 1450756740], [266.0, 1450756800], [267.0, 1450756860], [1373.0, 1450756920], [51.0, 1450756980], [388.0, 1450757040], [58.0, 1450757100], [175.0, 1450757160], [425.0, 1450757220], [338.0, 1450757280], [373.0, 1450757340], [509.0, 1450757400], [406.0, 1450757460], [168.0, 1450757520], [342.0, 1450757580], [299.0, 1450757640], [696.0, 1450757700], [483.0, 1450757760], [775.0, 1450757820], [1178.0, 1450757880], [625.0, 1450757940], [230.0, 1450758000], [553.0, 1450758060], [185.0, 1450758120], [584.0, 1450758180], [214.0, 1450758240], [183.0, 1450758300], [282.0, 1450758360], [262.0, 1450758420], [345.0, 1450758480], [204.0, 1450758540], [59.0, 1450758600], [299.0, 1450758660], [82.0, 1450758720], [376.0, 1450758780], [474.0, 1450758840], [526.0, 1450758900], [220.0, 1450758960], [293.0, 1450759020], [77.0, 1450759080], [109.0, 1450759140], [633.0, 1450759200], [69.0, 1450759260], [392.0, 1450759320], [376.0, 1450759380], [309.0, 1450759440], [578.0, 1450759500], [519.0, 1450759560], [310.0, 1450759620], [497.0, 1450759680], [636.0, 1450759740], [674.0, 1450759800], [516.0, 1450759860], [143.0, 1450759920], [325.0, 1450759980], [516.0, 1450760040], [279.0, 1450760100], [977.0, 1450760160], [322.0, 1450760220], [1277.0, 1450760280], [568.0, 1450760340], [907.0, 1450760400], [465.0, 1450760460], [528.0, 1450760520], [156.0, 1450760580], [729.0, 1450760640], [316.0, 1450760700], [466.0, 1450760760], [356.0, 1450760820], [549.0, 1450760880], [448.0, 1450760940], [386.0, 1450761000], [400.0, 1450761060], [391.0, 1450761120], [588.0, 1450761180], [574.0, 1450761240], [507.0, 1450761300], [545.0, 1450761360], [417.0, 1450761420], [542.0, 1450761480], [346.0, 1450761540], [561.0, 1450761600], [765.0, 1450761660], [446.0, 1450761720], [356.0, 1450761780], [523.0, 1450761840], [508.0, 1450761900], [595.0, 1450761960], [457.0, 1450762020], [163.0, 1450762080], [298.0, 1450762140], [301.0, 1450762200], [445.0, 1450762260], [170.0, 1450762320], [595.0, 1450762380], [508.0, 1450762440], [268.0, 1450762500], [488.0, 1450762560], [670.0, 1450762620], [366.0, 1450762680], [501.0, 1450762740], [701.0, 1450762800], [484.0, 1450762860], [232.0, 1450762920], [317.0, 1450762980], [153.0, 1450763040], [444.0, 1450763100], [330.0, 1450763160], [399.0, 1450763220], [612.0, 1450763280], [359.0, 1450763340], [320.0, 1450763400], [424.0, 1450763460], [490.0, 1450763520], [426.0, 1450763580], [717.0, 1450763640], [339.0, 1450763700], [420.0, 1450763760], [436.0, 1450763820], [398.0, 1450763880], [419.0, 1450763940], [595.0, 1450764000], [518.0, 1450764060], [780.0, 1450764120], [466.0, 1450764180], [474.0, 1450764240], [505.0, 1450764300], [593.0, 1450764360], [654.0, 1450764420], [402.0, 1450764480], [456.0, 1450764540], [525.0, 1450764600], [578.0, 1450764660], [413.0, 1450764720], [790.0, 1450764780], [567.0, 1450764840], [512.0, 1450764900], [441.0, 1450764960], [501.0, 1450765020], [550.0, 1450765080], [692.0, 1450765140], [499.0, 1450765200], [507.0, 1450765260], [519.0, 1450765320], [581.0, 1450765380], [414.0, 1450765440], [371.0, 1450765500], [376.0, 1450765560], [617.0, 1450765620], [327.0, 1450765680], [755.0, 1450765740], [615.0, 1450765800], [526.0, 1450765860], [569.0, 1450765920], [473.0, 1450765980], [508.0, 1450766040], [558.0, 1450766100], [577.0, 1450766160], [473.0, 1450766220], [594.0, 1450766280], [695.0, 1450766340], [607.0, 1450766400]]},
{"target": "upper_90", "datapoints": [[861.0, 1450754160], [767.0, 1450754220], [809.0, 1450754280], [744.0, 1450754340], [624.0, 1450754400], [2445.0, 1450754460], [3134.0, 1450754520], [586.0, 1450754580], [505.0, 1450754640], [626.0, 1450754700], [1441.0, 1450754760], [1246.0, 1450754820], [666.0, 1450754880], [813.0, 1450754940], [1654.0, 1450755000], [785.0, 1450755060], [254.0, 1450755120], [534.0, 1450755180], [1042.0, 1450755240], [1574.0, 1450755300], [1001.0, 1450755360], [526.0, 1450755420], [2447.0, 1450755480], [1596.0, 1450755540], [794.0, 1450755600], [731.0, 1450755660], [425.0, 1450755720], [835.0, 1450755780], [510.0, 1450755840], [404.0, 1450755900], [112.0, 1450755960], [418.0, 1450756020], [1032.0, 1450756080], [1661.0, 1450756140], [435.0, 1450756200], [730.0, 1450756260], [591.0, 1450756320], [389.0, 1450756380], [208.0, 1450756440], [512.0, 1450756500], [968.0, 1450756560], [1274.0, 1450756620], [536.0, 1450756680], [893.0, 1450756740], [708.0, 1450756800], [332.0, 1450756860], [1555.0, 1450756920], [331.0, 1450756980], [814.0, 1450757040], [261.0, 1450757100], [358.0, 1450757160], [821.0, 1450757220], [713.0, 1450757280], [945.0, 1450757340], [671.0, 1450757400], [663.0, 1450757460], [1046.0, 1450757520], [957.0, 1450757580], [1017.0, 1450757640], [1096.0, 1450757700], [1233.0, 1450757760], [2616.0, 1450757820], [1919.0, 1450757880], [1850.0, 1450757940], [883.0, 1450758000], [1206.0, 1450758060], [479.0, 1450758120], [1282.0, 1450758180], [501.0, 1450758240], [3727.0, 1450758300], [1019.0, 1450758360], [1075.0, 1450758420], [798.0, 1450758480], [571.0, 1450758540], [457.0, 1450758600], [1682.0, 1450758660], [381.0, 1450758720], [641.0, 1450758780], [618.0, 1450758840], [753.0, 1450758900], [805.0, 1450758960], [783.0, 1450759020], [521.0, 1450759080], [532.0, 1450759140], [1380.0, 1450759200], [696.0, 1450759260], [613.0, 1450759320], [597.0, 1450759380], [1241.0, 1450759440], [1000.0, 1450759500], [1034.0, 1450759560], [590.0, 1450759620], [797.0, 1450759680], [959.0, 1450759740], [1105.0, 1450759800], [921.0, 1450759860], [740.0, 1450759920], [736.0, 1450759980], [961.0, 1450760040], [521.0, 1450760100], [1583.0, 1450760160], [640.0, 1450760220], [1977.0, 1450760280], [1628.0, 1450760340], [1821.0, 1450760400], [1130.0, 1450760460], [799.0, 1450760520], [435.0, 1450760580], [1280.0, 1450760640], [1171.0, 1450760700], [1078.0, 1450760760], [564.0, 1450760820], [1707.0, 1450760880], [786.0, 1450760940], [725.0, 1450761000], [2347.0, 1450761060], [770.0, 1450761120], [896.0, 1450761180], [1019.0, 1450761240], [1241.0, 1450761300], [988.0, 1450761360], [693.0, 1450761420], [757.0, 1450761480], [1522.0, 1450761540], [883.0, 1450761600], [1307.0, 1450761660], [691.0, 1450761720], [600.0, 1450761780], [698.0, 1450761840], [883.0, 1450761900], [796.0, 1450761960], [749.0, 1450762020], [512.0, 1450762080], [946.0, 1450762140], [1069.0, 1450762200], [1202.0, 1450762260], [696.0, 1450762320], [1044.0, 1450762380], [1297.0, 1450762440], [661.0, 1450762500], [829.0, 1450762560], [1268.0, 1450762620], [646.0, 1450762680], [1111.0, 1450762740], [1341.0, 1450762800], [658.0, 1450762860], [806.0, 1450762920], [918.0, 1450762980], [442.0, 1450763040], [796.0, 1450763100], [847.0, 1450763160], [988.0, 1450763220], [756.0, 1450763280], [716.0, 1450763340], [761.0, 1450763400], [749.0, 1450763460], [731.0, 1450763520], [900.0, 1450763580], [1157.0, 1450763640], [811.0, 1450763700], [638.0, 1450763760], [833.0, 1450763820], [787.0, 1450763880], [883.0, 1450763940], [1654.0, 1450764000], [1011.0, 1450764060], [1751.0, 1450764120], [1000.0, 1450764180], [1073.0, 1450764240], [1106.0, 1450764300], [1127.0, 1450764360], [1441.0, 1450764420], [825.0, 1450764480], [881.0, 1450764540], [903.0, 1450764600], [1065.0, 1450764660], [1215.0, 1450764720], [1613.0, 1450764780], [1012.0, 1450764840], [1426.0, 1450764900], [1380.0, 1450764960], [1181.0, 1450765020], [1178.0, 1450765080], [1336.0, 1450765140], [1004.0, 1450765200], [1236.0, 1450765260], [954.0, 1450765320], [1183.0, 1450765380], [952.0, 1450765440], [1163.0, 1450765500], [818.0, 1450765560], [1183.0, 1450765620], [847.0, 1450765680], [1227.0, 1450765740], [1109.0, 1450765800], [1061.0, 1450765860], [824.0, 1450765920], [917.0, 1450765980], [1006.0, 1450766040], [964.0, 1450766100], [906.0, 1450766160], [1036.0, 1450766220], [939.0, 1450766280], [1203.0, 1450766340], [1344.0, 1450766400]]},
{"target": "upper_95", "datapoints": [[861.0, 1450754160], [767.0, 1450754220], [809.0, 1450754280], [907.0, 1450754340], [624.0, 1450754400], [2445.0, 1450754460], [3134.0, 1450754520], [611.0, 1450754580], [505.0, 1450754640], [646.0, 1450754700], [1441.0, 1450754760], [1246.0, 1450754820], [666.0, 1450754880], [813.0, 1450754940], [1654.0, 1450755000], [785.0, 1450755060], [309.0, 1450755120], [1570.0, 1450755180], [1042.0, 1450755240], [1574.0, 1450755300], [1001.0, 1450755360], [729.0, 1450755420], [2447.0, 1450755480], [1596.0, 1450755540], [883.0, 1450755600], [731.0, 1450755660], [1173.0, 1450755720], [1255.0, 1450755780], [716.0, 1450755840], [635.0, 1450755900], [931.0, 1450755960], [558.0, 1450756020], [1614.0, 1450756080], [1881.0, 1450756140], [435.0, 1450756200], [1798.0, 1450756260], [1493.0, 1450756320], [2108.0, 1450756380], [297.0, 1450756440], [702.0, 1450756500], [1216.0, 1450756560], [1666.0, 1450756620], [536.0, 1450756680], [893.0, 1450756740], [916.0, 1450756800], [473.0, 1450756860], [1555.0, 1450756920], [331.0, 1450756980], [1644.0, 1450757040], [556.0, 1450757100], [358.0, 1450757160], [821.0, 1450757220], [1325.0, 1450757280], [1052.0, 1450757340], [974.0, 1450757400], [816.0, 1450757460], [1062.0, 1450757520], [1438.0, 1450757580], [3759.0, 1450757640], [1479.0, 1450757700], [2117.0, 1450757760], [2878.0, 1450757820], [3627.0, 1450757880], [2101.0, 1450757940], [931.0, 1450758000], [1593.0, 1450758060], [487.0, 1450758120], [2282.0, 1450758180], [983.0, 1450758240], [4287.0, 1450758300], [1422.0, 1450758360], [1604.0, 1450758420], [1099.0, 1450758480], [1128.0, 1450758540], [1547.0, 1450758600], [1932.0, 1450758660], [595.0, 1450758720], [708.0, 1450758780], [1481.0, 1450758840], [1107.0, 1450758900], [875.0, 1450758960], [1128.0, 1450759020], [618.0, 1450759080], [1809.0, 1450759140], [2170.0, 1450759200], [831.0, 1450759260], [1898.0, 1450759320], [1556.0, 1450759380], [1388.0, 1450759440], [1864.0, 1450759500], [1220.0, 1450759560], [1351.0, 1450759620], [1612.0, 1450759680], [1089.0, 1450759740], [1364.0, 1450759800], [1397.0, 1450759860], [1194.0, 1450759920], [892.0, 1450759980], [1275.0, 1450760040], [1110.0, 1450760100], [2732.0, 1450760160], [1751.0, 1450760220], [2395.0, 1450760280], [1750.0, 1450760340], [1821.0, 1450760400], [1353.0, 1450760460], [1088.0, 1450760520], [938.0, 1450760580], [1699.0, 1450760640], [1497.0, 1450760700], [1880.0, 1450760760], [599.0, 1450760820], [2319.0, 1450760880], [1114.0, 1450760940], [840.0, 1450761000], [2462.0, 1450761060], [1316.0, 1450761120], [1018.0, 1450761180], [1195.0, 1450761240], [1300.0, 1450761300], [1389.0, 1450761360], [908.0, 1450761420], [2060.0, 1450761480], [1535.0, 1450761540], [1535.0, 1450761600], [2505.0, 1450761660], [920.0, 1450761720], [996.0, 1450761780], [1378.0, 1450761840], [1171.0, 1450761900], [1105.0, 1450761960], [848.0, 1450762020], [798.0, 1450762080], [1338.0, 1450762140], [1307.0, 1450762200], [1317.0, 1450762260], [940.0, 1450762320], [1418.0, 1450762380], [1699.0, 1450762440], [859.0, 1450762500], [1038.0, 1450762560], [1760.0, 1450762620], [676.0, 1450762680], [1501.0, 1450762740], [1521.0, 1450762800], [714.0, 1450762860], [964.0, 1450762920], [1286.0, 1450762980], [609.0, 1450763040], [1363.0, 1450763100], [1610.0, 1450763160], [1097.0, 1450763220], [1571.0, 1450763280], [949.0, 1450763340], [1239.0, 1450763400], [998.0, 1450763460], [808.0, 1450763520], [1158.0, 1450763580], [1683.0, 1450763640], [1195.0, 1450763700], [733.0, 1450763760], [1498.0, 1450763820], [1015.0, 1450763880], [956.0, 1450763940], [2610.0, 1450764000], [1335.0, 1450764060], [2282.0, 1450764120], [1840.0, 1450764180], [1540.0, 1450764240], [1371.0, 1450764300], [1553.0, 1450764360], [1722.0, 1450764420], [1031.0, 1450764480], [1850.0, 1450764540], [1590.0, 1450764600], [1264.0, 1450764660], [1828.0, 1450764720], [2048.0, 1450764780], [1460.0, 1450764840], [1498.0, 1450764900], [1671.0, 1450764960], [1516.0, 1450765020], [2505.0, 1450765080], [1489.0, 1450765140], [1141.0, 1450765200], [1756.0, 1450765260], [1161.0, 1450765320], [1687.0, 1450765380], [1227.0, 1450765440], [1979.0, 1450765500], [1457.0, 1450765560], [1400.0, 1450765620], [1267.0, 1450765680], [1560.0, 1450765740], [1843.0, 1450765800], [1565.0, 1450765860], [1266.0, 1450765920], [1063.0, 1450765980], [1464.0, 1450766040], [1333.0, 1450766100], [1004.0, 1450766160], [1358.0, 1450766220], [1234.0, 1450766280], [1744.0, 1450766340], [1640.0, 1450766400]]}
];
for (var i = 0; i < timeserie.length; i++) {
var series = timeserie[i];
var now = Date.now();
var decreaser = 0;
for (var y = 0; y < series.datapoints.length; y++) {
series.datapoints[y][1] = (now - decreaser);
decreaser += 50000;
}
}
var annotation = {
name : "annotation name",
enabled: true,
datasource: "generic datasource",
showLine: true,
}
var annotations = [
{ annotation: annotation, "title": "Donlad trump is kinda funny", "time": 1450754160000, text: "teeext", tags: "taaags" },
{ annotation: annotation, "title": "Wow he really won", "time": 1450754160000, text: "teeext", tags: "taaags" },
{ annotation: annotation, "title": "When is the next ", "time": 1450754160000, text: "teeext", tags: "taaags" }
];
var now = Date.now();
var decreaser = 0;
for (var i = 0;i < annotations.length; i++) {
var anon = annotations[i];
anon.time = (now - decreaser);
decreaser += 1000000
}
app.all('/', function(req, res) {
res.send('I have a quest for you!');
res.end();
});
app.all('/search', function(req, res){
var result = [];
_.each(timeserie, function(ts) {
result.push(ts.target);
});
res.send(JSON.stringify(result));
res.end();
});
app.all('/annotations', function(req, res) {
console.log(req.url);
console.log(req.body);
res.send(JSON.stringify(annotations));
res.end();
})
app.all('/query', function(req, res){
console.log(req.url);
console.log(req.body);
var tsResult = [];
_.each(req.body.targets, function(target) {
var k = _.filter(timeserie, function(t) {
return t.target === target.target;
});
_.each(k, function(kk) {
tsResult.push(kk)
});
});
res.send(JSON.stringify(tsResult));
res.end();
});
app.listen(3333);
console.log("Server is listening");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment