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

Nutrition facts: check values before sending them #4446

Open
10 tasks
Tracked by #511
g123k opened this issue Aug 4, 2023 · 2 comments
Open
10 tasks
Tracked by #511

Nutrition facts: check values before sending them #4446

g123k opened this issue Aug 4, 2023 · 2 comments

Comments

@g123k
Copy link
Collaborator

g123k commented Aug 4, 2023

Hi everyone,

Currently, we don't check what is in the nutrition screen, whereas on the website we have multiple checks.

Tasks

@monsieurtanuki
Copy link
Contributor

Energy should not exceed 3800 kJ

Yes it should: I eat what I want to eat! 😉

@teolemon
Copy link
Member

Asked Gemini Advanced to give it a first jab

import 'dart:math';

/// Check the relation between kJ and kCal
bool isValidEnergyRelation(double kJ, double kCal) {
  // The relation should be approximately 4.184 kJ per kCal
  double expectedKCal = kJ / 4.184;
  return (kCal - expectedKCal).abs() <= 0.1; // Allow small tolerance
}

/// Ensure energy does not exceed 3800 kJ
bool isValidEnergy(double kJ) {
  return kJ <= 3800;
}

/// Ensure fat does not exceed 100g
bool isValidFat(double fat) {
  return fat <= 100;
}

/// Ensure saturated fat does not exceed total fat
bool isValidSaturatedFat(double saturatedFat, double fat) {
  return saturatedFat <= fat;
}

/// Ensure carbohydrates do not exceed 100g
bool isValidCarbohydrates(double carbohydrates) {
  return carbohydrates <= 100;
}

/// Ensure sugars do not exceed total carbohydrates
bool isValidSugars(double sugars, double carbohydrates) {
  return sugars <= carbohydrates;
}

/// Ensure fibers do not exceed 100g
bool isValidFibers(double fibers) {
  return fibers <= 100;
}

/// Ensure proteins do not exceed 100g
bool isValidProteins(double proteins) {
  return proteins <= 100;
}

/// Compute sodium from salt and check if it's valid
double computeSodium(double salt) {
  return salt * 0.393; // 39.3% of salt is sodium
}

bool isValidSalt(double salt) {
  return salt <= 2.5;
}

/// Generic function to check if a nutrient does not exceed 100g
bool isValidNutrient(double nutrient) {
  return nutrient <= 100;
}

@teolemon teolemon added the good first issue Good for newcomers label Jun 18, 2024
@teolemon teolemon removed the ✨ enhancement New feature or request label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 💬 To discuss and validate
Status: To do
Development

No branches or pull requests

3 participants