Skip to content

Conversation

@izulin
Copy link
Collaborator

@izulin izulin commented Oct 4, 2020

Context

14 new functions: VAR.P, VAR.S, VARA, VARPA, STDEV.P, STDEV.S, STDEVA, STDEVPA, SUBTOTAL, PRODUCT, VARP, VAR, STDEVP, STDEV.

How has this been tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

Checklist:

  • My code follows the code style of this project,
  • My change requires a change to the documentation,
  • I described the modification in the CHANGELOG.md file.

izulin and others added 2 commits October 4, 2020 15:34
Copy link
Contributor

@wojciechczerniak wojciechczerniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add to https://github.com/handsontable/hyperformula/blob/master/docs/guide/known-limitations.md that SUBTOTAL is not supported fully. There is no difference between 1 and 101. We don't have support for row/column visibility meta data. @izulin @voodoo11 is this even possible? A callback in options maybe?

hfInstance = new Hyperformula({
  isHidden: function(rowIndex) {
    return handsontableInstance.isHidden(rowIndex);
  }
});

expect(engine.getCellValue(adr('A1'))).toBeCloseTo(0.707106781186548, 6)
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(1.78885438199983, 6)
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.oasis-open.org/office/OpenDocument/v1.3/csprd02/part4-formula/OpenDocument-v1.3-csprd02-part4-formula.html#__RefHeading__1018768_715980110

Unlike the STDEV function includes values of type Text and Logical. Text values are treated as number 0. Logical TRUE is treated as 1, and FALSE is treated as 0. Empty cells are not included.

The handling of string constants as parameters is implementation-defined. Either, string constants are converted to numbers, if possible and otherwise, they are treated as 0, or string constants are always treated as 0.

🙈 Which implementation did we choose? How does it relate to Excel requirements?

  • Arguments can be the following: numbers; names, arrays, or references that contain numbers; text representations of numbers; or logical values, such as TRUE and FALSE, in a reference.
  • Arguments that contain TRUE evaluate as 1; arguments that contain text or FALSE evaluate as 0 (zero).
  • If an argument is an array or reference, only values in that array or reference are used. Empty cells and text values in the array or reference are ignored.
  • Arguments that are error values or text that cannot be translated into numbers cause errors.
  • If you do not want to include logical values and text representations of numbers in a reference as part of the calculation, use the STDEV function.

Source: https://docs.oasis-open.org/office/OpenDocument/v1.3/csprd02/part4-formula/OpenDocument-v1.3-csprd02-part4-formula.html#__RefHeading__1018768_715980110

BTW We should add more tests for the requirements above

Copy link
Collaborator Author

@izulin izulin Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which implementation did we choose? How does it relate to Excel requirements?

I don't really understand -- we implemented STDEVA function.

The logic behind -A variants are nothing new, we already handled it with AVERAGEA, MAXA, MINA, SUMA functions. I'll add more extensive test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ODFF description suggests that STDEV can have different behavior depending on the implementation: "The handling of string constants as parameters is implementation-defined. Either, string constants are converted to numbers, if possible and otherwise, they are treated as 0, or string constants are always treated as 0."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then for consistency I would keep it the same as in AVERAGEA. Where should it be documented?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create a test that is our behaviour documentation with a clear description and an inconsistency comment

@izulin
Copy link
Collaborator Author

izulin commented Oct 6, 2020

We should add to https://github.com/handsontable/hyperformula/blob/master/docs/guide/known-limitations.md that SUBTOTAL is not supported fully. There is no difference between 1 and 101. We don't have support for row/column visibility meta data. @izulin @voodoo11 is this even possible? A callback in options maybe?

hfInstance = new Hyperformula({
  isHidden: function(rowIndex) {
    return handsontableInstance.isHidden(rowIndex);
  }
});

That would be super messy with the logic behind triggering recalculations, caching etc. (if done correctly, would probably result in performance hit).

@izulin izulin requested a review from bardek8 October 9, 2020 12:38
Copy link
Collaborator

@bardek8 bardek8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes!
LGTM, but let's wait for a green light from @wojciechczerniak

Copy link
Contributor

@wojciechczerniak wojciechczerniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added few examples but all tests should be reviewed if they can be improved.

Comment on lines 16 to 25
it('should calculate variance (sample)', () => {
const engine = HyperFormula.buildFromArray([
['=VAR.S(2, 3)'],
['=VAR.S(2, 3, 4, TRUE(), FALSE(), "1",)'],
['=VAR.S(B3:I3)', 2, 3, 4, true, false, 'a', '\'1', null],
])
expect(engine.getCellValue(adr('A1'))).toEqual(0.5)
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(2.28571428571429, 6) //inconsistency with product #1
expect(engine.getCellValue(adr('A3'))).toEqual(1)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add clear descriptions to the conditions we're checking

it('should ignore empty cells, logical values, text and error values if argument is a reference', () => {
      ['=VAR.S(B3:I3)', 2, 3, 4, true, false, 'a', '\'1', null, '#DIV/0'],
it('should count logical values and text representation of numbers that are arguments', () => {
      ['=VAR.S(2, 3, 4, TRUE(), FALSE(), "1",)'],

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors are not ignored.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistency with the docs then? Not again...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it in the docs?

Copy link
Contributor

@wojciechczerniak wojciechczerniak Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Empty cells, logical values, text, or error values in the array or reference are ignored." Source: https://support.microsoft.com/en-us/office/var-s-function-913633de-136b-449d-813e-65a00b2b990b

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the implementation clearly propagates errors 🥇

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, nothing to add here then 🤷 Thanks for checking

Copy link
Contributor

@wojciechczerniak wojciechczerniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Few descriptions can be more specific though. They say the same but results are different. I've added specifics to two of them but could you apply those to all pairs?
STDEVA vs STDEVS
STDEVPA vs STDEVP
VARA vs VARS
VARPA vs VARP

Comment on lines 114 to 119
'VAR.S': {
method: 'vars',
},
'VAR.P': {
method: 'varp',
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a valid solution to make VARP and VARS aliases here that are linking to the same method but under different name?

Suggested change
'VAR.S': {
method: 'vars',
},
'VAR.P': {
method: 'varp',
},
'VAR.S': {
method: 'vars',
},
'VAR.P': {
method: 'varp',
},
'VARS': {
method: 'vars',
},
'VARP': {
method: 'varp',
},

BTW. Are we missing arguments definitions or they are redundant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those functions are not using the mechanism that requires args definitions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such method as 'VARS' -- VAR should be an alias of VAR.S

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@wojciechczerniak wojciechczerniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 🥇

@izulin izulin merged commit 719b630 into develop Oct 14, 2020
@izulin izulin deleted the jk/subtotal branch October 14, 2020 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants