Skip to content

Commit

Permalink
added template
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdu committed Sep 13, 2024
1 parent c720b7c commit c4abf36
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pyfastx==2.1.0
PySide6-Essentials==6.4.3
primer3-py==2.0.3
pyinstaller==6.10.0
jinja2==3.1.4
26 changes: 19 additions & 7 deletions src/stats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import jinja2
import pyfastx

from PySide6.QtCore import *
Expand Down Expand Up @@ -1061,15 +1062,15 @@ def get_style_css(self):
styles = []
for css_file in css_files:
f = QFile(css_file)
text = None

if f.open(QIODevice.ReadOnly | QFile.Text):
text = QTextStream(f).readAll()
else:
text = None

f.close()

if text:
styles.append("<style>{}</style>".format(text))
styles.append(text)

return '\n'.join(styles)

Expand All @@ -1083,15 +1084,15 @@ def get_script_js(self):
js = []
for js_file in js_files:
f = QFile(js_file)
text = None

if f.open(QIODevice.ReadOnly | QFile.Text):
text = QTextStream(f).readAll()
else:
text = None

f.close()

if text:
js.append("<script>{}</script>".format(text))
js.append(text)

return '\n'.join(js)

Expand Down Expand Up @@ -1241,9 +1242,20 @@ def generate_summary_report(self):
</html>
"""

with open('template/stats.html') as fh:
content = fh.read()

template = jinja2.Template(content)

styles = self.get_style_css()
scripts = self.get_script_js()

return template.render(
styles = styles,
scripts = scripts
)

tables = self.get_stats_tables()
plots = self.get_stats_plots()

return template.format(styles, scripts, tables, plots)
#return template.format(styles, scripts, tables, plots)
69 changes: 69 additions & 0 deletions src/template/stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title>Krait statistics report</title>
<style>
:root {
--tblr-font-sans-serif: 'Inter Var', -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
}
body {
font-feature-settings: "cv03", "cv04", "cv11";
}
{{ styles }}
</style>
</head>
<body >
<div class="page">
<header class="navbar navbar-expand-md d-print-none" >
<div class="container-xl">
<h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-md-3">
Krait Statistics Report
</h1>
<div class="navbar-nav flex-row order-md-last">
<div class="nav-item d-none d-md-flex me-3">
</div>
</div>
</header>
<div class="page-wrapper">
<div class="page-body">
<div class="container-xl">

</div>
</div>
<footer class="footer footer-transparent d-print-none">
<div class="container-xl">
<div class="row text-center align-items-center flex-row-reverse">
<div class="col-lg-auto ms-lg-auto">
<ul class="list-inline list-inline-dots mb-0">
<li class="list-inline-item"><a href="https://krait2.readthedocs.org" target="_blank" class="link-secondary" rel="noopener">Documentation</a></li>
<li class="list-inline-item"><a href="https://github.com/lmdu/krait2/releases" target="_blank" class="link-secondary" rel="noopener">Check updates</a></li>
<li class="list-inline-item"><a href="https://github.com/lmdu/krait2" target="_blank" class="link-secondary" rel="noopener">Source code</a></li>
<li class="list-inline-item">
<a href="https://github.com/lmdu/krait2/issues" target="_blank" class="link-secondary" rel="noopener">
Report issues
</a>
</li>
</ul>
</div>
<div class="col-12 col-lg-auto mt-3 mt-lg-0">
<ul class="list-inline list-inline-dots mb-0">
<li class="list-inline-item">
Generated by
<a href="https://github.com/lmdu/krait2" class="link-secondary">Krait</a>
v2.0.0
</li>
</ul>
</div>
</div>
</div>
</footer>
</div>
</div>
<script type="text/javascript">
{{ scripts }}
</script>
</body>
</html>

0 comments on commit c4abf36

Please sign in to comment.