The Ana Tag

JETT's integration with the jAgg project allows the use of the "ana" tag, which performs analytic operations on a List of items, yielding analytic results that can be populated in the resultant spreadsheet. The "ana" tag requires a body.

Attributes

  • The "ana" tag supports all base tag attributes.
  • items: List Required. This is the List of items to analyze.
  • analytics: String Required. This is a list of analytic specification strings, delimited by semicolons, e.g. "Lag(price) partitionBy(month);Sum(quantity) orderBy(year, month) rows(12, 0)". These represent analytic operations to perform on the list of values. A property may be nested, e.g. "Avg(stock.price)".
  • analyticsVar: String Optional. If given, this is the name under which the array of AnalyticAggregator objects will be published in the beans map. This new bean can only be referenced from within the Block defined by the tag.
  • valuesVar: String Required. This is the name under which the analytic results will be published in the beans map. This new bean can only be referenced from within the Block defined by the tag.

The analytics specified in the "analytics" attribute may be an AnalyticFunction, either built-in to the jAgg library, or custom built by the developer.

Usually, a forEach tag is used inside the body of the "ana" tag to display the analytic results.

Example

A List of Employees is available in the beans map.

  • Robert Stack, salary $1000, title "Data Structures Programmer"
  • Suzie Queue, salary $900, title "Data Structures Programmer"
  • Elmer Fudd, salary $800, title "Cartoon Character"
  • Bugs Bunny, salary $1500, title "Cartoon Character"
Name Title Salary Overall Salary Rank Percent Salary of Title Total
<jt:ana items="${employees}" analytics="Rank() orderBy(salary DESC);RatioToReport(salary) partitionBy(title)" analyticsVar="analytics" valuesVar="results"><jt:forEach items="${results}" var="result">${result.object.fullName} ${result.object.title} ${result.object.salary} ${result.getAnalyzedValue(0)} ${result.getAnalyzedValue(1)}</jt:forEach></jt:ana>

One can refer to analyzed values by passing in the indexed AnalyticFunction or by passing the index itself into the "getAnalyzedValue" method.

Whether getAnalyzedValue(0) or getAnalyzedValue(analytics[0]) is used, it gets transformed into...

Name Title Salary Overall Salary Rank Percent Salary of Title Total
Robert Stack Data Structures Programmer $1000.00 2 52.63%
Suzie Queue Data Structures Programmer $900.00 3 47.37%
Elmer Fudd Cartoon Character $800.00 4 34.78%
Bugs Bunny Cartoon Character $1500.00 1 65.22%

Notice how Robert Stack's and Suzie Queue's percentages total 100%, as do Elmer Fudd's and Bugs Bunny's, because of the partitioning. However, the ranking has no partitioning, so the entire list is used for the ranking.