Variable expression contains another variable - jasper-reports

I am trying to put some variable inside Variable Expression of another variable.
For example:
$V{sum} = $F{quantity} * ${price}, where sum is simple variable without any calculation
$V{total} = $F{disb} * $V{price}, where total has 'Sum' calculation type.
As a result I receive the wrong amount.
But If I use:
$V{total} = $F{disb} * $F{quantity} * ${price}
the amount is valid.
Is there any reason that variable inside variable expression gives wrong value? Thank you

If you are outputting the $V{total} of your first example in a textfield, then you will need to make sure the Evaluation Time is set correctly per your report. Most likely you will want to set the field evaluation time to "Report".
The evaluation time determines when dynamically calculated variables are actually processed during the report's generation life-cycle.

Related

ADF Pipeline Use variable inside another Set Variable

I have two activities inside a for each
Set variable 1 - Value is a string. I want to add this string to the content of Set Variable 2
#item().MessageType (eg :- EVENT, TYPE , STATUS etc. These are the output of a dataflow activity)
Set variable 2 :
#activity('df_dataflow_activity').output.runStatus.output.CacheWaterMarkValue.value[0].EVENT
Here, I want to dynamically change the last part to EVENT,STATUS etc.
#activity('df_dataflow_activity').output.runStatus.output.CacheWaterMarkValue.value[0].{get value of Variable 1)
I tried but getting unable to parse error.
`#activity('df_dataflow_activity').output.runStatus.output.CacheWaterMarkValue.value[0].EVENT`
gives me result of 99999 . The last part EVENT/TYPE/STATUS I want it to be dynamic
Set Variable is used to store the value into a variable. You can use that variable in later activities.
You can include the variable which is used in set variable1 in set variable2.
Set variable1:
Set Variable2:
#concat('sample_',variables('var1'))

How to set variable value after "Print when Expression" from textfield returned true

Using iReport I have a textfield with following "Print When Expression":
new Boolean($F{data}.doubleValue()<3 && $V{check}.intValue()==0);
My problem is that I only want to print this textfield once. For that I thought I can use a variable (check).
I tried to use this expression for the variable:
($F{data}.doubleValue()<3) ? 1 : 0
The problem is that the expression for the variable is called before the textfield checks its "print condition" and so the textfield never get printed.
How can I achieve that the variable value is set AFTER the textfield "print condition" returned true?
I want to mark the first value which is smaller than a reference value
I often use the parameter map (P{REPORT_PARAMETERS_MAP}) to store and evaluate custom expression depending on previous values and outputs
Example (return true if value $F{X}<100 and it has never been below before)
<printWhenExpression>
<![CDATA[$F{X}.doubleValue()<100?$P{REPORT_PARAMETERS_MAP}.put("X_LESS_100",true)==null?true:false:false]]>
</printWhenExpression>
This expression leverage the fact that Map.put(K,V) returns the previous value associated with key, that is null if never called, while second time $F{X} is below 100 it will return our previous set value that is true.
Note: you do not need to define any variable.
I found a workaround, but I don't find it a very good way, because my solution is related to the evaluation time of the conditions from the textfield and the variable.
So if anybody has a nice solution please post it.
I set the initial value of my check variable to 0.
The variable expression looks like this:
($F{data}.doubleValue() >= 3)? 0 : ($F{data}.doubleValue() < 3 && $V{check}.intValue()==0) ? 2 : 1;
The "Print When Expression" from the textfield is:
new Boolean($V{check}.intValue()==2);

Matlab - using a function mulitple times in the same workspace, to add values and fields to a structure

I have a structure such as:
specimen.trial1 = 1
I now want to add another trial to the specimen, so that
specimen.trial1 = 1
specimen.trial2 = 2
I can do this without a problem within the workspace and command window. But, if I'm using a function to calculate the numbers for each trial (with dynamic fields), the new field and value erases the previous one. Eg:
function [specimen] = dummy(trial,value)
specimen.(trial) = value
end
run the function:
[specimen] = dummy('trial1',1)
then run the function again with different inputs, but keeping the structure intact in the workspace
[specimen] = dummy('trial2',2)
Instead of getting a structure with 2 fields, I get just one with Trial2 being the only field. Does that make any sense? What would like is to use the outputs of a function to progressively add to a structure.
Thank you,
Chris
Yes it makes sense, because you're creating a new struct specimen within your function.
Solution: pass the the previous specimen to the function as well.
function [specimen] = dummy(specimen,trial,value)
specimen.(trial) = value
end
and call:
[specimen] = dummy(specimen,'trial1',1)
or alternativly leave out the assignment at all and use the following
function [output] = dummy(value)
output = value
end
and call:
[specimen.trail1] = dummy(1)
which really depends on what you actually want to do. Put passing a name to a function which uses this name to define a struct is a little pointless unless you "use" that name otherwise. Also if you want to have input-dependent dynamic names you'd also go with the first alternative

set threshold as a function of autoThreshold

I have written a macro for ImageJ/FIJI to deconvolve my confocal microscopy images and run the "3D Object Counter" plugin. The macro successfully runs all required commands and saves all required data in the specified places.
However, I have found that the 3D-OC autothreshold (as shown in the plugin dialog box) is to stringent resulting in objects being lost or divided.
To remedy this I would like to reduce the autothreshold by a predetermined function something similar to what was done here (from:How to get threshold value used by auto threshold Plugin) which resulted in this code:
setAutoThreshold();
getThreshold(lower,upper);
v=setThreshold(lower,upper*0.5);
run("3D Objects Counter", "threshold="v" slice=10 min.=400 max.=20971520 objects statistics summary");
The idea was to call the AutoThreshold values, modify them and set them to a variable. However when these lines are run the following error is returned:
Number or numeric function expected in line 3.
v=<setThreshold>(lower,upper*0.5);
And if the variable is inserted directly into the threshold key for run(3D-OC) the following msg is encountered:
Numeric value expected in run() function
Key:"threshold"
Value or variable name:"setThreshold(lower,upper*0.5"
Any suggestions or help on how to designate the 3D-OC threshold value as a variable as described would be greatly appreciated (as would any work arounds of course :) ).
Cheers
Edit: After testing Jan's response below (which works perfectly), it appears I need to call the threshold set by the 3D-OC plugin. Anyone know how to do this?
The getThreshold(lower, upper) function returns the lower and upper threshold levels in the provided variables. There is no need to assign any value to a new variable, and as you observed, setThreshold does not have any return value.
Instead, you can use the value(s) returned from getThreshold and use them as parameters in the run method (in the correct way, by string concatenation, see here):
setAutoThreshold();
getThreshold(lower, v);
run("3D Objects Counter", "threshold=" + v + " slice=10 min.=400 max.=20971520 objects statistics summary");
Alternatively, you can use &v in the second parameter to avoid string concatenation in the last line (see the documentation for the run() macro function):
run("3D Objects Counter", "threshold=&v slice=10 min.=400 max.=20971520 objects statistics summary");
You might have to use the lower instead of the upper threshold value, depending on whether you count bright or dark objects.

iReport - Concatenating two variables with different evaluation time

I have two variables
$V{from} has evaluation value set to Now and
$V{to} has evaluation value set to Group.
Both seems to be working fine.
Now I need to append them. Currently I have $V{fromTo} which has expression $V{from} + "-" + $V{to}. Its evaluation time value is Group. What I want is just to simply append the current values of the two first mentioned variables. The current expression gives me the result (e.g. from = 1, to = 45)
45-45
Seems like the expression is taking the value of $V{from} evaluated during group execution time also. Any idea how to do this?
(Note, requirement does not allow me to just simply drag the two fields, i badly needed to store it in one variable)
I had the same problem. I solved setting Evaluation Time to Auto in my Text Field.