cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
New to using JMP? Hit the ground running with the Early User Edition of Discovery Summit. Register now, free of charge.
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
lala
Level VII

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!

12 REPLIES 12
jthi
Super User

Re: 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?

-Jarmo
lala
Level VII

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)
jthi
Super User

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

jthi_0-1725635158322.png

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

-Jarmo
lala
Level VII

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!

2024-09-07_14-43-44.png

jthi
Super User

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);

jthi_0-1725715446331.png

 

-Jarmo
lala
Level VII

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

I an not 

2024-09-07_21-50-57.png

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

Paul_Nelson_0-1725722269962.pngPaul_Nelson_1-1725722313890.png

Paul_Nelson_2-1725723439163.png

 

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. 

lala
Level VII

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

Thank  Paul!

2024-09-08_07-56-25.png

lala
Level VII

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

Thanks Experts!

OK

2024-09-08_09-10-34.png