Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] charts: non-invertible matrix returns NaN as predicted data #5202

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

anhe-odoo
Copy link
Contributor

Task Description

When trying to make a trending line, almost all model use matrix computation to get the predicted data, with some matrix multiplications and inversions. When the matrix aren't inversibles, the user get a traceback, which is not fine.
This PR aims to fix these issues by returning an array of NaN when there is an error in the computation of the predicted dataset.

Related Task

  • Task: 4328743

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented Nov 13, 2024

Pull request status dashboard

Copy link
Contributor

@hokolomopo hokolomopo left a comment

Choose a reason for hiding this comment

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

I forgot how math works, but is it really not possible to do a polynomial regression of degree 2 between [1, 3] ?

predictLinearValues([values], [normalizedLabels], [normalizedNewLabels], true)
)[0];
} catch (e) {
return [];
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we return an empty array here, but an array of NaN in th'e other cases ? Cna't we return an empty array everytime in a global try/catch on the function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The empty array is a mistake, it should returns NaN every time. In fact, the idea of returning NaN was to see the series in the legend, while an empty array gives no entry in the legend.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This means that we end up displaying a legend for an invisible dataset since it only contains NAN values. I don't really see the point - the user will just wonder what went wrong. Hiding the legend doesn't do the trick either. I think the error should be somehow visible in the sidepanel if something went wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree with that point of showing the error, but should it be done in v18 or in master then ? As it will change some part of the structure of the side panel to be able to display an error message (not a big change, but one change "quand-même"

src/helpers/figures/charts/chart_common.ts Outdated Show resolved Hide resolved
Comment on lines +3202 to +3203
expect(runtime.chartJsConfig.data.datasets[1].data.every((x) => isNaN(Number(x)))).toBeTruthy();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Shoudln't we avoid giving an useless dataset filled with NaN to chartJS ? At some points we will change something and it chartJs will end up putting it in a legend or a tooltip or something.

@anhe-odoo anhe-odoo force-pushed the 18.0-chart-handle_trendline_error-anhe branch from 63adf97 to 0012c66 Compare November 13, 2024 16:42
Task Description

When trying to make a trending line, almost all model use matrix
computation to get the predicted data, with some matrix
multiplications and inversions. When the matrixes aren't invertible
the user get a traceback, which is not fine.
This PR aims to fix these issues by returning an array of NaN when
there is an error in the computation of the predicted dataset.

Related Task

Task: 4328743
@anhe-odoo anhe-odoo force-pushed the 18.0-chart-handle_trendline_error-anhe branch from 0012c66 to 8ff8278 Compare November 14, 2024 09:01
try {
switch (config.type) {
case "polynomial": {
const order = config.order ?? 2;
Copy link
Collaborator

@rrahir rrahir Nov 22, 2024

Choose a reason for hiding this comment

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

Shouldn't this crash/return early if the order is not provided? We know that the config was badly done at that point. Do youthink this should be checked by the allowDispatch?

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.

4 participants