Giter Site home page Giter Site logo

Comments (5)

monsieurtanuki avatar monsieurtanuki commented on May 21, 2024 1

Working on it...

from smooth-app.

stephanegigandet avatar stephanegigandet commented on May 21, 2024

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.

monsieurtanuki avatar monsieurtanuki commented on May 21, 2024

@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.

stephanegigandet avatar stephanegigandet commented on May 21, 2024

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?

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.

monsieurtanuki avatar monsieurtanuki commented on May 21, 2024

Done in #40.

from smooth-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.