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

feat(web): Display preliminary instead of estimated when using TSA #6905

Conversation

tonypls
Copy link
Collaborator

@tonypls tonypls commented Jun 26, 2024

Issue

We have changed the estimation card to read Preliminary for time slicer average data but not the rest of the badges

Description

This PR updates the chart badges to display "Preliminary" instead of "Estimated" when the estimation method is Time Slicer Average.

The map tooltip data does not have the estimation method data to conditionally display here as it only gets estimated as a boolean. Setting this as preliminary for hour would not be accurate for mode reconstruct breakdown zones.

Comment on lines 198 to 203
(day) => day.meta.estimationMethod || day.meta.estimatedPercentage === 100
);

const allTimeSlicerAverageMethod = chartData.every(
(day) => day.meta.estimationMethod === EstimationMethods.TSA
);
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it doesn't start to make sense to create a custom function for these instead so we only loop over it once and set different Boolean flags instead?

Or at the very least re arrange these so the TSA is checked first and then the early TSA return then the rest of the function as it were.

Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

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

I really like this direction with the use of Enums, added some more small initial feedback points.

web/src/hooks/getEstimationTranslation.ts Outdated Show resolved Hide resolved
? t(`estimation-card.aggregated_estimated.${field}`, {
percentage: estimatedPercentage,
})
: t(`estimation-card.${estimationMethod?.toLowerCase()}.${field}`);
Copy link
Member

Choose a reason for hiding this comment

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

Should we change the enums to be lower case by default so we don't need to call toLowerCase()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sometimes they are taken from the api object and are uppercase or lowercase, I'll make it so the translations and enums match the casing but I think in the future could improve this by matching this as one case between front and backend.

web/src/utils/constants.ts Outdated Show resolved Hide resolved
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

Thanks for doing one step extra and ensuring we have strict types for the estimation methods!

Comment on lines 196 to 214
function analyzeChartData(chartData: AreaGraphElement[]) {
let estimatedCount = 0;
let tsaCount = 0;

for (const day of chartData) {
if (day.meta.estimationMethod === EstimationMethods.TSA) {
tsaCount++;
}
if (day.meta.estimationMethod || day.meta.estimatedPercentage === 100) {
estimatedCount++;
}
}

return {
allTimeSlicerAverageMethod: tsaCount === chartData.length,
allEstimated: estimatedCount === chartData.length,
hasEstimation: estimatedCount > 0,
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks way better than all the redundat loops!

Copy link
Collaborator Author

@tonypls tonypls Jul 3, 2024

Choose a reason for hiding this comment

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

The functional evangelist in me really struggled typing let 😆

@tonypls
Copy link
Collaborator Author

tonypls commented Jul 3, 2024

/review
--pr_reviewer.extra_instructions="
In the possible issues section, emphasize the following:

  • Is the code logic efficient?

"
--pr_reviewer.num_code_suggestions="4"

Copy link
Contributor

github-actions bot commented Jul 3, 2024

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

Efficiency Concern:
The analyzeChartData function in graphUtils.ts iterates over the entire chartData array multiple times through various checks. This could be optimized by consolidating these checks into a single loop to reduce the computational overhead.

Code feedback:
relevant fileweb/src/features/charts/graphUtils.ts
suggestion      

Consider refactoring the analyzeChartData function to use a single loop to iterate through the chartData array. This change will improve the efficiency by reducing the number of iterations over the data. Here's a suggested refactor:

function analyzeChartData(chartData: AreaGraphElement[]) {
  let estimatedCount = 0;
  let tsaCount = 0;
  for (const day of chartData) {
    if (day.meta.estimationMethod === EstimationMethods.TSA) {
      tsaCount++;
    }
    if (day.meta.estimationMethod || day.meta.estimatedPercentage === 100) {
      estimatedCount++;
    }
  }
  return {
    allTimeSlicerAverageMethod: tsaCount === chartData.length,
    allEstimated: estimatedCount === chartData.length,
    hasEstimation: estimatedCount > 0,
  };
}

This refactor maintains the original functionality while improving the performance by reducing the number of times the array is traversed. [important]

relevant linefor (const day of chartData) {

@VIKTORVAV99
Copy link
Member

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

Efficiency Concern: The analyzeChartData function in graphUtils.ts iterates over the entire chartData array multiple times through various checks. This could be optimized by consolidating these checks into a single loop to reduce the computational overhead.

Code feedback:

That was literally one things we fixed, not an issue to be reviewed...

@tonypls tonypls enabled auto-merge (squash) July 3, 2024 13:12
@tonypls tonypls merged commit 923aa25 into master Jul 3, 2024
20 checks passed
@tonypls tonypls deleted the tonyvanswet/avo-282-update-estimation-pill-to-say-preliminary-for branch July 3, 2024 13:15
@VIKTORVAV99
Copy link
Member

Was this a accidental change we made here?
image
It should not say imprecise here but rather show the estimated percentage like the other badge.

@tonypls
Copy link
Collaborator Author

tonypls commented Jul 4, 2024

Was this a accidental change we made here? image It should not say imprecise here but rather show the estimated percentage like the other badge.

Good spotting, I'll look into it!

@tonypls
Copy link
Collaborator Author

tonypls commented Jul 4, 2024

Was this a accidental change we made here? image It should not say imprecise here but rather show the estimated percentage like the other badge.

Good spotting, I'll look into it!

Fix here: #6953

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants