Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    applySummaryFunction not consistent with grid summary functions

    SmartClient_v90p_2014-03-13_PowerEdition

    This is related to post: http://forums.smartclient.com/showthread.php?t=26693

    It seems like the summary functions have been updated (per the previous post) to correctly handle cases where there are dots "." in a formula field (divide by zero). I have tested this with the grid using summary functions.

    However, in some cases we allow the user to add descriptive text to summary functions, so the display in the grid is more useful. For example a user may want to display the sum and average, so our application allows users to display the text "Total" and "Average" in the summary row, so the values are more descriptive. This is achieved using a custom function for the summary function. I have simplified the code for this test case to illustrate my point.

    Repro steps:
    - Load the test case
    - The grid will display with a formula column (observations/inspections).
    - Observe some rows have a divide by zero, resulting in "." for the formula value.
    - I have added three sumamry functions to the grid, "sum", "avg" and "max", in that order.
    - Observe that those values are 6, 3 and 6 respectively, which are correct.
    - Open the browser console (Firefox). Note that the same summary calculations yield null.

    It seems like isc.SimpleType.applySummaryFunction() has not been updated to behave the same as the built in grid summaries that were fixed (per the previous post).

    Code:
    <html>
    
    	<head>
    		<title >SNTQ-1843</title>
    		
    		<script type="text/javascript" >
    			var isomorphicDir="http://localhost:8080/isomorphic/";
    			
    			var data = [
    				{ project:"Some zeros",  inspections:0, observations:0 },
    				{ project:"Some zeros",  inspections:5, observations:0 },
    				{ project:"Some zeros",  inspections:0, observations:0 },
    				{ project:"Some zeros",  inspections:1, observations:6 }
    			];
    		</script>
    		
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Core.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Foundation.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Containers.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Grids.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Forms.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_DataBinding.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Drawing.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_PluginBridges.js"></script> 
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Charts.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Tools.js"></script>
    		 <script type="text/javascript" SRC="http://localhost:8080/isomorphic/skins/EnterpriseBlue/load_skin.js"></script>
    	</head>
    <body>
    
    	 <script type="text/javascript">
    
    		var gridObject = isc.ListGrid.create({
    			fields:[
    				{name:"project", title:"Project", type:"text" },
    				{name:"formula", title: "Formula", userFormula: { formulaVars: {A:"observations", B:"inspections"}, text:"A/B" }, summaryFunction :["sum", "avg", "max"] },
    				{name:"inspections", type:"integer", title:"# Inspections"},
    				{name:"observations", type:"integer",  title:"# Observations"}
    			],
    				dataFetchMode : "local",
    				data: data,
    				width : "100%",
    				align : "center",
    				autoFitData : "vertical",
    				autoFitMaxHeight : 400,
    				alternateRecordStyles : true,
    				canAddFormulaFields : true,
    				canAddSummaryFields : true,
    				canGroupBy : true,
    				canReorderFields : true,
    				showGridSummary : true,
    				useAdvancedFieldPicker : true,
    				advancedFieldPickerThreshold : 2
    		});
    			
    		var aggregateFunction = function(records, summaryField, f, t) {
    		
    			var val = isc.SimpleType.applySummaryFunction(records, gridObject.getField(summaryField), f);
    			if (typeof (val) != "undefined" && val != null) {
    				return t + val;
    			}
    			else {
    				return t + "null";
    			}
    		}
    
    		// set the summary functions for this formula
    		console.log("formula field summary function values");
    		console.log(aggregateFunction(gridObject.data, "formula", "sum", "=== Total is "));
    		console.log(aggregateFunction(gridObject.data, "formula", "avg", "=== Average is "));
    		console.log(aggregateFunction(gridObject.data, "formula", "max", "=== Maximum is "));
    					
    	</script>	
    
    </body>
    </html>

    #2
    It looks like your expectation is that SimpleType.applySummaryFunction() with execute a userFormula in order to determine values for a formula field. It won't do this, that's a ListGrid / DataBoundComponent feature.

    Comment


      #3
      I'm a bit confused by your reply. I would expect that the applySummaryFunction would calculate a summary (sum, avg, etc) given a list of records and a field.

      From the documentation: "Applies a SummaryFunction to an array of records "

      This works as expected if there are no records with 0 (change inspections to something greater than 0 in the data array). It returns the same values as the summary rows do with the native grid functionality. I am not trying to determine values for the formula field, as the grid does that, but get a summary of that formula field, in which case applySummaryFunction is not returning the same values as the grid in this specific case.

      Comment


        #4
        Yes, the docs are correct. What you are further assuming is that the method on SimpleType calculates values for a formula field. It does not do this, and it is not associated with the grid, so the grid won't be calculating formula values here either (you pass only a field object to the method, not a grid).

        Comment


          #5
          OK, based on your replay I tested with a straight data array. More specifically, it seems like the formula column is converted to a string (".") in this case, and the applySummaryFunction returns null because it cannot handle strings.

          I have implemented a workaround for this case where I convert the fields with "." to 0 as this should be the expected behavior in the cases that we are testing.

          Comment


            #6
            The "." is ListGrid.badFormulaResultValue, so it's both a display value and also specific to grids, not something that would be expected as a record value for a numeric field, or expected to be understood by the method on SimpleType.

            It's not clear what behavior you're seeing where you need a "workaround", but if you have a working approach, great.

            Comment


              #7
              I create a formula column and get the "." becuase of divide by zero. I then use grid.data to get the data set, and the value for the formula field in these cases are ".".

              The workaround is needed to get the applySummaryFunction to ignore these values - I basically create a new array of records without the "." records, so my sum, avg, etc. return a non-null value.

              Its not the most elaborate solution, but it works. Setting the badFormulaResultValue to 0 will not work either, this display 0 in the table instead of "." but will throw off calculations such as average.

              I understand that they are two separate functions and components, but I would expect that they would produce the same result given the same set of data. It looks like the grid ignores bad formula results for summaries, (I understand that its a function of the grid), but for consistency the applySummaryFunction should do the same (ignore non-numeric values/calculations)

              Comment


                #8
                We've made a fix to the SC 10.0d/SGWT 5.0d, SC 9.1p/SGWT 4.1p, and SC 9.0p/SGWT 4.0p branches to solve this issue. These should be picked up by the next nightlies.

                Comment


                  #9
                  Thanks. Confirmed that this is fixed.

                  Comment

                  Working...
                  X