Support either ISO or time_t dates for download.
authorPat Thoyts <Patrick.Thoyts@renishaw.com>
Tue, 17 May 2016 22:53:12 +0000 (23:53 +0100)
committerPat Thoyts <Patrick.Thoyts@renishaw.com>
Tue, 17 May 2016 22:53:12 +0000 (23:53 +0100)
sensor-hub.wsgi
static/sensor-hub.html

index 4d09940196eb879b046c897059d77f9a5e15be75..6009057b7d69a28fb7057c76c31b49df6193ba6d 100755 (executable)
@@ -120,6 +120,14 @@ class SensorHubService():
         result = sorted(groups, key=len, reverse=True)[0]
         return {'response': result, 'version': self.version}
 
+    def parse_time(self, str):
+        """Parse a time, either as unix time or a ISO timestamp"""
+        try:
+            return int(str)
+        except ValueError:
+            return int(dateparser.parse(str).timestamp())
+
+    def get_ascii(self, data):
     @cherrypy.expose
     def download(self, *args, **kwargs):
         try:
@@ -128,7 +136,9 @@ class SensorHubService():
             if param_from is None or param_until is None:
                 raise Exception("must provide both from and to parameters")
             else:
-                data = self.get_since(int(param_from), int(param_until))
+                param_from = self.parse_time(param_from)
+                param_until = self.parse_time(param_until)
+                data = self.get_since(param_from, param_until)
                 if cherrypy.request.params.get('type') == 'text':
                     cherrypy.response.headers['content-type'] = 'text/plain'
                     raise Exception("not implemented")
index 801efa55280b3868130cab343b6a51b89c331384..4574e372eedddd1525b519955eab3e0d812b898d 100644 (file)
@@ -1,4 +1,4 @@
-<!doctype html>
+<!doctype html>
 <html lang="en">
 <head>
 <meta charset="utf-8"/>
@@ -70,8 +70,8 @@ function weekend_markings(axes) {
 }
 function on_download(mimetype)
 {
-    if (document.custom.graph) {
-        var axes = document.custom.graph.getAxes()
+    if (document.custom.graph_main) {
+        var axes = document.custom.graph_main.plot.getAxes()
         var upper = parseInt(axes.xaxis.max / 1000);
         var lower = parseInt(axes.xaxis.min / 1000);
         var url = 'download?type=' + mimetype + '&from=' + lower + '&to=' + upper;