Check a workbook

The ghfdb check command compares a filled-in upload template workbook with the field schema and the published vocabularies, and writes what it found to a report beside the workbook. The report also gives every child its preview scores under the quality scheme. This page describes the command, the report it writes and each kind of problem. The workbook is read and never changed.

Command

ghfdb check <workbook>

Argument

Meaning

workbook

The path of an .xlsx or .xlsm file with a sheet named data list.

The command writes <name>.report.html in the folder of the workbook, replacing a report from an earlier check, and prints one line on standard output:

212 children, 37 problems in 14 of them, report: /data/my-data.report.html

The first time it runs, the command downloads the vocabularies and keeps them in the user’s cache directory. Later checks use the cache and need no network connection.

The exit status says what happened.

Status

Meaning

0

The check ran and found no problem.

1

The check ran and found at least one problem.

2

The check could not run, and the reason is on standard error. The workbook is not a workbook or has no data list sheet or header row, the report cannot be written, the vocabularies are neither cached nor downloadable, or a rule names a concept the vocabularies no longer publish (the message names the rule).

ghfdb.cli.main runs the command from Python and returns the status. ghfdb.cli.run is the entry point the ghfdb command calls, and exits with that status.

How a check runs

        flowchart TD
    workbook["Workbook"] --> read["Read the data list sheet"]
    read --> columns["Match each column to a field"]
    columns --> cells["Check every cell against its field"]
    vocabularies["Published vocabularies"] --> cells
    cells --> rules["Check the cross-field rules"]
    columns --> layout["List the column problems"]
    rules --> scores["Score every child, leaving out the cells with a problem"]
    scores --> report["Write the HTML report beside the workbook"]
    layout --> report
    report --> status["Print one line and give a status"]
    

The report

ghfdb.qc.report.Report writes the report as one web page that opens in any browser. The page holds a summary, a table of the problems and a table of the preview scores, and no copy of the data. Its styles are in the page, and it has no script and no link to another file. It is written to a temporary file in the workbook’s folder and moved over the earlier report, so a check that fails leaves the earlier report whole.

The problems table

One row for each problem. Problems of the workbook’s columns come first, and the rest follow in order of row and then of the field’s place in the schema. The problems of the rules follow the field problems of their row. Dataset.check gives the same table, with the columns named row, code, column_name, kind, value, suggestion, rule and related.

Column

Contents

Excel row

The row of the child in the workbook. Empty for a problem of the columns.

Field code

The code of the field, such as P1. Empty for an unknown column.

Published column name

The name the field’s column has in the upload template. For an unknown column, its header.

Kind

The kind of problem (see below).

Value

The cell as it was found, written as text. The page shows markup in a value as text and never runs it.

Suggestion

The closest allowed term, for a value that is not in the vocabulary and is like one.

Rule

For a rule problem, the identifier of the broken rule, such as CF-1, linked to the rule in the latest published reference, with the rule’s statement. Empty for every other kind.

Related

For a rule problem, the field that made the rule apply: its code, its published column name and the value found, such as P12 explo_method [Drilling]. Empty for every other kind.

The Preview scores table

One row for each child, after the problems, in the order of the workbook. Every score is a preview: the GHFDB portal recalculates each one, and its value is authoritative. Each heading of a score links to the page of the quality scheme that explains it. Dataset.scores gives the same table.

Column

Contents

Excel row

The row of the child in the workbook.

Rules

The rules that score the child, probe sensing or borehole and mine. Empty when no rules apply.

U-score

The U-score, U1 to U4, or Ux.

T-score

The T-score, a number, from the probe-sensing or borehole and mine rules.

TC-score

The TC-score, a number, from the same rules.

M-score

The M-score, M1 to M4, with an x when information is missing, or Mx.

Perturbation flags

The perturbation flags.

Quality code

The U-score, M-score and flags joined by full stops, as in U2.M3x.-e-PX--.

Has problems

Whether the check found a problem in the child.

A score that could not be determined is an empty cell, never 0. The x on an M-score is the missing-information mark: information the scheme needs was missing, and the child could grade better with it. A child with a problem is still scored, with every cell that has a problem of kind missing, wrong type, out of range, not in vocabulary or rule counted as empty, so fix the problems and check again to see the scores the portal will give. A workbook with no children has the table with no rows, and the report says there is no child to score.

The summary

The summary names the workbook file, the ghfdb version, which made the scores, the time of the check in UTC, the releases of the vocabularies the check read, the number of children, the number of problems, the number of children with problems and a link to the quality scheme. When there is no problem it says so.

Kinds of problem

Kind

Meaning

Example

missing

A field that is mandatory in both domains, borehole and mine (B) and probe sensing (S), is empty.

Row 12 has no value in a mandatory field.

wrong type

A cell is not the field’s type or does not match its pattern. A number stored as text is accepted.

abc in a number field.

out of range

A number is below the minimum or above the maximum, or text is longer than the maximum length.

A latitude of 120.

not in vocabulary

A value is not one of the field’s allowed terms.

granit where granite is allowed, with granite as the suggestion.

rule

A cross-field rule is broken: the fields of one child do not say what the rule requires together. The problem is the field to fill in or to change, and the Rule and Related columns say which rule and why it applies.

An empty field that is mandatory for borehole and mine data only, in a child explored by drilling.

unknown column

A column of the workbook names no field. When its header is close to a published column name, that name is the suggestion.

A column headed Notes, or Ref_ISGN with Ref_IGSN as the suggestion.

no column

The workbook has no column for a field. A mandatory field is also missing on every child.

An upload template with a column deleted.

duplicate column

Two columns name the same field. The first is checked.

Two columns headed P1.

A field that is mandatory in one domain only is not missing when it is empty. It is a rule problem, and only for a child whose exploration method puts it in that domain.

A field that takes several values in a cell, written with a separator, is checked value by value, and the problem names the value.

How long a check takes

A workbook of 90,000 children, the size of the GHFDB, with every field filled, was checked and checked, scored and reported in 11 seconds on the development machine, with the cross-field rules applied and one child in a hundred breaking a rule, once the vocabularies were cached. The test suite fails the check when it takes 15 seconds.

Python API

The report a check writes beside the workbook, a single web page.

class ghfdb.qc.report.Report(workbook_path: Path, problems: DataFrame, children: int, vocabularies: Vocabularies, scores: DataFrame)

The problems a check found and what it was checked against.

The report holds no copy of the data: the problems with the values they were found in, and a summary.

Parameters:
  • workbook_path – The workbook that was checked.

  • problems – One line for each problem, with the columns row, code, column_name, kind, value, suggestion, rule and related. A problem of the workbook’s columns comes first and has no row. A problem of kind rule shows its rule’s identifier, linked to the rule in the latest published reference, with the rule’s statement, and the field that made the rule apply. Other kinds leave both cells empty.

  • children – The number of children checked.

  • vocabularies – The vocabularies the check read, which name the releases the report states.

  • scores – The preview scores of the children, as Dataset.scores returns them, indexed by Excel row. A score not determined is an empty cell.

workbook_path

The workbook.

problems

The problems.

children

The number of children.

vocabularies

The vocabularies.

scores

The preview scores.

build(path: Path) → None

Render the page and write it to a file.

Parameters:

path – The file to write.

static cell(position: int, value: Any) → dict[str, str]

Turn a value of the problem table into a cell of the report.

Parameters:
  • position – The value’s column in the problem table.

  • value – The value, which may be absent.

Returns:

The cell, which links the identifier of a rule to its reference entry.

cells() → list[list[dict[str, str]]]

List the problems as text, an absent value as an empty cell.

Returns:

One list of eight cells for each problem, in the order of the problems. A cell is its text, and for a rule its link to the rule reference and the rule’s statement.

property path: Path

<workbook name>.report.html beside it.

Type:

Where the report is written

score_rows() → list[tuple[str, ...]]

List the preview scores as table rows, one for each child.

Returns:

For each child, in the order of the scores, the text of its cells in the order of SCORE_TABLE: an empty cell for a score not determined, never zero.

summary() → list[tuple[str, str]]

List what the summary states.

Returns:

A label and a value for each line of the summary.

write() → Path

Write the report, replacing an earlier one.

The report is written to a temporary file in the same folder and moved over the earlier report, so a report that cannot be written leaves the earlier one whole.

Returns:

The path of the report.

Raises:

CheckError – The report cannot be written. The message names the report.

class ghfdb.qc.report.ScoreColumn(heading: str, column: str, page: str | None)

A column of the table of preview scores.

heading

The heading the column carries.

Type:

str

column

What the column shows: row for the Excel row, problems for whether the child has problems, any other value a column of Dataset.scores.

Type:

str

page

The page of the scheme reference that explains the column, without its extension, or None for a column the scheme does not define.

Type:

str | None

The ghfdb command.

ghfdb.cli.check(path: Path) → int

Check a workbook and write its report.

Parameters:

path – The workbook.

Returns:

0 when no problem was found, 1 when there are problems.

Raises:
  • CheckError – The workbook cannot be checked or the report cannot be written.

  • MissingSchemeError – A vocabulary a field names is not defined where it is published.

  • OSError – The vocabularies are not cached and cannot be downloaded.

ghfdb.cli.main(argv: list[str] | None = None) → int

Run the command.

Parameters:

argv – The arguments after the command name. Without them, those the command was run with.

Returns:

0 when no problem was found, 1 when problems were found and 2 when the check could not be run, with the reason on standard error.

Return type:

The exit status

ghfdb.cli.run() → None

Run the command and exit with its status.