ID |
Date |
Icon |
Author |
Author Email |
Category |
OS |
ELOG Version |
Subject |
1790
|
Tue Apr 4 08:15:29 2006 |
| Stefan Ritt | stefan.ritt@psi.ch | Request | | 2.6.1 | Re: Simple math within an elog form |
Steve Jones wrote: | This may sound a little strange but I am trying to determine if it is possible to create a series of attributes that may be assigned an integer value via OPTIONS, and then take the selected values and perform some simple math and display the result. |
This item is already on the wishlist, so I added your vote there. But due to my workload, it will certainly not be implemented in the next few weeks. |
1792
|
Wed Apr 5 00:00:14 2006 |
| Steve Jones | steve.jones@freescale.com | Request | | 2.6.1 | Re: Simple math within an elog form |
Stefan Ritt wrote: |
Steve Jones wrote: | This may sound a little strange but I am trying to determine if it is possible to create a series of attributes that may be assigned an integer value via OPTIONS, and then take the selected values and perform some simple math and display the result. |
This item is already on the wishlist, so I added your vote there. But due to my workload, it will certainly not be implemented in the next few weeks. |
Quote: |
Ok, understood. So instead I am trying to use $shell and am running into a problem
##################################################
# Define Risk1
#
Options Risk1 = 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
##################################################
# Define Risk2
#
Options Risk2 = 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
##################################################
# Define Risk2
#
Options Risk3 = 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
##################################################
# Define TotalRisk
#
Subst TotalRisk = $shell(echo $Risk1 + $Risk2 + $Risk3 > /tmp/elog_out)
#Subst TotalRisk = $shell(gawk 'BEGIN{ print $Risk1 + $Risk2 + $Risk3 }' )
#Subst TotalRisk = $shell(uname -a)
What comes out with my simple echo or gawk line is "+ + " so it looks like the attributes are not getting passed into the $shell code? |
1793
|
Wed Apr 5 10:07:59 2006 |
| Stefan Ritt | stefan.ritt@psi.ch | Request | | 2.6.1 | Re: Simple math within an elog form |
Steve Jones wrote: |
Subst TotalRisk = $shell(echo $Risk1 + $Risk2 + $Risk3 > /tmp/elog_out)
What comes out with my simple echo or gawk line is "+ + " so it looks like the attributes are not getting passed into the $shell code? |
The reason is that the substitutions get evaluated from left to right, so first the shell is called with $Risk1, and because the shell by itself does a subsitution and $Risk1 is not defined on the unix system, the shell returns an empty string, leading to "+ +" as the result.
I changed that in the current SVN version, so we have first the attribute substitions, then then shell substitution. The "echo $Risk1..." will of course not work, since it gets substituted by elog as "echo 12 + 23 + 45" (or whatever the numbers are), and the "echo" will just return these numbers without adding them. To make the shell to add things, you would need to define the risks as environment variables for the shell, so I guess the "gawk" method will work better for you. I tried it and it worked fine for me. |
1794
|
Wed Apr 5 13:50:14 2006 |
| Steve Jones | steve.jones@freescale.com | Request | | 2.6.1 | Re: Simple math within an elog form |
Stefan Ritt wrote: |
Steve Jones wrote: |
Subst TotalRisk = $shell(echo $Risk1 + $Risk2 + $Risk3 > /tmp/elog_out)
What comes out with my simple echo or gawk line is "+ + " so it looks like the attributes are not getting passed into the $shell code? |
The reason is that the substitutions get evaluated from left to right, so first the shell is called with $Risk1, and because the shell by itself does a subsitution and $Risk1 is not defined on the unix system, the shell returns an empty string, leading to "+ +" as the result.
I changed that in the current SVN version, so we have first the attribute substitions, then then shell substitution. The "echo $Risk1..." will of course not work, since it gets substituted by elog as "echo 12 + 23 + 45" (or whatever the numbers are), and the "echo" will just return these numbers without adding them. To make the shell to add things, you would need to define the risks as environment variables for the shell, so I guess the "gawk" method will work better for you. I tried it and it worked fine for me. |
Sorry, I waSn't clear about just why I was using "echo". Since elog removes the /tmp/elog_shell temporary file I couldn't "see" what was actually being passed to the shell - gawk was giving me an error and I was flying blind. So I used echo to create my own temporary file.
Yes, gawk should now work -- I'l download and compile the latest and provide feedback.
Thanks! |
1795
|
Wed Apr 5 18:56:48 2006 |
| Steve Jones | steve.jones@freescale.com | Request | | 2.6.1 | Re: Simple math within an elog form |
Steve Jones wrote: |
Stefan Ritt wrote: |
Steve Jones wrote: |
Subst TotalRisk = $shell(echo $Risk1 + $Risk2 + $Risk3 > /tmp/elog_out)
What comes out with my simple echo or gawk line is "+ + " so it looks like the attributes are not getting passed into the $shell code? |
The reason is that the substitutions get evaluated from left to right, so first the shell is called with $Risk1, and because the shell by itself does a subsitution and $Risk1 is not defined on the unix system, the shell returns an empty string, leading to "+ +" as the result.
I changed that in the current SVN version, so we have first the attribute substitions, then then shell substitution. The "echo $Risk1..." will of course not work, since it gets substituted by elog as "echo 12 + 23 + 45" (or whatever the numbers are), and the "echo" will just return these numbers without adding them. To make the shell to add things, you would need to define the risks as environment variables for the shell, so I guess the "gawk" method will work better for you. I tried it and it worked fine for me. |
Sorry, I waSn't clear about just why I was using "echo". Since elog removes the /tmp/elog_shell temporary file I couldn't "see" what was actually being passed to the shell - gawk was giving me an error and I was flying blind. So I used echo to create my own temporary file.
Yes, gawk should now work -- I'l download and compile the latest and provide feedback.
Thanks! |
Ok, confirming that this now works. Passing the command:
Subst <attribute> = $shell(gawk 'BEGIN{ print $Attrib1 + $Attrib2 + $Attrib3 }' )
will cause the result to be pushed into <attribute>, so gawk in essence becomes a simple calculator and operates on the formula "$Attrib1 + $Attrib2 + $Attrib3". |
66304
|
Tue Apr 14 08:30:42 2009 |
| Stefan Ritt | stefan.ritt@psi.ch | Question | Windows | 2.7.5-2187 | Re: Simple Math |
mike cianci wrote: |
Sorry to bother you. I could see in past Forum entries that the question of "Simple Math" has come up before, although the answers were not all that simple.
Can you do simple math (i.e. attribute A + attribute B = attribute C) in ELOG ?
Thank you for putting up with my questions.
Mike
|
No, you can't. The only way is to export a logbook to CSV, then import it in a spreadsheet program, then do the math there. |
66310
|
Tue Apr 14 17:57:56 2009 |
| Erik Iverson | eiverson@ornl.gov | Question | Windows | 2.7.5-2187 | Re: Simple Math |
Stefan Ritt wrote: |
mike cianci wrote: |
Sorry to bother you. I could see in past Forum entries that the question of "Simple Math" has come up before, although the answers were not all that simple.
Can you do simple math (i.e. attribute A + attribute B = attribute C) in ELOG ?
Thank you for putting up with my questions.
Mike
|
No, you can't. The only way is to export a logbook to CSV, then import it in a spreadsheet program, then do the math there.
|
You can pass numerical attributes to an external command via "Execute new =...". This external command can then do the math and pass the result _back_ to the logbook either as a new entry or as an edit with the command-line client "elog".
For example, given a new entry with (numerical) attributes A and B, if you have
Execute new = add_them.pl $A $B $message id
in your elog.cfg file, then $A and $B will be passed to the add_them.pl perl script. Now have the perl script (or bc, or whatever you want to use) do the appropriate math and submit the result. For example, your perl script might include
$C=$A+$B
$D=$A*$B
elog -a C=$C ... -e "$message id" "Sum as edit"
elog -a D=$D ... "Product as new entry"
|
66051
|
Mon Nov 17 11:06:29 2008 |
| Stefan Ritt | stefan.ritt@psi.ch | Bug report | | 2.7.3-2109 | Re: Show/Hide links are displayed but don't work if Show attachments = 0 |
Dennis Seitz wrote: |
If I add this statement to a logbook config file:
Show attachments = 0
When viewing and individual entry, attached images are not displayed, which is as intended, but the links Show/Hide and Show All/Hide All are still displayed although they do nothing when clicked except switch between Show and Hide. Clicking on an image opens it in a separate window.
Could you make show/hide and show/hide all work? This way, by default the images are not displayed, but the default could be overridden on a case by case basis as desired, and the images displayed inline in the same window with the entry.
|
Very good idea! I changed that in ELOG V2.7.5-2139. The fix will be contained in the next release. |
|
ELOG V3.1.5-3fb85fa6 |