From a0053844fc9f0dfb1cf1f94f28a1e14400de4bf6 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 16 Aug 2017 09:05:29 +0200 Subject: [PATCH] moved python scripts to DataProcessing repo --- tools/matlab/.gitkeep | 0 tools/python/.gitignore | 1 - tools/python/README.md | 11 -------- tools/python/file-filter.py | 23 ----------------- tools/python/file-merge.py | 35 ------------------------- tools/python/villas/__init__.py | 4 --- tools/python/villas/msg.py | 24 ----------------- tools/python/villas/ocb.py | 38 --------------------------- tools/python/villas/ts.py | 46 --------------------------------- 9 files changed, 182 deletions(-) delete mode 100644 tools/matlab/.gitkeep delete mode 100644 tools/python/.gitignore delete mode 100644 tools/python/README.md delete mode 100755 tools/python/file-filter.py delete mode 100755 tools/python/file-merge.py delete mode 100644 tools/python/villas/__init__.py delete mode 100644 tools/python/villas/msg.py delete mode 100644 tools/python/villas/ocb.py delete mode 100644 tools/python/villas/ts.py diff --git a/tools/matlab/.gitkeep b/tools/matlab/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/python/.gitignore b/tools/python/.gitignore deleted file mode 100644 index 0d20b6487..000000000 --- a/tools/python/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pyc diff --git a/tools/python/README.md b/tools/python/README.md deleted file mode 100644 index 2e703ac5b..000000000 --- a/tools/python/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Python tools - -These python scripts are intended to manipulate measurements recorded by VILLASnode's `file` node-type. - -## Exampples - -##### Merge two files and filter the output based on timestamps - -``` -./file-merge.py testfile.dat testfile2.dat | ./file-filter.py 3 5 > output.dat -``` diff --git a/tools/python/file-filter.py b/tools/python/file-filter.py deleted file mode 100755 index de9e145d6..000000000 --- a/tools/python/file-filter.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -import sys - -import villas -from villas import * - -def main(): - if len(sys.argv) != 3: - print "Usage: %s from to" % (sys.argv[0]) - sys.exit(-1) - - start = villas.Timestamp.parse(sys.argv[1]) - end = villas.Timestamp.parse(sys.argv[2]) - - for line in sys.stdin: - msg = villas.Message.parse(line) - - if start <= msg.ts <= end: - print msg - -if __name__ == "__main__": - main() diff --git a/tools/python/file-merge.py b/tools/python/file-merge.py deleted file mode 100755 index 3b67b12b0..000000000 --- a/tools/python/file-merge.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python - -import sys - -import villas -from villas import * - -def main(): - files = sys.argv[1:] - - all = [ ] - last = { } - - for file in files: - handle = sys.stdin if file == '-' else open(file, "r") - - msgs = [ ] - for line in handle.xreadlines(): - msgs.append(villas.Message.parse(line, file)) - - all += msgs - last[file] = villas.Message(villas.Timestamp(), [0] * len(msgs[0].values), file) - - all.sort() - for msg in all: - last[msg.source] = msg - - values = [ ] - for file in files: - values += last[file].values - - print villas.Message(msg.ts, values, "") - -if __name__ == "__main__": - main() diff --git a/tools/python/villas/__init__.py b/tools/python/villas/__init__.py deleted file mode 100644 index bdf91102a..000000000 --- a/tools/python/villas/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from msg import Message -from ts import Timestamp - -__all__ = [ "msg", "ts" ] diff --git a/tools/python/villas/msg.py b/tools/python/villas/msg.py deleted file mode 100644 index 4d34e017a..000000000 --- a/tools/python/villas/msg.py +++ /dev/null @@ -1,24 +0,0 @@ -from . import ts - -class Message: - """Parsing a VILLASnode sample from a file (not a UDP package!!)""" - - def __init__(self, ts, values, source = None): - self.source = source - self.ts = ts - self.values = values - - @classmethod - def parse(self, line, source = None): - csv = line.split() - - t = ts.Timestamp.parse(csv[0]) - v = map(float, csv[1:]) - - return Message(t, v, source) - - def __str__(self): - return '%s %s' % (self.ts, " ".join(map(str, self.values))) - - def __cmp__(self, other): - return cmp(self.ts, other.ts) diff --git a/tools/python/villas/ocb.py b/tools/python/villas/ocb.py deleted file mode 100644 index c5983e83e..000000000 --- a/tools/python/villas/ocb.py +++ /dev/null @@ -1,38 +0,0 @@ -import re - -class OcbMapping: - def __init__(self, entityId, entityType, attributeName, attributeType): - self.entityId = entityId - self.entityType = entityType - self.attributeName = attributeName - self.attributeType = attributeType - - @classmethod - def parse(self, lines): - m = re.match('([a-z]+)\(([a-z]+)\)\.([a-z]+).\(([a-z]+)\)', re.I) - return OcbMapping(m.group(1), m.group(2), m.group(3), m.group(4)) - - @classMethod - def parseFile(self, file): - -class OcbEntity: - -class OcbAttribute: - -class OcbResponse: - def __init__(self, mapping): - self.mapping = mapping - - def getJson(self, msg): - json = { "contextResponses" : [ ] } - - for (value in msg.values): - json["contextResponses"].append({ - "statusCode" : { "code" : 200, "reasonPhrase" : "OK" } - "contextElement" : { - "attributes" = [ ], - "id" : "", - "isPattern" : false, - "type" - } - }) diff --git a/tools/python/villas/ts.py b/tools/python/villas/ts.py deleted file mode 100644 index 96df86812..000000000 --- a/tools/python/villas/ts.py +++ /dev/null @@ -1,46 +0,0 @@ -import re - -class Timestamp: - """Parsing the VILLASnode human-readable timestamp format""" - - def __init__(self, seconds = 0, nanoseconds = None, offset = None, sequence = None): - self.seconds = seconds - self.nanoseconds = nanoseconds - self.offset = offset - self.sequence = sequence - - @classmethod - def parse(self, ts): - m = re.match('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts) - - seconds = int(m.group(1)); # Mandatory - nanoseconds = int(m.group(2)) if m.group(2) else None - offset = float(m.group(3)) if m.group(3) else None - sequence = int(m.group(4)) if m.group(4) else None - - return Timestamp(seconds, nanoseconds, offset, sequence) - - def __str__(self): - str = "%u" % (self.seconds) - - if self.nanoseconds is not None: - str += ".%09u" % self.nanoseconds - if self.offset is not None: - str += "+%u" % self.offset - if self.sequence is not None: - str += "(%u)" % self.sequence - - return str - - def __float__(self): - sum = float(self.seconds) - - if self.nanoseconds is not None: - sum += self.nanoseconds * 1e-9 - if self.offset is not None: - sum += self.offset - - return sum - - def __cmp__(self, other): - return cmp(float(self), float(other))