Comments on Calc Macro
Last modified by Joao Peixe on 2023/04/06 10:07
Choose the export format from the list below:
Export as Portable Document Format (PDF) using the Web Browser
Export as HyperText Markup Language (HTML)
v1.0 - The sum macro appears to treat negative numbers as positive when summing.
Add the following code to line 138 of Macros.CalcGroovy page will solve this problem.
137 else {
138 def value = 0;
139
140 Added by [email protected]
141 deal with nagative numbers
142 def prev = child2.getPreviousSibling();
143 if (prev && prev.toString().equals("-"))
144 content = "-" + content;
145
146 try {
147 value = Float.parseFloat(content)
148 println "ADDING: ${value} for content ${content}"
I experience >100% CPU usage and page loads 20 seconds on following use-case
|2012-02 |Team building in the mountains|29|400|Including mobility team|(% style="text-align: right;" %){{calc formula="$C*$D" format="0"/}}|
|2012-03|Release pizza party|17|30|Pizza party for finishing maintenance release|(% style="text-align: right;" %){{calc formula="$C*$D" format="0"/}}|
|2012-06|Release pizza party|17|30|Pizza party for finishing release in scope of half/year collaboration|(% style="text-align: right;" %){{calc formula="$C*$D" format="0"/}}|
|2012-07|Team building in the mountains|29|400|Final release team building |(% style="text-align: right;" %){{calc formula="$C*$D" format="0"/}}|
| | | | |(% style="text-align: right;" %)**Grand total**|(% style="text-align: right;" %)**{{sum type="col" format="0 ?"/}}**|
The Calc Macro worked well in xWiki 6.3. After upgrading to 6.4.1, the macro stopped working and now displays: "Failed to execute the [groovy] macro. Click on this message for details."
Debugging the CalcGroovy script, it appears that when the script does a .getParent() on the MacroBlock that is coming in, it is returning null. Previously, it used to return the TableHeader block of the table containing the Macro.
Are there any workarounds for this issue, or plans to make it compatible with 6.4.x?
Thanks
The regression has been caused by https://jira.xwiki.org/browse/XWIKI-11805. Sorry about that. I'll be fixed soon.
I'll try to look at it and see what I can do
Yes I confirm what Vincent is saying. It should work again after the core issue is fixed.
The {{sum /}} macro needs a way of filtering rows. I would suggest a parameter of "exclude" which takes a comma separated list of rows to exclude. My current issue is that the row headings also have a number in them and then this gets added to the sum.
I've encountered an unexpected result with the calc formula. When I try to get values either by using $b or $col.get(2), if the value is 20, I get 2020. So instead of sum, let's say, 20+10, the sum is 2020+1010=3030. Am i doing something wrong? In the same table, sum is working fine.