ComputedDM

A ComputedDM is a data measure that is calculated from other data measures.


01

<ComputedDM bucketization="DAILY">


02

<Name>SumOfQuantities</Name>


03

<DisplayName>Sum Of Quantities</DisplayName>


04

<Depends>RequestQuantity</Depends>


05

<Depends>PromiseQuantity</Depends>


06

<Computation>


07

rq = timeline.dataMeasures["RequestQuantity"].getBucket(bucket.startDate);


08

pq = timeline.dataMeasures["PromiseQuantity"].getBucket(bucket.startDate);


09

return ((!rq.hasValue() ? 9d : rq.value) + (!pq.hasValue() ? 10d : pq.value))


10

</Computation>


11

</ComputedDM>


  • Depends: A list of DataMeasures on which this ComputedDM is depends on; these will be evaluated PRIOR to evaluating this ComputedDM to ensure their valuables are available to your computation.

  • Computation: A Groovy expression which returns the value for a given bucket (column). This computation will be called once per bucket in the current Timeline;

Note

Don't reference a data measure if you don't have a Depends element for it! This will give you non-deterministic behavior in which the DM you are referencing from your code may or may not have been computed yet, producing invalid results!

The following variables are bound to the groovy shell and can be used from your expression. See the javadocs for the package com.onenetwork.platform.data.tlv for the details of this API.


  • timeline—represents the current Timeline object; includes methods like:

    • getDataMeasures()—returns a map of DM name to DataMeasure object (see DataMeasure interface in the Platform javadocs)

    • getStart()—Timeline start date.

    • getEnd()—Timeline end date.

    • getFilterValues()—returns the map of filter values by filter field name.

    • getHeaderValues()—returns the map of header table values by field name.

  • bucket—represents the current bucket; ant instance of the Bucket interface from the API, which includes methods like:

    • getStartDate()—bucket start date.

    • getValue()—returns bucket value (if any).

    • setValue(double)—set the provided value to the bucket.

    • hasValue()—returns true if bucket has any value associated with it otherwise false.

    • previous()—returns the previous bucket relative to the current bucket.

    • next()—returns the next bucket relative to the current bucket.

    • sibling(int)—returns the bucket by offset. Offset can be negative or positive.

  • dmName—represents the current DM name which can be used to fetch the DataMeasure from the timeline object, i.e. timeline.dataMeasures[dmName]. This is mostly to be used
    for DataBasedDMGenerator scenarios where DMs are generated at runtime and DM name is not known beforehand.

  • No DataMeasure is bound to the groovy shell, but you can fetch DataMeasures from the Timeline object. DataMeasure includes methods like:

    • getName()—returns the data measure name.

    • getBucketization()—returns the bucketization type

    • getBucket(Date)—returns the bucket interface for the provided date.

    • getBucketsForWeek(Date)—returns the collection of buckets for the entire week for the provided date (used when DM is WEEKLY DM and we need buckets for entire week).

    • getTimeline()—returns the parent Timeline object.


1

<Computation>


2

rq = timeline.dataMeasures["RequestQuantity"].getBucket(bucket.startDate);


3

pq = timeline.dataMeasures["RequestQuantity2"].getBucket(bucket.startDate);


4

return ((!rq.hasValue() ? 9d : rq.value) + (!pq.hasValue() ? 10d : pq.value))


5

</Computation>

In the above example, we are fetching the DataMeasure object from the collection based on DMName. Then we call the getBucket method on to get the Bucket object for the provided date. The "bucket" variable which is used is made available to your expression, and is the current Bucket object for this ComputedDM. (Your computation will be called once per visible bucket.) In the last line, we sum up the two request quantities, substituting 9 for qty 1 and 10 for qty 2 if they have no value. We return that as the result of the computation.


Let's take another example:

<TLVList xmlns="http://www.onenetwork.com/Platform">
<TLV>
<Name>MyFirstTLV</Name>
<Description>My First TLV Report Example</Description>
<Bucketization>DAILY</Bucketization>
<BucketsPerPage>10</BucketsPerPage>
<SqlDef Name="DummySql1" GroupName="TLVs"><![CDATA[
SELECT the_date, quantity, sys_book_id FROM(
SELECT TO_DATE('2011-07-01','YYYY-MM-DD') the_date , 2 quantity, 10000 sys_book_id FROM dual UNION ALL
SELECT TO_DATE('2011-07-02','YYYY-MM-DD') the_date , 3 quantity, 10000 sys_book_id FROM dual UNION ALL
SELECT TO_DATE('2011-07-04','YYYY-MM-DD') the_date , 2 quantity, 10000 sys_book_id FROM dual UNION ALL
SELECT TO_DATE('2011-07-05','YYYY-MM-DD') the_date , 4 quantity, 10000 sys_book_id FROM dual UNION ALL
SELECT TO_DATE('2011-07-08','YYYY-MM-DD') the_date , 3 quantity, 10000 sys_book_id FROM dual)
]]></SqlDef>
<Filters bindSqlNulls="true">
<CustomFilterField>
<FieldRef category="PDF" levelType="Undefined">
<FieldName>DateRange</FieldName>
</FieldRef>
<Hidden>false</Hidden>
<Editable>true</Editable>
<Type>DATE_RANGE</Type>
<Optional>false</Optional>
<DateRangeMapping fromSqlName="DATE_RANGE_START" toSqlName="DATE_RANGE_END"/>
</CustomFilterField>
<DateRange start="$NULL$" end="$NULL$"/>
</Filters>
<DMRef>ZBKS.RequestQuantity</DMRef>
<DM bucketization="WEEKLY">
<Name>PromiseQuantity</Name>
<DisplayName>Promise Quantity</DisplayName>
<SqlDefName>DummySql1</SqlDefName>
<SqlQuantityField levelType="Undefined">
<FieldName>quantity</FieldName>
</SqlQuantityField>
<SqlDateField levelType="Undefined">
<FieldName>the_date</FieldName>
</SqlDateField>
</DM>
<ComputedDM bucketization="WEEKLY">
<Name>SumOfQuantities</Name>
<DisplayName>Sum Of Quantities</DisplayName>
<Depends>RequestQuantity</Depends>
<Depends>PromiseQuantity</Depends>
<Computation>
rq = timeline.dataMeasures["RequestQuantity"].getBucketsForWeek(bucket.startDate);
pq = timeline.dataMeasures["PromiseQuantity"].getBucket(bucket.startDate);
return (rq.value.sum() + (!pq.hasValue() ? 10d : pq.value))
</Computation>
</ComputedDM>
</TLV>
</TLVList>

In the above example, RequestQuantity is DAILY, PromiseQuantity is WEEKLY and we also want ComputedDM to be WEEKLY. In the computation section we are using getBucketsForWeek() as the RequestQuantity is DAILY bucketized. We want the sum of all the buckets for that week added to PromiseQuantity, which is already WEEKLY. Please note how WEEKLY buckets are rendered below.
images/download/attachments/144835678/ComputedDM_WeeklySum_UI-version-1-modificationdate-1645048558000-api-v2.png
For more information on Groovy expressions, please check the following URL http://groovy.codehaus.org/Beginners+Tutorial