labqc.report¶
Records and reports: keep what was calculated, with what, by which version, and when.
A RunRecord holds one calculation: the labqc function, its inputs and settings, the result, a short description of the method, the labqc version, a UTC timestamp and optionally the analyst. Records round-trip through JSON, so a saved budget can be reloaded later, and can be written to Excel (one sheet per record) or to a one-page PDF.
Excel and PDF output need the [reports] extra: pip install "labqc[reports]".
RunRecord
dataclass
¶
One calculation, kept as a record.
function: the labqc function that made the result, e.g. "labqc.uncertainty.combine". inputs, settings, result: plain dictionaries (numbers, strings, lists, and lists of row dicts for tables). method: one or two sentences naming the formula or standard.
Source code in src/labqc/report.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
to_json ¶
to_json() -> str
The record as indented JSON (UTF-8 text, keys in a fixed order).
Source code in src/labqc/report.py
95 96 97 | |
from_json
classmethod
¶
from_json(text: str | bytes) -> RunRecord
Read a record saved with to_json. Raises ValueError for anything else.
Source code in src/labqc/report.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
plain ¶
plain(value: Any) -> Any
Turn numpy, pandas and float edge cases into plain JSON values.
Infinity becomes the string "inf" (JSON has no infinity), NaN becomes None, DataFrames become lists of row dicts and tuples become lists.
Source code in src/labqc/report.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
record_budget ¶
record_budget(components: Sequence[Component], result: Result, coverage: float | None = None, fixed_k: float | None = None, unit: str = '', title: str = 'Uncertainty budget', analyst: str | None = None, correlation: Mapping[tuple[str, str], float] | None = None) -> RunRecord
Record a budget made with combine (or propagate) so it can be reported and reloaded.
correlation is the one passed to combine; it is stored as [name, name, r] rows.
Source code in src/labqc/report.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
budget_from_record ¶
budget_from_record(record: RunRecord) -> tuple[pd.DataFrame, dict[str, Any]]
The components table and settings of a recorded budget, ready for combine again.
Returns (table with the columns of components_from_table, dict with value, unit,
coverage, fixed_k and correlation, a {(name, name): r} dict or None). Raises ValueError
if the record is not an uncertainty budget.
Source code in src/labqc/report.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
to_excel ¶
to_excel(records: Sequence[RunRecord], path: PathOrFile) -> None
Write records to an .xlsx workbook, one sheet per record (needs openpyxl).
Source code in src/labqc/report.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
to_pdf ¶
to_pdf(record: RunRecord, path: PathOrFile) -> None
Write one record as a PDF: title, meta data, method, inputs, result (needs reportlab).
Source code in src/labqc/report.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |