How this JSL conversion to base 36 is done in python.
txt = Hex( (Today() - Informat( "01/01/1970", "mm/dd/yyyy" ) - In Hours( 8 )) * 1000 + 600000 + Day( Today() ), base( 36 ) );
a = Today();
b = Informat( "01/01/1970", "mm/dd/yyyy" );
c = In Hours( 8 );
d = Day( Today() );
e = (a - b - c) * 1000 + 600000 + d;
f = Hex( (a - b - c) * 1000 + 600000 + d, base( 36 ) );
I asked ChatGPT several times and the results were inconsistent with the JSL results.Only ask for help from experts who are familiar with both JSL and python.Thank you very much!
Automation and ScriptingWindowsRe: How this JSL conversion to base 36 is done in python.Which part are you having problems with? Building the number to convert? Or the conversion?
Re: How this JSL conversion to base 36 is done in python.Is your understanding of this function in JSL
txt = Hex( (Today() - Informat( "01/01/1970", "mm/dd/yyyy" ) - In Hours( 8 )) * 1000 + 600000 + Day( Today() ), base( 36 ) );
how can you calculate the same result in python
I also don't understand Informat("01/01/1970", "mm/dd/yyyy").So we don't know where ChatGPT's answer is.
It calculates the result of a Token, if the calculation is not correct.POST download is not possible.In fact, python calculations cannot be downloaded.
Thanks!
ChatGPT
import datetime
# Step 1: Current time (China's East 8 time zone)
now = datetime.datetime.now()
# Step 2: Date of January 1, 1970
epoch = datetime.datetime(1970, 1, 1)
# Step 3: Calculate the difference in seconds between the current time and January 1, 1970, and subtract 8 hours
time_diff = (now - epoch).total_seconds() - (8 * 3600)
# Step 4: Convert the time difference to milliseconds, add 600,000, and add today's day of the month
milliseconds = time_diff * 1000
e = milliseconds + 600000 + now.day
# Step 5: Convert the result to a base-36 representation
def to_base36(num):
chars = '0123456789abcdefghijklmnopqrstuvwxyz'
base36 = ''
while num > 0:
num, i = divmod(int(num), 36)
base36 = chars[i] + base36
return base36
# Output the base-36 value
result = to_base36(e)
print("Python calculated result:", result)
# Output the current precise timestamp
print("Current timestamp:", now)Re: How this JSL conversion to base 36 is done in python.If you don't understand the first part, you have to start with that. In Format converts a string to a JMP datenum using specified format/pattern

Which in your case is 2082844800. Also, if you are using JMP, why would you perform the conversion in Python? You can just run JSL in Python using run_jsl
Re: How this JSL conversion to base 36 is done in python.Google search: Python base36
gives the following for base36 conversion including a 2-line solution using numpy.
https://stackoverflow.com/questions/1181919/python-base-36-encoding
One of many search results for Python and base36.
Also understand that Python's Epoch date is 1 Jan 1970. If you are getting JMP's raw date value the Epoch date is 1 Jan 1904. Also, when doing direct time conversions on the seconds, make sure you also account for leap years.
Re: How this JSL conversion to base 36 is done in python.How does this JSL in python pass to python?
I'll just go through the paste board
Thanks!

Re: How this JSL conversion to base 36 is done in python.There is no need to use clipboard to move information between jmp and python in JMP ( suggest you read through https://www.jmp.com/support/help/en/18.0/#page/jmp/python.shtml# ).
import jmp
txt = "initial";
print(txt);
jmp.run_jsl("""
txt = "hello world";
Python Send(txt);
""")
print(txt);

Re: How this JSL conversion to base 36 is done in python.I an not

Re: How this JSL conversion to base 36 is done in python.The fundamental issue you are missing is that the JSL environment and the Python Environment have different variable scopes. Within JSL, names go into the global namespace when Names Default To Here(0); or not specified. They are in the 'here' namespace when Names Default To Here(1); or they are within a particular namespace if you choose to create another namespace via JSL. Further special things like :age are checked if they are column references of the current data table. This is on the JSL side of the boundary. On the Python side, variables created in Python wind up in the Python dictionary of the appropriate scope. In the globals() dictionary for the body of the script. Each module, function, ... has its own local dictionary. Python and JSL do not automatically share the variables with one another. This requires an action on your part to 'send' a JSL variable to the Python environment or 'get' a Python value back into the JSL environment. For that purpose Python Send( v ) takes the JSL value v and creates a Python variable named v with a copy of the value of v. A few special types like data tables and matrices are passed as a reference to the actual object instead of a copy. But most values come across as a copy. jV = Python Get( pV ) ; Looks up the pV variable in the Python environment and copies the value to the JSL variable jV.
As @jthi mentioned there is plenty of JMP documentation that talks about this functionality. The send() / get() capability has been fundamental with the Python Integration beginning with JMP 14. Please spend time exploring our documentation and sample scripts. The Scripting Index found from the Help menu is builtin JMP documentation for JSL and Python. Within the Scripting Index, 'All Categories' shows everything, with a search field next to it. Search of Python will quickly show all the JSL Python functionality with descriptions and runnable samples. If you chose the 'Python' category, it filters to show all the new JMP 18+ functionality supported from the Python environment. Here you will find descriptions and runnable examples showing the functionality of the JMP 18+ Python side of the integration. Lastly, from the Python environment, doc strings have been utilized so you can use Python's builtin help functionality. help( jmp.DataTable ) for example



As you have found, the flexibility of Python packages allows you create your own ways of passing data. Spending time with our documentation and samples provided. Play with them and learning how they function, will go a long way to clearing up how to best utilize JMP's Python integration.
As an aside, using Chat GPT or other AI tools to write code is only truly useful if you know how the code is supposed to work. It's just like trusting a website article, you need to know enough of how things work ( Python, JSL, ... ) to have an idea of whether the code you get is accurate, almost working, gets the concepts right, or just complete disinformation. Finally, AI knowledge of the current JMP 18+ Python integration is likely to be a lot smaller than information on JMP 14-17 simply due to the newness of JMP 18. I am confident that the best source of information is our documentation, our Scripting Index and the included $SAMPLE_SCRIPTS directories.
Re: How this JSL conversion to base 36 is done in python.Thank Paul!

Re: How this JSL conversion to base 36 is done in python.Thanks Experts!
OK

Re: How this JSL conversion to base 36 is done in python.I have two questions for the experts:
1. How to concatenate two JMP tables in python?
2, how can the following python be modified to python asyncio asynchronous execution form?
Thanks Experts!
import jmputils
import jmp
from datetime import datetime, timedelta
today = datetime.today()
dates = []
for i in range(200):
dates.append((today - timedelta(days=i)).strftime('%Y%m%d'))
j = 0
for date in dates:
#print(date)
j += 1
jmp.run_jsl('''
b=Python Get(date);
d1=New Table("o",Add Rows(1),New Column("date",Set Values({b})));
Python Send(d1)
''')
#print(d1)
jmp.run_jsl('''
j=Python Get(j);
//b=Python Get(d1);
if(j==1,d2=d1;d2<<SETNAME></SETNAME>I still don't have an answer.Looking forward to expert help.
Re: How this JSL conversion to base 36 is done in python.I asked ChatGPT several times, and python's asyncio framework is written like this
But the execution is always unsuccessful.
Ask for expert help in your community.
Thanks!
import asyncio
import concurrent.futures
import jmp
# Define a global variable kk
kk = 1
# Create an asynchronous function to run the JSL script
async def run_jsl_script():
global kk
loop = asyncio.get_event_loop()
# Simplified JSL script
jsl_script = f'''
Print("Value of kk: {kk}");
b = Python Get({kk});
Print("Value of b: ", b);
d1 = New Table("o", Add Rows(1), New Column("date", Set Values({{b}})));
if (b == 1,
d2 = d1;
d2 << Set Name("Name 2");
Print("Table d1 copied to d2 with new name.");
,
current data table(d2);
d2 << Concatenate(Data Table(d1), Append to first table);
Close(d1, nosave);
);
Python Send(d1);
'''
# Print the JSL script content for debugging
print("JSL script to be executed:")
print(jsl_script)
try:
# Use a thread pool to run the synchronous JSL script
with concurrent.futures.ThreadPoolExecutor() as pool:
# Call jmp.run_jsl function
await loop.run_in_executor(pool, lambda: jmp.run_jsl(jsl_script))
except Exception as e:
print(f"Error occurred: {e}")
# Update the kk variable
kk += 1
print(f"Current value of kk: {kk}")
# Main asynchronous function
async def main():
# Example of running the JSL script multiple times
for _ in range(3): # For example, run three times
await run_jsl_script()
print("All JSL scripts executed.")
# Run the main function
if __name__ == "__main__":
asyncio.run(main())