I think that this module is a great idea - I can't believe that this has not made it into userpoints_contrib.

The functionality would provide exactly what I am looking for so I am keen to know whether anybody has/is attempting a port to D7?

Thanks, Shaun

CommentFileSizeAuthor
#11 1353442-totals.patch825 bytescafuego

Comments

cafuego’s picture

I'm not really using D7 yet, so I haven't looked at porting it. If the schema hasn't changed, I imagine it's mostly a matter of rewriting the queries to use the new database API layer.

migala’s picture

It would be interesting to port this module to D7.

Thanks a lot

dRaz’s picture

Hi Migala.

Do you mean you are interested in porting it or interested in a port (by someone else)?

migala’s picture

I can port it, but since my last comment I discover that the functionality of this module are implemented in userpoints so I think porting this module is not necessary.

Maybe I'm wrong.

dRaz’s picture

I do not see the functionality available within userpoints but am currently working on a workaround using rules.

Perhaps you can point out the error here as it all looks fine to me but is not working....

The rule basically:

When a user logs in, the system checks to see whether it has been (for testing purposes) 3 minutes or longer since they last logged in.

If it has then they lose 30 points.

My rule setup:

Event: user logged in

Condition: php: return intval((time() – $account->access)/60) > 3;
(this should allow the user 3 minutes interval where if they log in they will not be penalised)

Action: grant userpoints -30

It all seems fine to me but isn't working for some reason.

Can you point out the error please - it must be within the condition?

Thanks,

Shaun

cafuego’s picture

Assigned: Unassigned » cafuego
Status: Active » Needs review

A 7.x-1.x-dev release of the module should be available shortly. Please test :-)

cafuego’s picture

Version: 6.x-2.0-beta2 » 7.x-1.x-dev
dRaz’s picture

Testing now.....

EDIT:

Install - fine
Admin links - not present in the menu but can be found at admin/config/people/userpoints/evaporate
Configuaration saves.

Now have to wait an hour to see if it works :) .....

EDIT:

Points do not evaporate.

After an hour I ran cron, logged in my user (after an hour and 10 minutes) and the points were the same as before.

Still needs work here.

In the meantime, if you could help with the above code that I posted, we have a temp fix.

Thanks for your efforts,

Shaun

cafuego’s picture

Status: Needs review » Needs work

Points do not evaporate.
After an hour I ran cron, logged in my user (after an hour and 10 minutes) and the points were the same as before.

Can you check what the watchlog log says for userpoints_evaporate? I checked that the queries ran locally, and my installation does log that it has evaporated some points, but I didn't actually check that the points had gone, now that you mention it :-P
Will do so shortly :-)

In the meantime, if you could help with the above code that I posted, we have a temp fix.

I've not used Rules on D7, mainly because it's always given me errors and WSODs, so I can't help with that one...

cafuego’s picture

I see the problem, the named placeholder in the query that updates point totals is parsed as a string, so the query fails silently.

cafuego’s picture

Status: Needs work » Needs review
StatusFileSize
new825 bytes

The DB API is not cooperative and refuses to interpret the number of points to be deducted as an integer, so I've had to include the value in-line in the query, without using a placeholder.

That updates the totals for me when cron runs. A new 7.x-1.x-dev release will be built when d.o next does its cron builds.

If you need to test sooner, you can apply the attached patch to your 7.x userpoints_evaporate module.

dRaz’s picture

Good work Caf, I have made the changes, just waiting now to see if working.

Have you tested the "inactive only" function too??

dRaz’s picture

edit: see below

dRaz’s picture

Well, after leaving the "test" for 11 hours...

This morning I had the following results (bare in mind cron runs every 3 hours):

-10 Content Tue, 13/12/2011 - 22:32 Lost due to inactivity Approved view
-10 Content Tue, 13/12/2011 - 22:32 Lost due to inactivity Approved view
-10 Comments Tue, 13/12/2011 - 22:32 Lost due to inactivity Approved view
-10 Comments Tue, 13/12/2011 - 22:32 Lost due to inactivity Approved view

So, something is not working as it should.

I have the following settings:

Every hour, evaporate 10 points for users who have been inactive for over 1 hour.

What is the code to check for inactivity as I must be close with my rule condition?

We can have a workaround for this whilst the module is in dev if you can point out the error in my above code:

My rule setup:

Event: user logged in

Condition: php: return intval((time() – $account->access)/60) > 3;
(this should allow the user 3 minutes interval where if they log in they will not be penalised)

Action: grant userpoints -30

The same inactivity php logic is tryign to be used here?

Thanks,

Shaun

cafuego’s picture

Okay, I've set up a site in aegir to be able to test this thing properly. There were two problems I've found and (hopefully) fixed in regard to this issue:

  1. The transaction log query was not limiting its run to the specific category, but inserting transaction for ALL categories on each run through the loop. That would be *bad* :-)
  2. There's a new table, userpoints_total, which keeps a running total of the combined number of points, which wasn't be updated.

I've fixed the transaction insert query to only affect the specific points category on each run and added a query to update the total points per user in the userpoints_total table. Should be in the next available 7.x-1.x-dev release.

Also, I've moved the configuration to a tab on the userpoints module configuration.

dRaz’s picture

Good work Caf, all sounds very promising.

Have you tested the "inactive" users feature also?

On a personal note, that is what I will be using this module for - removing points from inactive users.

cafuego’s picture

Yup, it's been running on my system overnight and it *looks* to be working as intended. I have a category that expires 5 points for inactive users each hour and a category that expires 1 point for all users each hours.

Both have worked correctly for the past 13 hours. All users have lost an equal amount of the points that always evaporate, the admin user has lost less of the points that only expire for inactive users because I've been using it to check results.

That is the codebase I checked in over 12 hours ago, so the current 7.x-1.x-dev should include those fixes.

dRaz’s picture

I'll give it a test Caf :)

cafuego’s picture

I note that userpoints_no_negative was not ported to D7, so I'll add functionality to evaporate to set 'No negative' as option for each category... my users now have -6 points :-) ( #1372452: 'No Negative' function in D7 port)

dRaz’s picture

That sounds like a good idea.

An alternative may be to add a limit, so:

if user has 30> points then evaporate else don't evaporate

Shaun

dRaz’s picture

Ok the module seems to be working fine but I have a question about it's logic:

Settings:

lose 10 points every 1 day
inactive users only
inactive for 3 days.

How does the above work?:

a) if they are/have been inactive for 3 days they will lose 30 points when they log in (10 for every day they have been inactive)?
b) they will begin losing 10 points per day after 3 days?

I beleive it should work like b) but I have a feeling it is working like a)

Can you claify? Thanks.

Shaun

cafuego’s picture

The module works like "b" indeed.

It doesn't work on an event basis at all, the design is instead to minimise database load and bulk evaporate points for *all* affected users simultaneously. So the module rather than patching in to Rules, uses hook-cron and runs its code on every cron run.

If a user hasn't logged in for 3 days, the module starts evaporating 10 points per day for that user.

That means it runs two SQL queries for each of the configured categories in order to set points for *all* users. After that, it now runs one additional query to update the grand totals. It's designed that way to be able to quite quickly evaporate points on a site with tens of thousands of users without looping through a Rule (calling a userpoints API function) tens of thousands of times each cron run.

dRaz’s picture

Ok thank you.

The no-negative feature is definately required then in that case as new users may not log in for 3 days after creating their account and will be deducted points upon first login....

How are you getting on with that? :)

cafuego’s picture

Status: Needs review » Reviewed & tested by the community

That seems to be working, as the test users have 0 points in one category and -72 in the other :-)

I'll mark this issue as RTBC and add a patch to the nonegative issue (as well as commit to -dev).

migala’s picture

in admin/config/people/userpoints/settings you will see this tab:
"Expiration",
there are the userpoints expiration feature.

Still thinking porting this module is not necesary.

HIH

cafuego’s picture

Expiring a points transaction after a set period is not the same as expiring a fixed number of points repeatedly after a given time interval. Userpoints does the former, this module does the latter.

migala’s picture

Sorry, you're right.
I had not understood.

Thanks for your info.

cafuego’s picture

Status: Reviewed & tested by the community » Fixed

Pushed 7.x-1.0-beta1, which includes these fixes as well as the no-negative functionality.

Marking this issue as 'Fixed'.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.