mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
moved python scripts to DataProcessing repo
This commit is contained in:
parent
467e405644
commit
a0053844fc
9 changed files with 0 additions and 182 deletions
1
tools/python/.gitignore
vendored
1
tools/python/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
*.pyc
|
|
@ -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
|
||||
```
|
|
@ -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()
|
|
@ -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()
|
|
@ -1,4 +0,0 @@
|
|||
from msg import Message
|
||||
from ts import Timestamp
|
||||
|
||||
__all__ = [ "msg", "ts" ]
|
|
@ -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)
|
|
@ -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"
|
||||
}
|
||||
})
|
|
@ -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))
|
Loading…
Add table
Reference in a new issue