Commit f29860fa authored by sarrvesh's avatar sarrvesh

add distance table to pdf

parent d9f852bb
......@@ -196,13 +196,14 @@ def on_resolve_click(n, closeMsgBox, targetName, is_open):
State('msgboxGenPdf', 'is_open'),
State('elevation-plot', 'figure')
State('elevation-plot', 'figure'),
State('distance-table', 'figure')
]
)
def on_genpdf_click(n_clicks, closeMsgBox, obsT, nCore, nRemote, nInt, nChan,
nSb, integT, antSet, pipeType, tAvg, fAvg, isDysco,
imNoiseVal, rawSize, procSize, pipeTime, isMsgBoxOpen,
elevation_fig):
elevation_fig, distance_table):
"""Function defines what to do when the generate pdf button is clicked"""
if isMsgBoxOpen is True and closeMsgBox is not None:
# The message box is open and the user has clicked the close
......@@ -225,7 +226,7 @@ def on_genpdf_click(n_clicks, closeMsgBox, obsT, nCore, nRemote, nInt, nChan,
g.generatepdf(relPath, obsT, nCore, nRemote, nInt, nChan,
nSb, integT, antSet, pipeType, tAvg, fAvg, isDysco,
imNoiseVal, rawSize, procSize, pipeTime, elevation_fig,
isMsgBoxOpen)
distance_table, isMsgBoxOpen)
return {'display':'block'}, '/luci/{}'.format(relPath), False
@app.server.route('/luci/static/<resource>')
......
......@@ -42,7 +42,7 @@ def makePdfPlot(elevation_fig, outfilename):
def generatepdf(pdffile, obsT, nCore, nRemote, nInt, nChan, nSb, integT,
antSet, pipeType, tAvg, fAvg, isDysco, imNoiseVal, rawSize,
procSize, pipeTime, elevation_fig, isMsgBoxOpen):
procSize, pipeTime, elevation_fig, distance_table, isMsgBoxOpen):
"""Function to generate a pdf file summarizing the content of the calculator.
Return nothing."""
# Create an A4 sheet
......@@ -103,8 +103,31 @@ def generatepdf(pdffile, obsT, nCore, nRemote, nInt, nChan, nSb, integT,
string += '<center>'
string += '<img src={} width=400 height=250>'.format(pngfilename)
string += '</center>'
# Add the distance table to the PDF
if distance_table != {}:
title = distance_table['layout']['title']
string += '<center><b>{}</b></center>'.format(title)
string += '<table border="0" align="left" width="80%">'
col_titles = distance_table['data'][0]['header']['values']
col_width = 100//len(col_titles)
string += '<thead><tr>'
for item in col_titles:
string += '<th width="{}%" align="left">'.format(col_width) + item + '</th>'
string += '</tr></thead>'
string += '<tbody>'
row_titles = distance_table['data'][0]['cells']['values'][0]
tab_data = distance_table['data'][0]['cells']['values']
# Transpose tab_data and write cells to the table
tab_data = list(map(list, zip(*tab_data)))
for row in tab_data:
string += '<tr>'
for item in row:
string += '<td>{}</td>'.format(item)
string += '</tr>'
string += '</tbody>'
string += '</table>'
# Write text to the pdf file
pdf.write_html(string)
......
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