Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handcalc decoration doesn't allow to render conditional statements #191

Open
danielchaco opened this issue Nov 21, 2023 · 4 comments
Open

Comments

@danielchaco
Copy link

I'm getting an issue when trying to use a decorated function with a conditional.

ParseException: Expected == | = | + | - | * | // | / | % | , | <= | < | >= | > | != term, found end of text (at char 4), (line:1, col:5)

@DonCammne
Copy link

Using a simple example, I don't get any error (just some rendering problems with si.mm):

Cell 1:

from handcalcs.decorator import handcalc
import handcalcs.render
import forallpeople as si
si.environment('structural', top_level=False)


@handcalc(jupyter_display=True)
def computeExample(a, b):
    if a <= 24*si.mm: c = 2*a
    elif a > 24*si.mm: c = a
    
    d = c * b**2
    return d

Cell 2:

%%render params 2

a = 10*si.mm
b = 1*si.m

Cell 3:

d = computeExample(a, b)

If you have an example that gives an error, please share it with us.

@Eastney
Copy link

Eastney commented May 3, 2024

I get the same error when trying conditionals. The most stable i can get is this:

@handcalc(override=str("symbolic"), precision= int(3), left= str("$"), right= str("$"), jupyter_display= True)
def flange_rigidity(flange_type,V,M_o,L,E,g_0,K_I,h_0):
J = (52.14 * V * M_o) / (L * E * (g_0**2) * K_I * h_0)
if J <= 1:
print("Rigidity Criterion is acceptable: J <= 1.0") # per definition, 2-3 Notation
elif J >= 1:
print("Rigidity Criterion is insufficient: J > 1.0") # per definition, 2-3 Notation
return J

It prints the response to the conditional before the latex, which spoils the appearance.
the bit that erks is that i had to switch to decorators to use logs. With %%render the logs don't work.

I must add that, it seems to be the text that causes the problem, because the following works just as expected, latex and all:

@handcalc(override=str("symbolic"), precision= int(3), left= str("$"), right= str("$"), jupyter_display= True)
def factor_f(C_36,A):
f = C_36/(1+A) # Factor f, factor for hub stress
if f <= 1:
return 1 # per definition, 2-3 Notation
elif f >= 1:
return f # per definition, 2-3 Notation

@Eastney
Copy link

Eastney commented May 3, 2024

to get the unstable version of the above, sorry for not including the first time, try this:

@handcalc(override=str("symbolic"), precision= int(3), left= str("$"), right= str("$"), jupyter_display= True)
def flange_rigidity(flange_type,V,M_o,L,E,g_0,K_I,h_0):
J = (52.14 * V * M_o) / (L * E * (g_0**2) * K_I * h_0)
if J <= 1: #
print("Rigidity Criterion is acceptable: J <= 1.0") # per definition, 2-3 Notation
elif J >= 1:
print("Rigidity Criterion is insufficient: J <= 1.0") # per definition, 2-3 Notation
return J

@Eastney
Copy link

Eastney commented May 4, 2024

okay, i apparently need to go back to school.... The following does work, not quite how i was thinking, but it works, the display is a bit erratic, but (again) it works.

@handcalc(override=str("symbolic"), precision= int(3), left= str("$"), right= str("$"), jupyter_display= True)
def factor_f(C_36,A):
f = C_36/(1+A) # Factor f, factor for hub stress
if f <= 1:
f <= 1 #"calculated f is not acceptable"), per 2-3 Notation
return f #
elif f >= 1:
f > 1 #"f is acceptable"), per 2-3 Notation
return f

p.s. love handcalcs, am wanting to use it more, mostly as a shortcut around Excel. I cannot escape IT, but i can short cut it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants