Skip to content

feat: Add flexibility to PriceTotalStats #1059

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

Conversation

AshutoshKhadse23
Copy link
Contributor

Closes: #1058

Added all 50 fields.
And provide the flexibility.
This is how it will look :

final stats = PriceTotalStats.fromJson(jsonData);

final priceCount = stats.priceCount;

final someNewField = stats.getInt('some_new_field');

if (stats.containsKey('another_new_field')) {
  final value = stats.getString('another_new_field');
}

final allKeys = stats.availableKeys;

@AshutoshKhadse23 AshutoshKhadse23 requested a review from a team as a code owner April 17, 2025 20:05
@AshutoshKhadse23 AshutoshKhadse23 changed the title add: flexibility to PriceTotalStats fea: Add flexibility to PriceTotalStats Apr 17, 2025
@AshutoshKhadse23 AshutoshKhadse23 changed the title fea: Add flexibility to PriceTotalStats feat: Add flexibility to PriceTotalStats Apr 17, 2025
Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @AshutoshKhadse23!
As you may have already understood from openfoodfacts/smooth-app#6553, your solution is a bit too complex.
Let's focus on openfoodfacts/smooth-app#6553 first.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 58.87097% with 51 lines in your changes missing coverage. Please review.

Project coverage is 75.54%. Comparing base (820d145) to head (1e78f3b).
Report is 102 commits behind head on master.

Files with missing lines Patch % Lines
lib/src/prices/price_total_stats.g.dart 71.42% 28 Missing ⚠️
lib/src/prices/price_total_stats.dart 11.53% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1059      +/-   ##
==========================================
- Coverage   76.34%   75.54%   -0.81%     
==========================================
  Files         239      264      +25     
  Lines        8494    10031    +1537     
==========================================
+ Hits         6485     7578    +1093     
- Misses       2009     2453     +444     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AshutoshKhadse23
Copy link
Contributor Author

@monsieurtanuki ,
I tried the simpler approach but was having issues with the autogenerated file price_total_stats.g.dart

@monsieurtanuki
Copy link
Contributor

@monsieurtanuki , I tried the simpler approach but was having issues with the autogenerated file price_total_stats.g.dart

@AshutoshKhadse23 Good news: we don't need price_total_stats.g.dart and JsonSerializable in that specific case.
More generally speaking, we're sort of migrating to a less strict structure, cf. #1056. We need more flexibility.

@AshutoshKhadse23
Copy link
Contributor Author

@monsieurtanuki ,
I’ve updated the code with a simpler approach, removing price_total_stats.g.dart and JsonSerializable as they’re no longer needed.

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Thank you @AshutoshKhadse23!

The point of the issue was to provide flexibility, and with a visible json field we have all the flexibility we need.

The getInt method makes sense too, as it's frequently used.

My initial thought was to use constants (or methods) as tags, and no getters. Another solution is to implement all getters.
You implemented both, with is more than enough.

I think we'd be better off with the getters and without the constants.
What do you think of it?

@AshutoshKhadse23
Copy link
Contributor Author

@monsieurtanuki, I agree with you and changed the code with the getters and without the constants.

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Thank you @AshutoshKhadse23, and congratulations for your first PR in this specific project!

@github-project-automation github-project-automation bot moved this from In progress to Reviewer approved in Dart package - Support for new APIs and issues Apr 19, 2025
@monsieurtanuki monsieurtanuki merged commit 3f29110 into openfoodfacts:master Apr 19, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add flexibility to PriceTotalStats
3 participants