Parent node's PercentDone is miscalculated in some cases

Support for v6.x of our Scheduling components


Post Reply
User avatar
Omega Code
Posts: 30
Joined: Wed Aug 14, 2019 11:27 am

Parent node's PercentDone is miscalculated in some cases

Post by Omega Code »

In some cases (depending on data) PercentDone attribute for parent nodes gets miscalculated.
It is most visible when all child nodes are 100% done but parent gets 99.9999999%.

wrong underlying value for percentdone.png
wrong underlying value for percentdone.png (48.61 KiB) Viewed 271 times

We think this is probably related to js floating point error but still we would like to have some good solution for that.

**We load top node percent done as exactly 100%. that is right value because all children are 100% as well. But after normalization value is wrong = 99.9999.. we need this value to be right because we are saving it for the backend. We don't worry about formatting, we display raw value in the test case just for ilustration.

Below is updated working test case:

BTC_69519.2.zip
Updated testcase showing more precisely what is the problem
(2.46 MiB) Downloaded 13 times

In our real/live application we have temporary fixed it by checking if the value is equal to 99.99999999999999 and if so we render it as 100 but obviously this solution is flaw. We need to do the same again while saving it on backend side. Also this way it still gets marked dirty/edited on each load (with autoNormalizeNodes) as we are using one suggested solution to trace changes to that field while normalization takes place (see: viewtopic.php?f=49&t=13701&p=71167 - included in updated testcase for illustration).

Thanks in advance for help with the above

PS: formatting here is irrelevant but just to explain:

  • We don't use built in percentdonecolumn that rounds percent value because we need this value to be floored.
  • We don't use numbercolumn because all we need is this value to be floored when formatting
Last edited by Omega Code on Wed Jul 15, 2020 9:29 am, edited 1 time in total.

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 3070
Joined: Fri Apr 01, 2016 11:08 am

Re: Parent node's PercentDone is miscalculated in some cases

Post by pmiklashevich »

Please use numbercolumn provided by ExtJS

Code: Select all

{
    xtype: 'numbercolumn',
    format:'0.##',
    // format:'0.00',
    text  : 'PercentDone',
    dataIndex  : 'PercentDone',
    // renderer: v => Math.floor(v),
    width : 150,
    editor:{
        xtype:'numberfield'
    },
    // we cant use this col type
    // - we need it to be floored (not rounded)
    // xtype : 'percentdonecolumn',
},
Pavel Miklashevich - Core Developer

User avatar
Omega Code
Posts: 30
Joined: Wed Aug 14, 2019 11:27 am

Re: Parent node's PercentDone is miscalculated in some cases

Post by Omega Code »

Thanks Pavel for the reply but sadly that doesn't change anything for better.
Underlying value is still 99.999999 and this is the problem because we are then saving this value to the API.
I've updated testcase and description to ilustrate it better.

PS: Besides we need this value to be formatted with floor, so "renderer: v => Math.floor(v)", is all what we need for display.


User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 3070
Joined: Fri Apr 01, 2016 11:08 am

Re: Parent node's PercentDone is miscalculated in some cases

Post by pmiklashevich »

If you need to control it on the data level, just specify convert function for your data field. For example:

Code: Select all

Ext.define('Gnt.examples.testcase.model.Task', {
    extend : 'Gnt.model.Task',

customizableFields : [
    // OVERRIDDEN to round the value
    {
        name : 'PercentDone', type : 'number', defaultValue : 0, convert : function (v, rec) {
            return Ext.Number.roundToPrecision(v, 2);
        }
    }
],

You can check value in console:

Code: Select all

Ext.first('ganttpanel').taskStore.getAt(0).getPercentDone();
Pavel Miklashevich - Core Developer

User avatar
Omega Code
Posts: 30
Joined: Wed Aug 14, 2019 11:27 am

Re: Parent node's PercentDone is miscalculated in some cases

Post by Omega Code »

Thanks Pavel,
This helped us a little bit as we can now handle this bug in one place.
Yet still the source of the problem remains (imprecise PercentDone calculation).
So our solution now looks like this:

Code: Select all

        { name : 'PercentDone', type : 'number', defaultValue: null,
            convert: v => v === 99.99999999999999 ? 100 : Math.floor(v),
        },

Post Reply