What I like about my solution is you can just let the db compute the 
average of the ratings for any given user when it's needed.

Admittedly this gets a little hairy if you want to rank sellers according 
to rating in an index list, or show the ratings in such a list. 

On Monday, October 14, 2013 4:26:42 PM UTC-4, Niphlod wrote:
>
> Things can get messy in no-time with a field that is constantly 
> recalculated every time (e.g.) a row gets inserted into the "ratings" table.
> Plan carefully those "updating functions" because if that function takes 
> 0.15 sec to execute, than you incur in AT LEAST 0.15 sec delay for every 
> insert/update/delete out there.
> The way to go for "real-time" is using DAL callbacks 
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callbacks
>
> I'd instead go for a scheduled function that every n minutes recalculates 
> what is there to recalculate (and I'll plan carefully that too).
>
>
> On Monday, October 14, 2013 10:12:26 PM UTC+2, Apple Mason wrote:
>>
>> Suppose I have three different types of users: buyer, distributor, and 
>> reseller.
>>
>> All buyers, distributors, and resellers have an email, password, and 
>> ratings. Since email and password are already part of auth_user, the 
>> ratings Field will be an extra field in auth_user.
>>
>> To separate the user roles, we can user auth_membership and auth_group to 
>> designate an auth_user as a 'buyer', 'distributor', or 'reseller'. 
>>
>> Although each user role uses the same backend code for storing email and 
>> password (through auth_user), how would one go about storing a custom 
>> rating mechanism for each user role?
>>
>> For example, let's say:
>>
>> A buyer is rated with some combination of # of product reviews written 
>> and credible purchase history.
>>
>> A reseller is rated with some combination of buyer reviews and warranty 
>> service.
>>
>> A distributor is rated with reseller reviews.
>>
>> Assuming I have the following functions which returns on an integer with 
>> range 1 - 100 for ratings:
>>
>> def buyer_calc_rating():  # Random calcluation for this example
>>      comment_num = len(db(db.comments.user == db.buyer.id).select())
>>      purchase_history = #... some calculation that returns int
>>
>>      return comment_num + purchase_history
>>
>> def reseller_calc_rating();   # Assume similar calculation returns int
>> def distributor_calc_rating();  # Assume similar calculation returns int
>>
>> I have two questions:
>>
>> - How would I go about assigning these functions to user's ratings Field 
>> in auth_user?
>>
>> - How would the ratings be dynamically updated each time something 
>> changes pertaining to rating calculation (ie, when a buyer rates a seller, 
>> etc)?
>>
>>    Would the preferred way be to stick the above functions in a module 
>> which is then called wherever some controller function changes ratings? I 
>> would always get an update-to-date rating on the user this way (simply by 
>> querying 'db.auth_user.rating'), but that would also be a code-maintanence 
>> nightmare since I would have to keep track of all the places in the code 
>> that manipulates ratings?
>>
>> Thanks in advance.
>>
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to