OCPI tariffs CLI
This crate provides a binary for doing calculations with
OCPI
tariffs.
Specifically for the OCPI 2.2.1 and
OCPI 2.1.1 version.
Installation
First install Rust and then install the OCPI tariffs command line tool:
cargo install ocpi-tariffs-cli
Usage
The binary is executed as ocpi-tariffs. Every subcommand takes
-o, --ocpi-version, which is required and accepts v221 or v211.
guess-version is the exception, since working out the version is its job.
Every subcommand reads its JSON from the path given by -f, --file (-c, --cdr for price),
and from standard input when that path is omitted, so the tool composes in a pipeline.
Run ocpi-tariffs --help for the list of subcommands, or ocpi-tariffs <subcommand> --help
for the options of one.
Subcommands
price
Price a charge detail record (CDR) against a tariff and print a breakdown of the calculated costs, period by period, alongside the totals the CDR itself carries so the two can be compared.
The tariff comes from -t, --tariff if given. Otherwise it is taken from the CDR, which may
embed several, in which case the first valid one is used. A tariff is valid for a session when
it starts before the session does and ends after the session starts.
Local times in a tariff are evaluated in the zone given by -z, --timezone. If you omit the
tariff the timezone is found or inferred from the CDR.
ocpi-tariffs price --ocpi-version v221 --cdr cdr.json --tariff tariff.json
explain
Describe in human language what a tariff charges and under which conditions. The explanation goes to standard output so it can be piped or redirected; status messages and warnings go to standard error.
-l, --language selects the language: en-US for English or nl-NL for Dutch. --pretty
prints the source tariff JSON before the explanation.
ocpi-tariffs explain --ocpi-version v221 --language nl-NL --file tariff.json
lint
Report the problems a tariff can have while still being valid against the OCPI schema: a
restriction that can never match, a price bound the wrong way round, a day_of_week list
covering the whole week. --pretty prints the tariff JSON alongside the warnings.
ocpi-tariffs lint --ocpi-version v221 --file tariff.json
guess-version
Work out whether a JSON document is OCPI 2.1.1 or 2.2.1. Takes -t, --type with cdr or
tariff to say which kind of object it is, and takes no --ocpi-version. Pass --validate to
also check the document's fields against the spec for the version it settles on.
ocpi-tariffs guess-version --type cdr --file cdr.json --validate