Feature #1005

Feature #917: Report Writer (see Feature #916: Use of map layer to find data from another layer)

Provide a way to get column statistics through JavaScript

Added by Andy Dufilie over 4 years ago. Updated over 3 years ago.

Status:ResolvedStart date:07/25/2012
Priority:HighDue date:
Assignee:Andy Dufilie% Done:

0%

Category:Visualization InterfaceEstimated time:40.00 h
Target version:-
Complexity: OIC Priority:No
Required by:MARC, Kansas City, MO

Description

Here's a function that will get column statistics values asynchronously:

/**
 * Adds a callback which will be called whenever the stats values for a specified column change.
 * @param weavePath A WeavePath object pointing to a column object in the session state.
 * @param callback A function which will receive a stats object for the column.
 */
function addStatsCallback(weavePath, callback) {
    weavePath = weavePath.weave.path(weavePath.getPath()); // makes a copy
    function callbackToString(f) {
        weavePath.addCallback(f).removeCallback(f);
        return weavePath.weave.path.callbacks.slice(-1)[0].name;
    }
    weavePath
        .libs('weave.api.WeaveAPI', 'flash.external.ExternalInterface')
        .vars({
            "statsCallback": callbackToString(function(){
                var stats = weavePath.getValue("\
                    var stats = WeaveAPI.StatisticsCache.getColumnStatistics(this);\
                    WeaveAPI.SessionManager.registerLinkableChild(stats, this);\
                    WeaveAPI.SessionManager.registerLinkableChild(WeaveAPI.globalHashMap, stats);\
                    stats.getCount();\
                    if (WeaveAPI.SessionManager.linkableObjectIsBusy(stats))\
                        return null;\
                    var names = ['count', 'max', 'mean', 'min', 'squareSum', 'standardDeviation', 'sum', 'variance'];\
                    var values = new Object();\
                    names.forEach(function(name){\
                        values[name] = stats['get' + name.charAt(0).toUpperCase() + name.substr(1)]();\
                    });\
                    return values;\
                ");
                if (stats)
                    callback.call(weavePath, stats);
            })
        })
        .exec("\
            var stats = WeaveAPI.StatisticsCache.getColumnStatistics(this);\
            var cc = WeaveAPI.SessionManager.getCallbackCollection(stats);\
            cc.addGroupedCallback(null, function(){\
                ExternalInterface.call(statsCallback);\
            }, true);\
        ");
}

Example usage:

var path = weave.path("defaultColorDataColumn", "internalDynamicColumn");
var callback = function(stats){
    console.log(this.getPath());
    console.log(JSON.stringify(stats, null, 3));
}
addStatsCallback(path, callback);

Example output:

["defaultColorDataColumn", "internalDynamicColumn"]
{
   "sum": 985.9000000000001,
   "variance": 5.393461057892637,
   "standardDeviation": 2.322382625213304,
   "count": 49,
   "squareSum": 20100.990000000005,
   "max": 40,
   "min": 0,
   "mean": 20.120408163265306
}

aggregate-value.png (23.9 KB) Andy Dufilie, 07/25/2012 03:13 PM

History

#1 Updated by Andy Dufilie over 4 years ago

  • Required by set to MARC, Kansas City, MO

#2 Updated by Andy Dufilie over 4 years ago

  • Estimated time set to 40.00

#3 Updated by Andy Dufilie over 4 years ago

Note: It may be better to provide ALL the statistics for all selected columns so the admin wouldn't have to go through so many wizards to set each value. The JavaScript code could then access what it wants and generate a table/report.

#4 Updated by Andy Dufilie over 4 years ago

When this is implemented, we also need to provide an example HTML template that displays the data.

#5 Updated by Andy Dufilie over 4 years ago

  • Priority changed from Normal to High

#6 Updated by Andy Dufilie over 4 years ago

  • Status changed from Awaiting Feedback to Community Discussion
  • OIC Priority set to No

#7 Updated by Manny Trillo over 4 years ago

Andy,

The reasoning behind this request was to circumvent the lack of reporting options in Weave. If we could have access to such variables, we could create a report outside of Weave. I like the fact that the variable can be created for selected records. Is it possible to create an array that applies the function to multiple columns instead of a single variable to one column? Often times you would want to aggregate multiple columns for the selected area and include all those aggregations in a report. Also, I am assuming that the Equation editor can be used to create a new column based on a specific expression and then this function could be used to create a variable for the calculated column. I have had issues with the equation editor, but that is a diferent story.

#8 Updated by Andy Dufilie over 3 years ago

  • Subject changed from Create an interface for setting JavaScript variables to aggregated column values (for use with an external HTML template) to Provide a way to get column statistics through JavaScript
  • Description updated (diff)
  • Status changed from Community Discussion to Resolved
  • Assignee set to Andy Dufilie

See the issue description for a JavaScript function that you can use.

Also available in: Atom PDF