-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #805 from qiboteam/dataclass_web_report
Simplifying plot generation
- Loading branch information
Showing
11 changed files
with
136 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import os | ||
import pathlib | ||
from dataclasses import dataclass | ||
from typing import Callable | ||
|
||
from jinja2 import Environment, FileSystemLoader | ||
|
||
from qibocal import __version__ | ||
from qibocal.cli.report import ReportBuilder | ||
from qibocal.auto.history import History | ||
from qibocal.auto.task import TaskId | ||
|
||
WEB_DIR = pathlib.Path(__file__).parent | ||
STYLES = WEB_DIR / "static" / "styles.css" | ||
TEMPLATES = WEB_DIR / "templates" | ||
|
||
|
||
def create_report(path, report: ReportBuilder): | ||
"""Creates an HTML report for the data in the given path.""" | ||
with open(STYLES) as file: | ||
css_styles = f"<style>\n{file.read()}\n</style>" | ||
@dataclass | ||
class Report: | ||
"""Report generation class.""" | ||
|
||
path: pathlib.Path | ||
"""Path with calibration data.""" | ||
targets: list | ||
"""Global targets.""" | ||
history: History | ||
"""History of protocols.""" | ||
meta: dict | ||
"""Meta data.""" | ||
plotter: Callable | ||
"""Plotting function to generate html.""" | ||
|
||
env = Environment(loader=FileSystemLoader(TEMPLATES)) | ||
template = env.get_template("template.html") | ||
html = template.render( | ||
is_static=True, | ||
css_styles=css_styles, | ||
version=__version__, | ||
report=report, | ||
) | ||
@staticmethod | ||
def routine_name(routine): | ||
"""Prettify routine's name for report headers.""" | ||
return routine.title() | ||
|
||
with open(os.path.join(path, "index.html"), "w") as file: | ||
file.write(html) | ||
def routine_targets(self, task_id: TaskId): | ||
"""Get local targets parameter from Task if available otherwise use global one.""" | ||
local_targets = self.history[task_id].task.targets | ||
return local_targets if len(local_targets) > 0 else self.targets |
Oops, something went wrong.