float support

gdoteof - March 30, 2009 - 02:47
Project:User Points
Version:6.x-1.x-dev
Component:Code: userpoints API
Category:feature request
Priority:normal
Assigned:gdoteof
Status:needs review
Description

As we discussed, I needed float support. It seems to be working fine.

The patch basically changes every reference to points or max_points from an int to a float, and updates the .install file to alter the database so the point columns are floats instead of ints.

AttachmentSize
addFloat.patch9.8 KB

#1

jredding - March 30, 2009 - 05:21

The patch is welcomed but it has problems.

each .install update is marred with this typo change

- db_change_field($ret, 'userpoints_txn', 'tid', 'tid', array('type' => 'int', 'not null' => true, 'default' => 0, 'length' => 11));
- db_change_field($ret, 'userpoints', 'tid', 'tid', array('type' => 'int', 'not null' => true, 'default' => 0, 'length' => 11));
+ db_change_field($ret, 'userpoints_txn', 'tid', 'tid', array('type' => 'int', 'not null' => true, 'default' => 0, 'lenght' => 11));
+ db_change_field($ret, 'userpoints', 'tid', 'tid', array('type' => 'int', 'not null' => true, 'default' => 0, 'lenght' => 11));

note the 'lenght' misspelling for the last db_change_field. each update has this error.

Can you please fix this error and reroll the patch.

Thanks

#2

gdoteof - March 30, 2009 - 14:28

oops. i even brought up the typo in the first place :). with typo fixed

AttachmentSize
addFloat2.patch 6.44 KB

#3

kbahey - March 30, 2009 - 16:48

Reviewed visually and removed some stray files and hunks.

Here is the reformatted version.

AttachmentSize
convert-to-float.patch 5.03 KB

#4

jredding - April 4, 2009 - 09:12

visual once-over looks good to me, I'm excited for it.

#5

jrust - June 15, 2009 - 21:53

Huge +1 for this one -- makes purchasing with point via Ubercart possible without having to round the order total. Applied the patch and it worked fine, except for one problem that arises due to using floats:

Once you add or subtract float points i.e. (50.54), then you start getting lots of digits for values like "Approved points balance" on the /myuserpoints page. This is because when MySQL does SUM() on a FLOAT column it pulls numbers with lots of numbers after the decimal point because floating point numbers are only approximate. So, two options: use DECIMAL instead or round the values in the summary.

#6

kbahey - June 24, 2009 - 17:14
Status:needs review» needs work

#7

jrust - June 25, 2009 - 23:54
Status:needs work» needs review

Attached is a patch that adds a setting specifying what precision to display and then formats the points when they are displayed with that level of precision.

AttachmentSize
417830-float-with-precision.patch 8.49 KB

#8

jrust - July 2, 2009 - 00:36

Adding a revised patch that fixes some bugs that showed up when users had more than 1000 points.

AttachmentSize
417830-float-with-precision-2.patch 7.52 KB

#9

kbahey - July 18, 2009 - 22:10

I want to commit this, but due to the fact that most contrib will not work properly until they deal with floats, I think that we should branch t 6.x-2.x-dev (DRUPAL-6--2) then commit this.

That is unless some kind soul(s) volunteer their time to changing all userpoints_contrib that are in 6.x-1.x-dev to the new API and make it ready for commit when I am ready.

What does everybody think?

 
 

Drupal is a registered trademark of Dries Buytaert.