Functional Weave
Code in Python

energy.meter-advance@1.0.0

README.md

1,705 bytes · view raw

# energy.meter-advance

The number of units a meter advanced between two reads: `closing - opening`,
or, when the closing read is lower, `closing + 10^digits - opening`, because
the register rolled over past all nines. A five-digit meter that read 99,950
and now reads 00,020 has advanced 70 units, not minus 99,930.

It is the step every meter-based bill, estimate and water charge starts with,
so `energy.estimate-read`, `energy.bill-calculate` and `energy.water-bill` all
use it rather than each re-deriving the rollover.

## Decisions

- **At most one rollover.** Between two reads a meter can only be known to
  have gone round once; a read history that implies more has a missing read.
- **A lower closing read is always a rollover.** A meter exchange, a
  corrected over-estimate or a meter running backwards all look the same, and
  all of them read as nearly a full turn of the register. Handle an exchange
  as two bills (old meter to its final read, new meter from its first), and
  check large advances before billing them.
- **Whole units only.** Reads are the black digits of the register. The red
  digits (tenths and hundredths on a gas meter) are ignored when reading, as
  the gov.uk guidance says, so they are not part of the input.
- **Reads must fit the register.** 123456 on a five-digit meter is refused,
  since it cannot be a read of that meter. Up to 15 digits, so every count
  stays an exact integer in all three languages.

## Source

Office for Product Safety and Standards, "Gas meter readings and bill
calculation" (https://www.gov.uk/guidance/gas-meter-readings-and-bill-calculation):
reads are the black digits, and units used are the current read less the
previous one.