Skip to content

Instantly share code, notes, and snippets.

@jonseymour
Last active January 31, 2022 10:48
Show Gist options
  • Save jonseymour/41e01c0bedb1bd23f23ed64da6b1d07a to your computer and use it in GitHub Desktop.
Save jonseymour/41e01c0bedb1bd23f23ed64da6b1d07a to your computer and use it in GitHub Desktop.
AEMO NMI checksum calculator
from itertools import chain
# Calculates the AEMO NMI checksum according to:
#
# https://www.aemo.com.au/Electricity/National-Electricity-Market-NEM/Retail-and-metering/-/media/EBA9363B984841079712B3AAD374A859.ashx
#
# Always calculates the checksum with the 10 left-most digits if supplied with
# a 10 or 11 character string. Unspecified results occur for inputs of other lengths.
#
def generate(nmi):
if len(nmi) > 10:
nmi=nmi[0:10]
ascii = chain(map(lambda x : ord(x)*2, nmi[-1::-2]), map(lambda x : ord(x), nmi[-2::-2]))
ascii_digits=''.join(map(lambda x: str(x), ascii))
digits = map(lambda x : ord(x) - ord('0'), ascii_digits)
reduction = sum(digits)
return nmi+str(((10-(reduction % 10))%10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment