pulsatrix 1.1.0
Loading...
Searching...
No Matches
report.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <string>
8#include <utility>
9#include <vector>
10
13
14namespace pulsatrix {
15
41class Report {
42public:
43 explicit Report(std::string title = "");
44
46 Report& markdown(std::string text);
48 Report& code(std::string source);
53 template <class T>
54 Report& show(const T& value) {
55 return output(mime_bundle_repr(value));
56 }
58 Report& text(std::string text);
59
60 [[nodiscard]] const std::string& title() const { return title_; }
61 [[nodiscard]] size_t num_cells() const { return cells_.size(); }
62
65 [[nodiscard]] std::string to_ipynb() const;
73 [[nodiscard]] std::string to_html(const HtmlOptions& options = {}) const;
74
76 void save_ipynb(const std::string& path) const;
78 void save_html(const std::string& path, const HtmlOptions& options = {}) const;
79
80private:
81 struct Output {
82 bool is_text = false;
83 std::string text;
84 MimeBundle bundle;
85 };
86 struct Cell {
87 enum class Kind { Markdown, Code } kind;
88 std::string source;
89 bool hidden_source = false;
90 std::vector<Output> outputs;
91 };
92 Cell& output_cell();
93
94 std::string title_;
95 std::vector<Cell> cells_;
96};
97
99[[nodiscard]] std::string MarkdownToHtml(const std::string& markdown);
100
101} // namespace pulsatrix
A document of markdown, code and rich outputs, written as a Jupyter notebook (nbformat 4....
Definition report.hpp:41
const std::string & title() const
Definition report.hpp:60
std::string to_ipynb() const
The notebook as nbformat 4.5 JSON. Its kernel spec is xeus-cpp's C++17 kernel, so the code cells run ...
Report & show(const T &value)
output(mime_bundle_repr(value)).
Definition report.hpp:54
Report(std::string title="")
Report & markdown(std::string text)
A markdown cell.
Report & output(MimeBundle bundle)
A rich output: attached to the last cell if it is a code cell, otherwise in a code cell of its own.
void save_html(const std::string &path, const HtmlOptions &options={}) const
std::string to_html(const HtmlOptions &options={}) const
One HTML page. Vega-Lite charts load Vega from the CDN (pinned, with integrity hashes) or,...
Report & text(std::string text)
A plain-text output (a stream output on stdout in the notebook).
void save_ipynb(const std::string &path) const
Report & code(std::string source)
A code cell showing source as C++ (not run).
size_t num_cells() const
Definition report.hpp:61
Self-contained HTML views of the viz documents (VIZ-3): interactive Vega-Lite charts with tooltips,...
Rich notebook display: mime_bundle_repr() for pulsatrix's types (roadmap NB-1).
Definition acquisition_functions.hpp:16
MimeBundle mime_bundle_repr(const Tensor &tensor)
@ Output
What the model's output is and means: its schema, labels and scope.
std::string MarkdownToHtml(const std::string &markdown)
Markdown (the subset Report::to_html() supports) as HTML; raw HTML is escaped.
Options for every HTML view.
Definition html.hpp:36
One displayable value in several formats: MIME type to data, richest first. Text formats (text/plain,...
Definition mime_bundle.hpp:35