]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/plugins/base.py
plugins: Automatically replace None by NaN
[collecty.git] / src / collecty / plugins / base.py
index 76eaad6a6e674c2f4bae256747746010d0769904..cf9c3b402410bf085fd7b0e825644aef42d6fba4 100644 (file)
@@ -147,8 +147,7 @@ class Plugin(object, metaclass=PluginRegistration):
                        try:
                                result = o.collect()
 
-                               if isinstance(result, tuple) or isinstance(result, list):
-                                       result = ":".join(("%s" % e for e in result))
+                               result = self._format_result(result)
                        except:
                                self.log.warning(_("Unhandled exception in %s.collect()") % o, exc_info=True)
                                continue
@@ -170,6 +169,25 @@ class Plugin(object, metaclass=PluginRegistration):
                if delay >= 60:
                        self.log.warning(_("A worker thread was stalled for %.4fs") % delay)
 
+       @staticmethod
+       def _format_result(result):
+               if not isinstance(result, tuple) and not isinstance(result, list):
+                       return result
+
+               # Replace all Nones by NaN
+               s = []
+
+               for e in result:
+                       if e is None:
+                               e = "NaN"
+
+                       # Format as string
+                       e = "%s" % e
+
+                       s.append(e)
+
+               return ":".join(s)
+
        def get_object(self, id):
                for object in self.objects:
                        if not object.id == id:
@@ -435,13 +453,13 @@ class GraphTemplate(object):
                        if self.upper_limit is not None:
                                args += ["--upper-limit", self.upper_limit]
 
-               # Add interval
-               args.append("--start")
-
                try:
-                       args.append(self.intervals[interval])
+                       interval = self.intervals[interval]
                except KeyError:
-                       args.append(str(interval))
+                       interval = "end-%s" % interval
+
+               # Add interval
+               args += ["--start", interval]
 
                return args