Skip to content

Commit d9967b3

Browse files
committed
Render TDMS Metadata
1 parent a4da985 commit d9967b3

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed

mfr/extensions/tdms/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .render import TdmsRenderer # noqa

mfr/extensions/tdms/render.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import os
2+
3+
import nptdms
4+
from nptdms import TdmsFile
5+
from mako.lookup import TemplateLookup
6+
7+
from mfr.core import extension
8+
9+
# class EscapeHtml(Extension):
10+
# def extendMarkdown(self, md, md_globals):
11+
# del md.preprocessors['html_block']
12+
# del md.inlinePatterns['html']
13+
14+
15+
class TdmsRenderer(extension.BaseRenderer):
16+
17+
TEMPLATE = TemplateLookup(
18+
directories=[
19+
os.path.join(os.path.dirname(__file__), 'templates')
20+
]).get_template('viewer.mako')
21+
22+
def __init__(self, *args, **kwargs):
23+
super().__init__(*args, **kwargs)
24+
self.metrics.add('nptdms_version', nptdms.version.__version__)
25+
26+
def render(self):
27+
"""Render a tdms file to html."""
28+
29+
tdms_file = TdmsFile.open(self.file_path, raw_timestamps=True)
30+
31+
body = "<div><ul>"
32+
for property, value in tdms_file.properties.items():
33+
body += "<li><b>File</b> = " + str(value) + "</li>\n\n"
34+
body += "</ul></div><div><ul>"
35+
for group in tdms_file.groups():
36+
body += "<li><b>Channel group</b> = " + group.name + "</li>\n"
37+
body += "<ul>"
38+
for channel in group.channels():
39+
body += "<li><b>Channel</b> = " + channel.name + "</li>\n"
40+
body += "<ul>"
41+
# Access dictionary of properties:
42+
for property, value in channel.properties.items():
43+
body += "<li>" + property + " = " + str(value) + "</li>\n\n"
44+
45+
# Access numpy array of data for channel:
46+
# body = body + str(channel[:]) + ""
47+
body += "</ul>"
48+
body += "</ul>"
49+
body += "</ul></div>"
50+
51+
return self.TEMPLATE.render(base=self.assets_url, body=body)
52+
53+
@property
54+
def file_required(self):
55+
return True
56+
57+
@property
58+
def cache_result(self):
59+
return True
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.tl { position: absolute; top: 0; left: 0; right: 30%; bottom: 30%;
2+
background: red; border:solid #000; border-width: 0 10px 10px 0; }
3+
4+
.tr { position: absolute; top: 0; left: 70%; right: 0; bottom: 30%;
5+
background: blue; border:solid #000; border-width: 0 0 10px 0; }
6+
7+
.bl { position: absolute; top: 70%; left: 0; right: 30%; bottom: 0;
8+
background: yellow; border:solid #000; border-width: 0 10px 0 0; }
9+
10+
.br { position: absolute; top: 70%; left: 70%; right: 0; bottom: 0;
11+
background: green; }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700" rel="stylesheet" type="text/css">
2+
<link rel="stylesheet" href="static/css/default.css">
3+
<link rel="stylesheet" href="${base}/css/tdms.css">
4+
5+
<body>
6+
<div class="tl">
7+
${body}
8+
</div>
9+
<div class="tr"></div>
10+
<div class="bl"></div>
11+
<div class="br"></div>
12+
</body>
13+
<script src="/static/js/mfr.js"></script>
14+
<script src="/static/js/mfr.child.js"></script>

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jinja2==2.10.1
3636
mistune==0.8.1
3737

3838
# Pdf
39-
reportlab==3.4.0
39+
reportlab==3.5.56
4040

4141
# Pptx
4242
# python-pptx==0.5.7
@@ -53,5 +53,8 @@ scipy==0.19.1
5353
# Md
5454
markdown==2.6.2
5555

56+
# TDMS
57+
npTDMS==1.1.0
58+
5659
# Issue: certifi-2015.9.6.1 and 2015.9.6.2 fail verification (https://github.com/certifi/python-certifi/issues/26)
5760
certifi==2015.4.28

0 commit comments

Comments
 (0)