Dashboard > Atlassian Plugins > ... > Macros > eval-data
  Atlassian Plugins Log In | Sign Up   View a printable version of the current page.  
  eval-data

Added by admin , last edited by David Peterson on Feb 27, 2007  (view change)
Labels: 

{eval-data}

Plugin: Scaffolding Plugin

Allows for the evaluation of mathematical expressions using data set inside a scaffold.

Usage

{eval-data:Name}expression{eval-data}

Parameters

Name Required Default Description
[default]/name
The name of the field the evaluated result will be stored in.
format
The format the resulting number should be converted to. Follows the standard java.text.DecimalFormat rules.

Functions

There are some special functions available:

  • round([number], [places]) - rounds the number to the amount of specified decimal places.
  • sumtable([table], [column]) - sums all rows for the column in the specified table. Put quotes around the table and column names.
  • avgtable([table], [column]) - averages all rows for the column in the specified table. Put quotes around the table and column names.

Examples

Basic Mathematics

The following example simply calculates the value of a fraction.

Numerator: {number-data:Numerator|decimal=true}1{number-data}
Denominator: {number-data:Denominator|decimal=true}2{number-data}

Result: {eval-data:Result|format=#0.0}${Numerator}/${Denominator}{eval-data}
Percentage: {eval-data:Percentage|format=##0\%}round(${Result} * 100, 0){eval-data}

Working with tables

This example

{table-data:Values}
|| Name || Value ||
| {text-data:Name}{text-data} | {number-data:Value}{number-data} |
{table-data}

Sum: {eval-data:Sum}sumtable("Values", "Value"){eval-data}
Average: {eval-data:Average}avgtable("Values", "Value"){eval-data}

Notes

  • The actual expression being evaluated goes inside the macro content. Other fields in the same context can be referenced in the calculation. See the example scaffold below for more details.

Recipes

See Also

I'm trying to add data collected using {list-data} macros without much success.  Here's a trivial example:

\| How much did you spend on Breakfast? \| {list-data:Breakfast}
{list-option}5{list-option}
{list-option}10{list-option}
{list-option}15{list-option}
{list-data} \|
\| How much did you spend on Lunch? \| {list-data:Lunch}
{list-option}5{list-option}
{list-option}10{list-option}
{list-option}15{list-option}
{list-data} \|
\| How much did you spend on Dinner? \| {list-data:Dinner}
{list-option}5{list-option}
{list-option}10{list-option}
{list-option}15{list-option}
{list-data} \|

Total Cost of Meals: {eval-data:Meal Sum}${Breakfast}+${Lunch}+${Dinner}{eval-data}
 

I realize the above example could be accomplished summing up a column in an {edit-table} macro, that's not what I'm asking.  I have a use case that's much too long to paste above that would be solved by summing up data entered in a series of {list-data} macros.

{list-data} doesn't store values as numbers, and {eval-data} currently doesn't do any type-conversion of them. My suggestion would be to use try using the {number-data} macro in 'select' mode. Eg, for your trivial example:

| How much did you spend on Breakfast? | {number-data:Breakfast|type=select|minValue=5|maxValue=15|step=5} |
| How much did you spend on Lunch? | {number-data:Lunch|type=select|minValue=5|maxValue=15|step=5} |
| How much did you spend on Dinner? | {number-data:Dinner|type=select|minValue=5|maxValue=15|step=5} |

Total Cost of Meals: {eval-data:Meal Sum}${Breakfast}+${Lunch}+${Dinner}{eval-data}

Of course, this is only useful if the options are a regular distance apart...

If you'd like to have a way of using list-data items as numbers, raise a feature request and it will hopefully get added in a future version.

This is for a risk analysis, where risk is scored from 0 to 5. Sometimes the options are 1,3,5, other times the options are 0 and 5, other times the options aren't evenly spaced, like 0,1,5.

I've put in a feature request here:

http://jira.adaptavist.com/browse/SCAFF-174

I was thinking of an alternate approach. Could I evaluate the option selected and use a

set-data: Please provide a name.
macro to set a numeric value?

... and use a {set-data} macro to set a numeric value? (that can be evaluated using the {eval-data} macro)

Hmm. Might work as a stop-gap solution. Not ideal though...

OK, yes it's inelegant, but here's a solution that converts text entered in my simple list example to numbers that can be evaluated:

| How much did you spend on Breakfast? | {list-data:Breakfast List}
{list-option}5{list-option}
{list-option}10{list-option}
{list-option}15{list-option}
{list-data} |
| How much did you spend on Lunch? | {list-data:Lunch List}
{list-option}5{list-option}
{list-option}10{list-option}
{list-option}15{list-option}
{list-data} |
| How much did you spend on Dinner? | {list-data:Dinner List}
{list-option}5{list-option}
{list-option}10{list-option}
{list-option}15{list-option}
{list-data} |

{hidden-data}
This block sets numeric values based on the text entered in the list.

{report-block}
{local-reporter:data:Breakfast List}{text-filter:reference:value|include=5|exclude=15}{local-reporter}
{report-body}{set-data:Breakfast|type=number}5{set-data}{report-body}
{report-block}
{report-block}
{local-reporter:data:Breakfast List}{text-filter:reference:value|include=.*10.*}{local-reporter}
{report-body}{set-data:Breakfast|type=number}10{set-data}{report-body}
{report-block}
{report-block}
{local-reporter:data:Breakfast List}{text-filter:reference:value|include=.*15.*}{local-reporter}
{report-body}{set-data:Breakfast|type=number}15{set-data}{report-body}
{report-block}

{report-block}
{local-reporter:data:Lunch List}{text-filter:reference:value|include=5|exclude=15}{local-reporter}
{report-body}{set-data:Lunch|type=number}5{set-data}{report-body}
{report-block}
{report-block}
{local-reporter:data:Lunch List}{text-filter:reference:value|include=.*10.*}{local-reporter}
{report-body}{set-data:Lunch|type=number}10{set-data}{report-body}
{report-block}
{report-block}
{local-reporter:data:Lunch List}{text-filter:reference:value|include=.*15.*}{local-reporter}
{report-body}{set-data:Lunch|type=number}15{set-data}{report-body}
{report-block}

{report-block}
{local-reporter:data:Dinner List}{text-filter:reference:value|include=5|exclude=15}{local-reporter}
{report-body}{set-data:Dinner|type=number}5{set-data}{report-body}
{report-block}
{report-block}
{local-reporter:data:Dinner List}{text-filter:reference:value|include=.*10.*}{local-reporter}
{report-body}{set-data:Dinner|type=number}10{set-data}{report-body}
{report-block}
{report-block}
{local-reporter:data:Dinner List}{text-filter:reference:value|include=.*15.*}{local-reporter}
{report-body}{set-data:Dinner|type=number}15{set-data}{report-body}
{report-block}
{hidden-data}

| Breakfast: | {report-info:data:Breakfast} |
| Lunch: | {report-info:data:Lunch} |
| Dinner: | {report-info:data:Dinner} |
| Total: | {eval-data:Meal Sum}${Breakfast}+${Lunch}+${Dinner}{eval-data} |

This doesn't seem to work as expected unless you remove the {hidden-data} macros.

I've got a strange issue trying to read data within eval-data fields on another page using report-info.  I have a page which has several eval-data fields which are all displaying correctly on that page.  I'm using report-info (for the most part) to read that data from another page but some fields work and some don't despite using exactly the same syntax.

Example - this combination works:

 {eval-data:BudgetRemaining|format=#,##0}${TotalBudget}-${TotalCost}{eval-data}
 
{report-info:data:BudgetRemaining|format=#,##0|source=Weekly Progress for %CurrentPage%} 

 but this one does not although the eval-data on the source page displays fine.

 {eval-data:TotalExpRemaining|format=#,##0}${TotalExpEstimate}-${TotalExpTD}{eval-data}
 
{report-info:data:TotalExpRemaining|format=#,##0|source=Weekly Progress for %CurrentPage%} 

Any ideas?

As you say, the only difference is the name of the value. Are you 'injecting' correctly in the context? Where is '%CurrentPage%' coming from?

'%CurrentPage%' is the title of the parent page and is populated with the following code:

 {replace-item:%CurrentPage%}{report-info:content:title|source=@parent}{replace-item

 Both eval-data macros use data from other pages to calculate their value.

Hi David,

I've got a problem with the eval-data macro. I have the following code in a macro:

{report-on:@self|injected=true}
Number of Domains: {set-data:nbrChildren|format=number}{report-info:content:children > collection:size}{set-data}
Eval : 100 / {get-data:nbrChildren} : {eval-data:pctColumnWidth|format=#0} 100 / ${nbrChildren} {eval-data}
{report-on}
pctColumnWidth: {get-data:pctColumnWidth}

I was expecting to see pctColumnWidth set to something like '12'. Instead, I got the following:

Number of Domains: 8
Eval : 100 / 8 : � 
pctColumnWidth: 

Can you shed any light on this, please? What I really want to do is dynamically set the width of a table based on the number of children that the current page has (ie. 100 / (nbrChildren) to get the percent). The {replace-and-render} macro works fine with setting the value. However, I can't set the value dynamically. The best I can do is have the user enter the column width into a {number-data} field.

Regards,
Rick

I think there are two problems. Firstly, I think it should be {set-data:nbrChildren|type=number (not 'format=number'). Secondly, I still don't think it will work, because set-data and eval-data are calculated when you save the page (for performance reasons), whereas the reporting macros are executed when viewing the page. Not only that, but the actual macro text will be saved in 'nbrChildren', not the number '8', so I'm not certain what will happen when you stick it into an eval-data.

I assume you've tried using the %content:children > collection:size% syntax? This will work slightly differently than using the report-info macro and might have a higher possibility of success. Also, do try it with 'type' instead of 'format' - that may also make a difference.

Just tested this:

{report-on:@self|injected=true}
Number of Domains: {set-data:nbrChildren|type=number}%children > size%{set-data}
Eval : 100 / {get-data:nbrChildren} : {eval-data:pctColumnWidth|format=#0} 100 / ${nbrChildren} {eval-data}
{report-on}
pctColumnWidth: {get-data:pctColumnWidth}

This almost works, except for the last line, which outputs as NaN. Not sure why, since it seems to work when actually being calculated...

Dude!

Cor blimey! What were you doing up at that time? I've heard of quick responses but that was ridiculous!

I tried what you tested on our environment (Confluence 2.7.1) with the latest version of Scaffolding (uploaded this morning), and it showed the following text:

Number of Domains: 

set-data: The value provided does not match the number format: %children > size% %children > size%

Eval : 100 / 1 : � 
pctColumnWidth: 

I got the same response in both the template and the page itself.

BTW, thanks for the pickup on 'format=number'. It was supposed to be 'type=number|format=#0' but I got confused. Interestingly, if I use type=number with {report-info}, I get the same message:

Number of Domains: 
set-data: The value provided does not match the number format: {report-info:content:children > collection:size} 8

Eval : 100 / 1 : � 
pctColumnWidth: 

From what I'm seeing here, it appears that the {set-data} macro is being evaluated before the {report-info} macro or %children > size% variable is resolved.

Finally, from your experience, do you know of another way to get the number of children of the current page? I know that the {page-info} macro doesn't have that value. Otherwise, I'll just have to show the user the calculation and get them to type in the answer.

Regards,
Rick

View the rest of this thread  |  2 more comments by 2 persons

Hi Guys,

I need to auto increment a table column that acts as a row counter. e.g.

Head 1 Head2
1. Text
2. Text
3. Text
4. Text
.. Text

Is this possible using the data-eval macro?

Regards,

Carl

Can this be used with dates? I want to find a simple way to calculate how long it took to complete a request, for example the following is results in no output:

{date-data:request_date}
{date-data:complete_date}
{eval-data:review_time|format=#0}${complete_date}-${request_date}{eval-data}

Also, is it possible to use content:creation date or content:modification date as a substitute for one of the dates above?

After upgrading from Confluence 2.7 to 2.9, I am having problems getting eval-data to work inside table-data. I am using:

Software Version
Confluence 2.9.2
Scaffolding 3.1.0
Reporting 3.0.1
{table-data:ProfitLoss}
{table-plus:autoNumber=true|autoTotal=true|columnTypes=S,S,S,I,I,I,I,I,I,I,I,I,S}
|| SOW Name || Status || Type || Est. Remaining Effort (h) || Contract Remaining Effort (h) || Est. Remaining Value || Contract Remaining Value || Effort Spent (h) || Orig. Effort (h) || Orig. Budget ($) || Orig. Forecast ($) || Hourly Rate ($) || Comments ||
| {text-data:SOW Name}SOW Name{text-data} |
{list-data:Status}
  {list-option}Forecast{list-option}
  {list-option}Active{list-option}
  {list-option}Delivered{list-option}
{list-data} |
{list-data:Type}
  {list-option:Time and Materials}T&M{list-option}
  {list-option:Fixed Price}Fixed{list-option}
{list-data} |
{number-data:ERE|format=#}0{number-data} |
{eval-data:CRE|format=#}${OE}-${ES}{eval-data} |
{eval-data:ERV|format=#,###}${ERE}*${Rate}{eval-data} |
{eval-data:CRV|format=#,###}${Budget}-(${ES}*${Rate}){eval-data} |
{number-data:ES|format=#}0{number-data} |
{number-data:OE|format=#}0{number-data} |
{number-data:Budget|format=#,###}0{number-data} |
{number-data:Forecast|format=#,###}0{number-data} |
{number-data:Rate|format=#}250{number-data} |
{text-data:Comments}Comments{text-data} |
{table-plus}
{table-data}

Using the above markup, every eval-data item displays the value '0' even when the input data in the other columns are non-zero and saved. In 2.7 it used to calculate the values ok.

It doesn't matter whether or not the table-plus is there, but as soon as I eliminate the surrounding table-data, the calculations are evaluated fine even in the preview mode (but of course no longer nicely formatted in a table...).

Note that I need the calculations to be inside eval-data because I will refer to them in other tables later on.

Hi Mikkel,

Thanks for the report. I'm not sure what's happening, but the best thing would be to create a bug report and we will follow it up from there.

David

It may be obvious to some, but to others, please note that the dollar signs ($) in the examples involving money DO NOT REFER TO CURRENCY. They are not optional and are required in front of your number-data field names to execute calculations.

Copyright(c) CustomWare Asia Pacific Pty Ltd
Powered by Atlassian Confluence 2.7.3, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators