Michael_Lowry

Convert between task run ID & job report ID

Discussion created by Michael_Lowry on Jun 27, 2016
Latest reply on Jul 1, 2016 by Michael_Lowry

Recently I did some investigation into the relationship between task run IDs and job report IDs. I discovered the following:

  • A task run ID is represented in the Automation Engine by a 31 bit integer (between 1 and 2147483647).
  • A job report ID is the base-26 representation of a task run ID. The letter A represents the numeral 0;B, 1; and so on up to Z, which represents the numeral 25. The job report ID is padded with leading zeros (As) to bring the total number of digits to 7. Represented in this way, a job report ID can be any base-26 number between AAAAAAB and GYTISYX.
  • Neither RUNNR2ALPHA nor ALPHA2RUNNRperforms range checking. Both return a meaningless result if provided input values exceeding 31 bits. (Because task IDs beyond 31 bits cannot exist,2147483647 is the highest decimal run ID, and GYTISYX the highest alphabetic job report ID, for which these commands will return a meaningful result.)
  • Gytis is a masculine Lithuanian given name.

I wrote a couple of scripts to convert between task run ID and job report ID. This makes it possible to do these conversions without relying on AE scripting. I also added some basic range checking.

runnr2alpha.py

import sys
numargs = len(sys.argv)
if len(sys.argv) < 2:
sys.exit("Too few arguments")
elif len(sys.argv) > 2:
sys.exit("Too many arguments")

runid = int(sys.argv[1])
if runid > 2147483647:
sys.exit("Run ID exceeds maximum 2147483647 (2^31 - 1).")
elif runid < 0:
sys.exit("Run ID may not be negative.")

def int_to_str(n, b, symbols='ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
return (int_to_str(n/b, b, symbols) if n >= b else "") + symbols[n%b]

def int_to_lstr(n):
i = int_to_str(int(n), 26)
while(len(i) < 7):
i = 'A' + i
return i

jobid = int_to_lstr(runid)
print jobid

alpha2runnr.py

import sys
numargs = len(sys.argv)
if len(sys.argv) < 2:
sys.exit("Too few arguments")
elif len(sys.argv) > 2:
sys.exit("Too many arguments")

jobid = sys.argv[1]
if len(jobid) != 7:
sys.exit("Job ID must be exactly 7 characters.")

alpha = set('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
if not set(jobid).issubset(alpha):
sys.exit("Job ID may contain only alphabetic characters.")

jobid = jobid.upper()

def str_to_int(s, b, symbols='ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
r = s[::-1]
d = 0
j = 0
for c in r:
d = (symbols.index(c) * pow(b,j)) + d
j += 1
return d

def str_to_int_add(s):
i = str_to_int(s, 26)
if i > 2147483647:
sys.exit("GYTISYX is the highest possible alphabetic job report ID.")
return i

runid = str_to_int_add(jobid)
print runid

 

Enjoy!

Thanks to N. C. for her help with the original script.

Outcomes