Skip to content

hertzforge.core.run_log_extract

run_log_extract

A run log brought into a project: one test, frozen at a stated entry.

A report holds references to project objects, never data that can move under it, and a run log keeps growing while the test runs. So a log is not referenced from a project; it is brought in as a snapshot, the way Photos brings image files in. take reads one test of a .hflog up to a stated entry and keeps the lines of the file that test's views read, exactly as written: the log's header, every entry of the test's chain and of the chain between tests up to that entry, and the few entries written elsewhere that answer something in the test (the next test's opening, which closes it to runs; a cause, path, restart or deviation that names one of its entries; a disposition of one of its anomalies), each with its corrections.

RunLogExtract reads that snapshot as RunLogModel reads a log, so its views (runs, interruptions, credited duration, findings, files, chronology, holds, owed lists) are what the model gave for the test at that entry, and nothing the file gains afterwards changes them. The extract keeps the test's head hash, which the report's data index can carry beside the log's other files. RunLogExtract.status compares the live file with the snapshot: when the file has grown it says how many newer entries the log holds, and a missing or changed file is said in words, never raised.

Refusals. take refuses a file that is not a run log, a test the log does not hold at the stated entry, an entry the log does not hold, a chain of the test (or between tests) that does not verify, an entry before the cut that the log cannot read, and, when no entry is stated, a last line still torn (an entry being written). A line that is not an entry at all (the fragment a crash leaves, ended by the next writer) is skipped as the log itself skips it, and named in problems, since the chain checks across it.

Drafts. The text an extract offers a report's author sections (draft_chronology, draft_findings) is a Draft, marked as drafted: it is offered, never placed, and the section stays owed until the author accepts or edits it. Only the fact of a deviation or anomaly is offered; its cause, effect and approval or disposition are the author's. A log with nothing of a kind offers nothing for it rather than "none", since an empty log cannot tell "nothing happened" from "nobody wrote it down".

Classes:

Name Description
LogStatus

What the live log file says against an extract: its state (one of

Draft

Text the run log offers one of a report's author sections.

RunLogExtract

One test of a run log, frozen at a stated entry, held in a project.

Functions:

Name Description
held

The run log extracts among objects (a project, or any mapping of

take

One test of the run log at path, frozen at entry upto.

stored_path

The log's path as a project file stores it: relative to the

resolved_path

A stored log path made absolute against the project file it was

Classes

LogStatus dataclass

LogStatus(state: str, newer: int, newer_in_test: int, message: str)

What the live log file says against an extract: its state (one of STATES), how many entries it holds after the extract's last entry (newer) and how many of those are of the extract's test (newer_in_test), and the state in words.

Attributes:

Name Type Description
badge str

The short words a badge shows: '' when the extract is

Attributes
badge property
badge: str

The short words a badge shows: '' when the extract is current.

Draft dataclass

Draft(section: str, text: str, source: str, notes: tuple[str, ...] = (), mark: str = DRAFTED)

Text the run log offers one of a report's author sections.

section is the skeleton section it is offered to, text the draft in the report's Markdown ('' when the log has nothing to offer), source which log, test and entry it was drafted from, notes what the author should know that the text does not say, and mark what it is shown with until the author accepts or edits it. A draft never fills a section: it is offered beside it, and the section stays owed until it is accepted. False when there is no text.

RunLogExtract

RunLogExtract(text: str, *, path: str, test: int, upto: int, taken: datetime | str, log_size: int, after: int = 0, after_in_test: int = 0, problems: Sequence[str] = ())

One test of a run log, frozen at a stated entry, held in a project.

Made by take (or Project.attach_run_log), and saved in the project file whole, so it reads the same wherever the project is opened, with or without the log beside it. Its views are the RunLogModel views of its test, read from the snapshot.

Parameters:

Name Type Description Default
text str

The snapshot: the log's header line and the lines of the entries kept, as JSON Lines.

required
path str

Where the log was, absolute (or as stored, when the project file it was resolved against is not known).

required
test int

The test.

required
upto int

The id of the last entry of the log the extract was taken to.

required
taken datetime or str

When it was taken, with its zone (ISO 8601 text as stored).

required
log_size int

The log file's size in bytes when it was taken.

required
after int

How many entries the file held after upto when it was taken, and how many of those were of the test.

0
after_in_test int

How many entries the file held after upto when it was taken, and how many of those were of the test.

0
problems sequence of str

The lines of the log before upto that were skipped as not entries.

()

Raises:

Type Description
RunLogError

When text is not a run log, does not hold the test, or holds an entry past upto.

Methods:

Name Description
verify

Check the snapshot's chains (the test's and the one between

runs

The test's runs (RunLogModel.runs).

interruptions

The test's aborts, trips and scheduled stops, with the cause,

credited

The time credited on each axis against the duration and its

findings

The test's deviations and anomalies by number, with the

open_anomalies

The test's anomalies with no disposition, with their owners.

files

Every file the test's entries name, by SHA-256

chronology

The test's entries in the order of their events, each with its

holds

The test's holds still unanswered at the extract's last

owed

The test's owed lists with a line still owed at the extract's

late

The test's entries written down late.

status

The live log against the extract.

cited

Which log, test and entry the extract holds, as a report cites

draft_chronology

The test's chronology from the log, as draft text for the

interruption_lines

The test's interruptions as a Markdown table: the entry, its

credit_lines

The time credited on each axis of the test against the

draft_findings

The test's deviations and anomalies from the log, as draft text

Attributes:

Name Type Description
log_id str

The log's id, from its header: the same log wherever it is.

log_title str

The log's title (the article or program it is kept for).

head str

The head of the test's chain at the extract's last entry: the

info Test

The test as the snapshot holds it: kind, state, header, axes,

kind str

The test's kind (run_log_model.TEST_KINDS).

title str

The test's title, from its header.

state str

The test's state at the extract's last entry: 'open', 'closed

header TestHeader

The test's header as it stood at the extract's last entry.

entries tuple[Entry, ...]

The test's entries, corrected, in the order written.

Attributes
log_id property
log_id: str

The log's id, from its header: the same log wherever it is.

log_title property
log_title: str

The log's title (the article or program it is kept for).

head property
head: str

The head of the test's chain at the extract's last entry: the hash of the test's last entry by then. A report's data index carries it, so the record outside the log anchors the record inside it (RunLog.verify(heads=...)).

info property
info: Test

The test as the snapshot holds it: kind, state, header, axes, runs and entries.

kind property
kind: str

The test's kind (run_log_model.TEST_KINDS).

title property
title: str

The test's title, from its header.

state property
state: str

The test's state at the extract's last entry: 'open', 'closed to runs' or 'released'.

header property
header: TestHeader

The test's header as it stood at the extract's last entry.

entries property
entries: tuple[Entry, ...]

The test's entries, corrected, in the order written.

Methods:
verify
verify() -> Verification

Check the snapshot's chains (the test's and the one between tests), as RunLog.verify checks a log holding one test.

runs
runs() -> list[Run]

The test's runs (RunLogModel.runs).

interruptions
interruptions() -> list[Interruption]

The test's aborts, trips and scheduled stops, with the cause, path and restart answering each (RunLogModel.interruptions).

credited
credited() -> list[Credit]

The time credited on each axis against the duration and its tolerance (RunLogModel.credited).

findings
findings() -> list[Finding]

The test's deviations and anomalies by number, with the dispositions against each (RunLogModel.findings).

open_anomalies
open_anomalies() -> list[Finding]

The test's anomalies with no disposition, with their owners.

files
files() -> list[FileRow]

Every file the test's entries name, by SHA-256 (RunLogModel.files).

chronology
chronology() -> list[ChronologyRow]

The test's entries in the order of their events, each with its time on the recorders' clock (RunLogModel.chronology).

holds
holds() -> list[Hold]

The test's holds still unanswered at the extract's last entry.

owed
owed() -> list[OwedList]

The test's owed lists with a line still owed at the extract's last entry.

late
late() -> list[Entry]

The test's entries written down late.

status
status(path: str | PathLike | None = None) -> LogStatus

The live log against the extract.

The file's length is compared first; it is read only when its length differs from the length when the extract was taken. It is then 'newer' when it holds entries after the extract's last entry (and they are counted), 'changed' when it is another log or no longer holds the test's head (cut short or edited since), 'unreadable' when it is no longer a run log this build reads, and 'missing' when there is no file. None of these is an error: the extract stands as it was taken.

Parameters:

Name Type Description Default
path str or PathLike

Where to look for the log; the extract's own path when omitted.

None

Returns:

Type Description
LogStatus

The state, the newer entries counted, and the state in words.

cited
cited(status: LogStatus | None = None) -> str

Which log, test and entry the extract holds, as a report cites it, with the badge in brackets when the live log holds newer entries, has changed, cannot be read or is not found: "the run log 'Article 7', test 1, to entry #12 (test head 3f2a...) [newer entries in the log]".

Parameters:

Name Type Description Default
status LogStatus

The live log's state, when it has been asked already; status() is asked when omitted.

None

Returns:

Type Description
str

The citation.

draft_chronology
draft_chronology() -> Draft

The test's chronology from the log, as draft text for the report's Chronology section: its runs in order with their axis, start, what each held, the counter at the stop and the outcome; its interruptions with the cause, path and restart logged; and the time credited on each axis.

Draft text only: it is offered beside the section and marked as drafted (DRAFTED), and the section stays owed until the author accepts or edits it. A test with no runs offers nothing.

Returns:

Type Description
Draft

The draft for section 'chronology'.

interruption_lines
interruption_lines() -> list[str]

The test's interruptions as a Markdown table: the entry, its time (on the recorders' clock where a clock check comes before it), the stop, and the cause, path and restart the log records, each 'not logged' or 'none logged' until it is. No lines when the log holds no interruption of the test, never a line saying there was none.

credit_lines
credit_lines() -> list[str]

The time credited on each axis of the test against the duration and its tolerance, one Markdown list item per axis; no lines when the test has no run.

draft_findings
draft_findings() -> Draft

The test's deviations and anomalies from the log, as draft text for the report's deviations section: each by number with its fact as typed at the console, an anomaly's owner, and whether a disposition is logged.

Only the fact is offered. The cause, the effect and the approval or disposition are the author's, and a log with no findings offers nothing, never "none": the author sets the section to None in one step when that is so.

Returns:

Type Description
Draft

The draft for section 'deviations'.

Functions:

held

held(objects: Mapping[str, Any]) -> list[tuple[str, RunLogExtract]]

The run log extracts among objects (a project, or any mapping of names to objects), as (name, extract), in their order. Empty when there are none, so a report feature that reads a run log changes nothing in a project without one.

take

take(path: str | PathLike, test: int | None = None, upto: int | None = None, *, taken: datetime | None = None) -> RunLogExtract

One test of the run log at path, frozen at entry upto.

Parameters:

Name Type Description Default
path str or PathLike

The run log (.hflog, or an older .vdlog).

required
test int

The test, by number. May be left out when the log holds one test.

None
upto int

The id of the last entry the extract holds, from anywhere in the log; the log's last entry when omitted.

None
taken datetime

When the extract was taken, with its zone; now when omitted.

None

Returns:

Type Description
RunLogExtract

The snapshot.

Raises:

Type Description
FileNotFoundError

When there is no file at path.

RunLogError

When the file is not a run log or holds no entries, the log has no entry upto, or no test test by then (or several tests and test is omitted), an entry before the cut cannot be read, a chain the extract rests on does not verify (the message names the chain, the entry and the line), or, with upto omitted, the last line is torn.

stored_path

stored_path(path: str, project_file: str | None) -> str

The log's path as a project file stores it: relative to the project file's folder, with forward slashes, when the log is in that folder or one beneath it, and absolute otherwise (or when the project file is not known).

Parameters:

Name Type Description Default
path str

The log's path.

required
project_file str or None

The project file the path is stored in.

required

Returns:

Type Description
str

The path to store.

resolved_path

resolved_path(stored: str, project_file: str | None) -> str

A stored log path made absolute against the project file it was stored in; an absolute path, or a relative one with no project file known, is returned as stored.

Parameters:

Name Type Description Default
stored str

The path as the project file stores it.

required
project_file str or None

The project file.

required

Returns:

Type Description
str

The path to look for the log at.