Comments (5)
Working on it...
from smooth-app.
It would be great to do it in exactly the same way as the Javascript implementation:
// match_product_to_preference checks if a product matches
// a given set of preferences and scores the product according to
// the preferences
//
// The product object must contain the attribute_groups field
//
// Output values are returned in the product object
//
// - match_status: yes, no, unknown
// - match_score: number (maximum depends on the preferences)
// - match_attributes: array of arrays of attributes corresponding to the product and
// each set of preferences: mandatory, very_important, important
function match_product_to_preferences (product, product_preferences) {
var score = 0;
var status = "yes";
var debug = "";
product.match_attributes = {
"mandatory" : [],
"very_important" : [],
"important" : []
};
if (product.attribute_groups) {
// Iterate over attribute groups
$.each( product.attribute_groups, function(key, attribute_group) {
// Iterate over attributes
$.each(attribute_group.attributes, function(key, attribute) {
if ((! product_preferences[attribute.id]) || (product_preferences[attribute.id] == "not_important")) {
// Ignore attribute
debug += attribute.id + " not_important" + "\n";
}
else {
if (attribute.status == "unknown") {
// If the attribute is important or more, then mark the product unknown
// if the attribute is unknown (unless the product is already not matching)
if (status == "yes") {
status = "unknown";
}
}
else {
debug += attribute.id + " " + product_preferences[attribute.id] + " - match: " + attribute.match + "\n";
if (product_preferences[attribute.id] == "important") {
score += attribute.match;
}
else if (product_preferences[attribute.id] == "very_important") {
score += attribute.match * 2;
}
else if (product_preferences[attribute.id] == "mandatory") {
score += attribute.match * 4;
if (attribute.match <= 20) {
status = "no";
}
}
}
product.match_attributes[product_preferences[attribute.id]].push(attribute);
}
});
});
}
else {
// the product does not have the attribute_group field
status = "unknown";
}
product.match_status = status;
product.match_score = score;
product.match_debug = debug;
}
from smooth-app.
@stephanegigandet There's a familiarity with the score computation in FilterRankingHelper
. What is the target: keep both computations? Replacing the current FilterRankingHelper
one with this one?
from smooth-app.
There's a familiarity with the score computation in
FilterRankingHelper
. What is the target: keep both computations? Replacing the currentFilterRankingHelper
one with this one?
The code in FilterRankingHelper was written before we had computations done directly in the server, so we should replace it with the logic from the JS code.
from smooth-app.
Done in #40.
from smooth-app.
Related Issues (20)
- Leverage the new deeplink to the Hunger Games Eco-Score dashboard by country
- Impossible to close the app ? HOT 2
- Light on light issue in light mode on dark mode device HOT 2
- Auto-completion for brands only works for the first one
- Set a random visitor ID at each requests instead of using 0000000… for anonymous analytics HOT 4
- Edition: we shouldn't suggest an item which is already in the list
- Update of all the local products from the server
- F-Droid build failed
- _ClientSocketException: ClientException with SocketException: Failed host lookup: 'static.openfoodfacts.org' (OS Error: N...
- Upgrade to flutter 3.19?
- Search History Keyword Tapping Doesn't work
- RankingFloatingActionButton partially off-screen for some translations
- User feedback HOT 2
- What else required to calculate Nutri-Score HOT 3
- Feedback from Alizarine @jusdekiwi HOT 1
- Nutrition table image not visible to edit values on mobile -> makes completion difficult from an image HOT 2
- no Best Before date on mobile HOT 1
- photo dates not visible on mobile, difficult to know the most up-to-date version HOT 10
- 🌅 GS1 "Sunrise 2027" - 2D Barcodes, GS1 Element String, and GS1 Digital Link URI support HOT 2
- In product addition mode, nothing happens when you try to click on the placeholder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smooth-app.