mirror of
https://github.com/lubuntu-team/metrics.git
synced 2025-05-01 15:41:28 +00:00
Add a summary page.
This commit is contained in:
parent
36ac2eb5fd
commit
5b4ed6ac5c
53
metrics
53
metrics
@ -18,7 +18,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging as log
|
import logging as log
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from jinja2 import Template
|
||||||
from modules.jenkins import JenkinsModule
|
from modules.jenkins import JenkinsModule
|
||||||
|
from os import path
|
||||||
|
|
||||||
ENABLED_MODULES = [JenkinsModule]
|
ENABLED_MODULES = [JenkinsModule]
|
||||||
|
|
||||||
@ -47,6 +49,40 @@ def sqlite_run(command, db, return_output=False):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def summary():
|
||||||
|
"""Reading summary_page, generate a summary page using the averages
|
||||||
|
|
||||||
|
summary_page should be a dict, with keys being the human-readable module
|
||||||
|
name and the value being another dict, which has averages for each day.
|
||||||
|
|
||||||
|
Example: {"foo": {1: (100, 200, 300)}}
|
||||||
|
|
||||||
|
Special-casing is done right in the template file, as different modules
|
||||||
|
are going to have different averages.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Open the template file as a Jinja2 Template
|
||||||
|
t_path = path.join("templates", "index.html")
|
||||||
|
with open(t_path) as templatef:
|
||||||
|
template = ""
|
||||||
|
for text in templatef.readlines():
|
||||||
|
template += text
|
||||||
|
template = Template(template)
|
||||||
|
|
||||||
|
# Render the template with the values from summary_page
|
||||||
|
log.debug("summary_page: " + str(summary_page))
|
||||||
|
template = template.render(page=summary_page)
|
||||||
|
|
||||||
|
# Write it back to the output file
|
||||||
|
# We don't have to worry about creating the output dir, since the
|
||||||
|
# module-specific template rendering should already do this for us
|
||||||
|
#
|
||||||
|
# FIXME: Writing to/from files is done in several places, maybe centralize
|
||||||
|
# the code in its own "internal" module?
|
||||||
|
with open(path.join("output", "index.html"), "w+") as f:
|
||||||
|
f.write(template)
|
||||||
|
|
||||||
|
|
||||||
def main(module):
|
def main(module):
|
||||||
"""Given a specific module, set it up and insert recent values"""
|
"""Given a specific module, set it up and insert recent values"""
|
||||||
|
|
||||||
@ -57,6 +93,10 @@ def main(module):
|
|||||||
run = [module.sqlite_setup(), module.sqlite_add()]
|
run = [module.sqlite_setup(), module.sqlite_add()]
|
||||||
log.debug(sqlite_run(run, db=args.db_location))
|
log.debug(sqlite_run(run, db=args.db_location))
|
||||||
|
|
||||||
|
# This is going to be a dict of tuples, with the key being the day and
|
||||||
|
# the value being a tuple with the averages
|
||||||
|
_averages = {}
|
||||||
|
|
||||||
# Pull some useful data and have the module render a template
|
# Pull some useful data and have the module render a template
|
||||||
# The output is in MODULENAME_DAYday.html
|
# The output is in MODULENAME_DAYday.html
|
||||||
# This generates a report for each of the given day windows
|
# This generates a report for each of the given day windows
|
||||||
@ -66,8 +106,11 @@ def main(module):
|
|||||||
data = sqlite_run(run, db=args.db_location, return_output=True)
|
data = sqlite_run(run, db=args.db_location, return_output=True)
|
||||||
log.debug(data)
|
log.debug(data)
|
||||||
|
|
||||||
# Render the template
|
# Render the template, which also returns the average values
|
||||||
module.render_template(day, data)
|
_averages[day] = module.render_template(day, data)
|
||||||
|
|
||||||
|
# Put the values from _averages on the summary page
|
||||||
|
summary_page[module.name] = _averages
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -88,6 +131,12 @@ if __name__ == "__main__":
|
|||||||
log.basicConfig(format="%(asctime)s\t%(levelname)s\t%(message)s",
|
log.basicConfig(format="%(asctime)s\t%(levelname)s\t%(message)s",
|
||||||
level=num_level)
|
level=num_level)
|
||||||
|
|
||||||
|
# Initialize a dict to store data for the summary page
|
||||||
|
summary_page = {}
|
||||||
|
|
||||||
for module in ENABLED_MODULES:
|
for module in ENABLED_MODULES:
|
||||||
log.info("Working on %s..." % module.__name__)
|
log.info("Working on %s..." % module.__name__)
|
||||||
main(module)
|
main(module)
|
||||||
|
|
||||||
|
# Render the summary page
|
||||||
|
summary()
|
||||||
|
@ -29,6 +29,9 @@ requests_cache.install_cache("jenkins", backend="sqlite", expire_after=300)
|
|||||||
class JenkinsModule:
|
class JenkinsModule:
|
||||||
"""Jenkins module for the Metrics program"""
|
"""Jenkins module for the Metrics program"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.name = "Jenkins"
|
||||||
|
|
||||||
def _auth_jenkins_server(self):
|
def _auth_jenkins_server(self):
|
||||||
"""Authenticate to the Jenkins server
|
"""Authenticate to the Jenkins server
|
||||||
|
|
||||||
@ -187,3 +190,6 @@ class JenkinsModule:
|
|||||||
with open(path.join("output", "jenkins_%sdays.html" % days),
|
with open(path.join("output", "jenkins_%sdays.html" % days),
|
||||||
"w+") as f:
|
"w+") as f:
|
||||||
f.write(template)
|
f.write(template)
|
||||||
|
|
||||||
|
# Return the averages for use in the summary
|
||||||
|
return (average["nonpassing"], average["failing"], average["total"])
|
||||||
|
49
templates/index.html
Normal file
49
templates/index.html
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<!-- HTML5 compliance -->
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<!-- Import Bootstrap 4.3.1 -->
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col" style="text-align: center;">
|
||||||
|
<h1>Summary for Lubuntu Project Metrics</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col" style="text-align: center;">
|
||||||
|
<h2>Jenkins Data</h2>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Time (days)</th>
|
||||||
|
<th>Average Failing</th>
|
||||||
|
<th>Average Non-passing</th>
|
||||||
|
<th>Average Total</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for day in page.Jenkins %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ day }}</td>
|
||||||
|
{% for avg in page.Jenkins[day] %}
|
||||||
|
<td>{{ avg }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user