UC-4: Calculating Trends

Calculating trends with an index is really complex to achieve, as you can only calculate aggregates using the data of a single result. The easiest way to calculate trends is therefore to precompute data. You can perform this operation with an aggregation processor.

This task shows you how to:


Before you begin: We assume that previous UCs have been completed.

Step 1 - Configure an Aggregation Processor for Trades

  1. Add an aggregation processor:
    1. Select Groovy as format
    2. For Name, enter Trades_UC_4
    3. Click Accept
  2. Replace the default code by the following one:

    // Process nodes having the “trade” type
    process("trade") {
       log.info "trade found for tendencies: " + it.metas.year + "_" + it.metas.country_id + "_" + 
    it.metas.type ;
    
       // default value
       it.metas.lastyearvolume = it.metas.getValue("volume");
    
       // Find previous year value to show tendencies
       // It is possible to build the path using a meta of the node
       for (path in match(it, "-" + it.metas.getValue("type") + "[country]" + "." + it.metas.getValue("type")
     + "[trade]" )) {
       // searching for path -export.export or -import.import or -reExport.reExport
       // Retrieve the last element of the path
       last = path.last();
       log.info "Node found: " + last.getUri();
       if ( last.metas.getValue("year").toInteger() == (it.metas.getValue("year").toInteger() - 1) ) {
       it.metas.lastyearvolume = last.metas.getValue("volume");
       }
     }
    }

  3. Save and apply the configuration.

Step 2 - Rescan the Trades Connector and Check What Is Indexed

  1. Go to the Home page and under the connectors list, click Scan for the trades JDBC connector.
  2. Open the Mashup UI application page: http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/searchcountry_v3
  3. Search for a country, for example, Brazil or France.
  4. Click the see details link.
  5. In the detail page, on the Trade volume per Year (Kg) tab, check the Variation / Year graph.



  6. You can also go to the analytics page: http://<HOSTNAME>:<BASEPORT>/mashup-ui/page/analytics_v1

    This page provides various graphics. Choose the Trades tab. For each Export / Import and Re-Export tabs, you can see the trends for each year.