Last active
January 31, 2022 10:48
-
-
Save jonseymour/41e01c0bedb1bd23f23ed64da6b1d07a to your computer and use it in GitHub Desktop.
AEMO NMI checksum calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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