Expand description
CSV/TSV connectivity (Phase A, post-v0.5.0 plan): import a CSV/TSV file into
an Improv Model, and export a measure’s cells back to CSV/TSV (an input
measure’s stored cells, or a derived measure’s engine-computed ones).
Mirrors improv_storage_sql’s shape (see its module docs): a column→model
mapping (dimension columns → categories/items, one value column → a
measure) turns external tabular data into ordinary input cells. CSV has no
live “refresh” concept (no persistent connection to re-query) — import is a
one-shot static load; re-running it against a changed file re-populates the
measure the same way a fresh import_csv call would.
- Storage separation. CSV is a data source/sink only; the canonical model lives in Mentat. Import produces ordinary categories/items/measures/ input cells — the engine gains no CSV-specific path.
- Testability. Every file-based entry point (
import_csv,export_measure_csv) has anio::Read/io::Writesibling (import_csv_from,export_measure_csv_to) so tests exercise the real logic against an in-memory buffer, no tempfiles required.
Structs§
- Dimension
Mapping - A CSV/TSV column that becomes a category: its distinct values become items.
- Export
Spec - Export options for
export_measure_csv_with. - Import
Spec - How to map a CSV/TSV file’s columns onto model elements. Each
dimensionsentry names a column that becomes a category;value_columnnames the column that becomes the imported measure’s value. A row therefore contributes one input cell:measure[dim=val, …] = value_column.
Enums§
- Column
Ref - A column reference: either a header name (requires
has_header) or a 0-based column index. Supporting both lets headerless files work too. - CsvError
Constants§
- DEFAULT_
MAX_ RECORDS - Record cap applied when
ImportSpec::max_recordsisNone. - MAX_
FIELD_ BYTES - Longest field accepted on import, in bytes (1 MiB).
- MAX_
RECORD_ BYTES - Longest record accepted on import, in bytes. Enforced while reading, so a file with one enormous field errors instead of being buffered whole.
Functions§
- export_
measure_ csv - Write a measure’s cells to a CSV/TSV file: one column per dimension
category (item name) plus a value column, header row first. An input
measure exports its stored cells; a derived measure is evaluated by the
engine and exports its computed cells (IMPROV.txt:113 — export the computed
view). Returns the number of rows written. See
export_measure_csv_tofor the writer-based (testable) version. - export_
measure_ csv_ to - Write a measure’s cells to
writeras CSV/TSV (delimiter). Rows are written in coordinate order, so output is deterministic. - export_
measure_ csv_ with export_measure_csv_towith explicitExportSpecoptions.- import_
csv - Import a CSV/TSV file into
modelperspec. Returns the number of cells imported. Seeimport_csv_fromfor the reader-based (testable) version. - import_
csv_ from - Import CSV/TSV data read from
readerintomodelperspec(spec.pathis ignored). Distinct dimension-column values become items, interned by name — an item is reused when one already exists with that name in the target category. Returns the number of cells imported.