diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-03-05 16:47:32 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-03-05 16:47:32 +0100 |
commit | 7ca173de3de046501d79164da0c8c8871a03089b (patch) | |
tree | 16d857cf2ab7fd8b7b3c29efbacd6b01c2eacec7 /web/static/app/diller/global.js | |
parent | dda9ef2ae7971bceaa792e328c8489cb0695b77e (diff) | |
download | diller-server-7ca173de3de046501d79164da0c8c8871a03089b.tar.gz diller-server-7ca173de3de046501d79164da0c8c8871a03089b.tar.bz2 diller-server-7ca173de3de046501d79164da0c8c8871a03089b.tar.xz diller-server-7ca173de3de046501d79164da0c8c8871a03089b.zip |
web:
o Adding an API method to get per-hour aggregate values. Doesn't use the by_hour table yet.
o Adding a simple line graph component that can graph a single property's value.
Diffstat (limited to 'web/static/app/diller/global.js')
-rw-r--r-- | web/static/app/diller/global.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/web/static/app/diller/global.js b/web/static/app/diller/global.js new file mode 100644 index 0000000..0da8da7 --- /dev/null +++ b/web/static/app/diller/global.js @@ -0,0 +1,60 @@ +(function () { + var Diller = window.Diller = window.Diller || {}; + + function toDate(unknown) { + if (!unknown) { + return undefined; + } else if (moment.isMoment(unknown)) { + return unknown; + } else if (typeof unknown === 'string') { + unknown = unknown.trim(); + + if (unknown == '') { + return moment(); + } + + return moment(unknown, 'YYYY-MM-DDTHH:mm.sssZ'); + } else if (typeof unknown === 'string' || moment.isDate(unknown)) { + return moment(unknown); + } else { + return undefined; + } + } + + Diller.Interval = function (from, to) { + var f = toDate(from), + t = toDate(to); + + if (f.isAfter(t)) { + var tmp = f; + f = t; + t = tmp; + } + + return { + getFrom: function () { + return f || moment(); + }, + getTo: function () { + return t || moment(); + }, + toString: function () { + return 'yo' + } + }; + }; + + Diller.Interval.create = function (value) { + if (value instanceof Diller.Interval) { + return value; + } + + return new Diller.Interval.hours(24); + }; + + Diller.Interval.hours = function (hours) { + var to = moment(); + var from = to.subtract(hours, 'hours'); + return new Diller.Interval(from, to); + }; +})(); |