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: Added robotoff nutrient extraction #1026

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

Conversation

PrimaelQuemerais
Copy link
Member

What

This PR adds the nutrient extraction Robotoff feature to the package

Part of

#738

@PrimaelQuemerais PrimaelQuemerais requested a review from a team as a code owner January 23, 2025 14:14
@PrimaelQuemerais PrimaelQuemerais changed the title Added robotoff nutrient extraction feat: Added robotoff nutrient extraction Jan 23, 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.

Thank you @PrimaelQuemerais for your PR!
Please have a look at my comments.

@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:openfoodfacts/src/model/robotoff_nutrient_extraction.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import 'package:openfoodfacts/src/model/robotoff_nutrient_extraction.dart';
import 'model/robotoff_nutrient_extraction.dart';

/// Get nutrient extraction insights for a given barcode
/// cf. https://robotoff.openfoodfacts.org/api/v1/insights
static Future<RobotoffNutrientExtractionResult> getNutrientExtraction(
String barcode, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
String barcode, {
final String barcode, {

@@ -1,4 +1,5 @@
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/src/model/robotoff_nutrient_extraction.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import 'package:openfoodfacts/src/model/robotoff_nutrient_extraction.dart';

That file should be included in openfoodfacts.dart.

@@ -1,7 +1,5 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

// ignore_for_file: deprecated_member_use_from_same_package
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep it there, we need it.

Comment on lines +6 to +7
@JsonSerializable()
class RobotoffNutrientExtractionResult extends JsonObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally speaking, I would prefer one file per class (I'm from Java) and an explicit Robotoff prefix for all class names.
Not the most important part of my review, though.

Comment on lines +108 to +109
final Map<String, List<NutrientEntity>>? entities;
final Map<String, NutrientEntity>? nutrients;
Copy link
Contributor

Choose a reason for hiding this comment

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

That String key is a vague.
Please consider adding getters with Nutrient and PerSize parameters.

expect(result.status, 'found');
expect(result.insights!, isNotEmpty);
expect(result.insights![0].barcode, barcode);
expect(result.insights![0].data!.nutrients!['fat_100g']!.value, '0.5');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nutrient + PerSize

final String? barcode;
final String? type;
final NutrientDataWrapper? data;
final String? timestamp;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that a date?

@JsonKey(name: 'id')
final String? insightId;
final String? barcode;
final String? type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there known types?

@JsonKey(name: 'n_votes')
final int? nVotes;
final String? username;
final List<String>? countries;
Copy link
Contributor

Choose a reason for hiding this comment

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

Localized countries? Country codes?

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.

2 participants