Exchanges From Spreadsheet

This module provides a tool for converting tabular data in excel to a list of `ExchangeRef`s.

antelope.exchanges_from_spreadsheet module

This module provides a routine that generates a list of exchange refs from a properly formatted spreadsheet

exception antelope.exchanges_from_spreadsheet.ValueIsBalance

Bases: Exception

Used to signal when an exchange is reached that is designated as a balance.

exception antelope.exchanges_from_spreadsheet.TermDictDeprecated

Bases: Exception

Exchanges are allowed to specify terminations, including context, compartment, defaultprovider, activitylinkid, or target. However, the exchanges-from-spreadsheet code is not allowed to apply any interpretation or mapping between the specified terminations and the targets in the foreground. Instead, that mapping should be applied when the exchanges are used to create fragments. The main reason for this is that the signature of the exchange interface does not support term_flow, descend, or other fragment-specific aspects.

antelope.exchanges_from_spreadsheet.exchanges_from_spreadsheet(sheetlike, term_dict=None, node=None, origin=None)

A routine to create a list of flat exchanges (all having the same parent node) from an excel table.

Note that this only creates a sequence of exchange refs with strings as properties, plus an inoperable process_ref for the parent node. These could be used to construct a foreground model but do not by themselves constitute a foreground model.

Requirements for the sheet-like object: XlrdLike / xls_tools
  • name property that returns a string

  • nrows property that reports the number of rows

  • row(index) function that returns an ordered list of entries for the specified index (0-indexed).

  • row(0) returns a header list

  • row(1) is the process’s reference flow

  • subsequent rows are dependent flows

!TODO: support multiple references with is_ref or is_reference field

“entries” in the row() return must be “cell-like”:
  • value property that returns the cell’s value

  • ctype property [not currently used] that corresponds with xlrd.sheet.Cell:

    0=empty, 1=text, 2=number, 3=date, 4=boolean, 5=error, 6=blank (not clear what the difference is between empty and blank)

Columns are interpreted as follows (case-insensitive): Required: ‘flow’, ‘flowref’, ‘flow_ref’, ‘external_ref’ - in that order, used to specify flow ‘direction’, ‘flowdir’ - in that order, used to specify direction w.r.t. parent node ‘value’, ‘amount’ - in that order. This method returns unresolved catalog refs- in order for client code to use them, the flow refs must resolve (bc reference quantity must be known and is not required to be specified)

Optional ‘unit’, ‘units’ - unit of measure for the flow ‘context’, ‘compartment’, ‘defaultprovider’, ‘activitylinkid’, ‘target’ - used to determine the termination of the exchange, default to None

Ignored: ‘process’ - ignored

Any remaining fields are passed to the exchange ref as initialization arguments.

A ‘value’ whose string is lowercase-equivalent to ‘balance’ will add balance=True to the initialization dict and set the value to 0.

Parameters:
  • sheetlike – an Xlrd-like object with name, nrows, and row()

  • term_dict – DEPRECATED. Terminations should be handled in foreground code.

  • node – [None] if present, use as exchange parent node for all exchanges

  • origin – [‘local.spreadsheet’] Should be provided by caller if ‘node’ is omitted, to give identifying information to the created process

Returns: