Commit 6b4f5ba4 authored by Thorsten Simons's avatar Thorsten Simons

1.3.2 - added query runtime to content sheet in xlsx

parent b30d2505
Release History
===============
**1.3.2 2017-10-10**
* added query runtime to content sheet in xlsx
**1.3.1 2017-10-05**
* added timestamp of first and last record to xlsx file
......
......@@ -264,6 +264,7 @@ class DB():
for rec in data:
if first:
_csv.newsheet(mps[fu], list(rec.keys()),
runtime=runtime,
comment=self.queries.c.get(mps[fu],
'comment',
fallback=''))
......
......@@ -113,16 +113,18 @@ class Xlsx(Csv):
self.contentws = self.wb.add_worksheet(name='CONTENT')
def newsheet(self, name, fieldnames, comment=''):
def newsheet(self, name, fieldnames, runtime=0.0, comment=''):
"""
Create a new worksheet
:param name: the files base name
:param fieldnames: a list of field names
:param runtime: the time it took to run the query (seconds)
:param comment: a comment to be added
"""
self.content[name] = comment
self.fieldnames = fieldnames
self.content[name] = {'comment': comment,
'runtime': '({:0.1f} sec.)'.format(float(runtime))}
self.colw = [len(w) for w in fieldnames]
self.ws = self.wb.add_worksheet(name=name)
......@@ -183,33 +185,42 @@ class Xlsx(Csv):
"""
row = 3
col = 1
w_q = w_c = 0
w_q = w_c = w_r = 0
title = self.wb.add_format({'bold': True,
'align': 'center',
'font_size': 14,
'bg_color': 'yellow'})
left = self.wb.add_format({'bold': True,
right = self.wb.add_format({'bold': True,
'align': 'right',
'font_size': 12})
link = self.wb.add_format({'bold': True,
'align': 'left',
'font_size': 12,
'color': 'blue'})
light = self.wb.add_format({'bold': False,
'italic': True,
'align': 'right',
'font_size': 12,
'font_color': 'lightgrey'})
footer = self.wb.add_format({'bold': False,
'align': 'center',
'font_size': 10,
'bg_color': 'yellow'})
# headline
self.contentws.merge_range(1, 1, 1, 3, 'Content', title)
self.contentws.merge_range(1, 1, 1, 5, 'Content', title)
for q in sorted(self.content.keys()):
self.contentws.write(row, col, q, left)
self.contentws.write(row, col, q, right)
self.contentws.write_url(row, col+2,
'internal:{}!A1'.format(q),
link, self.content[q])
link, self.content[q]['comment'])
self.contentws.write(row, col+4, self.content[q]['runtime'], light)
w_q = len(q) if len(q) > w_q else w_q
w_c = len(self.content[q]) if len(self.content[q]) > w_c else w_c
w_c = len(self.content[q]['comment']) if len(
self.content[q]['comment']) > w_c else w_c
w_r = len(self.content[q]['runtime']) if len(
self.content[q]['runtime']) > w_r else w_r
row += 1
# set column width for...
......@@ -219,9 +230,13 @@ class Xlsx(Csv):
self.contentws.set_column(col+1, col+1, 2)
# ...the comment, linking to the respetive sheet
self.contentws.set_column(col+2, col+2, w_c*.9)
# ...spacer
self.contentws.set_column(col+3, col+3, 2)
# ...the queries' runtime in seconds
self.contentws.set_column(col+4, col+4, w_r*.9)
# footer
self.contentws.merge_range(row+2, 1, row+2, 3,
self.contentws.merge_range(row+2, 1, row+2, 5,
'created {} from log records starting at {}, ending at {}'
.format(asctime(),
strftime('%a %b %d %H:%M:%S %Y',
......
......@@ -27,8 +27,8 @@ class Gvars:
"""
# version control
s_version = "1.3.1"
s_builddate = '2017-10-05'
s_version = "1.3.2"
s_builddate = '2017-10-10'
s_build = "{}/Sm".format(s_builddate)
s_minPython = "3.4.3"
s_description = "hcprequestanalytics"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment