I'm trying to do a formula in Infopath:
Say i have 3 fields called singles, 10's and 25's.
I also have another field where the user typed in a number.
If the user types in 15 for example, this should fill in the 10's filed with 1, and the singles field with 5.
If the user typed 49 into the field, then the 25's would be filled with 1, the 10's with 2, and the singles with 4.
If they type in 50, then the 25's field will be filled with 2.
Does anyone have any idea where I could start in doing this?
Many thanks in advance.
Jason
Here is the basics of the solution (which was quickly verified in IP). I leave the math specifics up to you just in case this is a HW problem. If you have specific troubles post back and we can help.
Set a rule on your input field with no conditions so it will fire anytime the field changes.
Use the number function on a field to be able to use it in calculations. Infopath doesn't have a mod function so do divide with floor and subtraction.
Create an action for each amount (making sure to order them by highest first).
So for example your 25s field action would be floor(number(inputfield) / 25).
Your 10s action would be floor(number(inputfield) - number(25sfield) * 25) / 10).
Etc for each one (and note that the ones field is just whatever is leftover - no divide or floor needed).
Related
I need to make some percentage fields, but I cannot make them like I need.
In total there will be 5 fields, with user input data format XXX%.
The first issue it that the fileds in total should sum 100% else an error message should appear.
The second issue, has to do with field format. The user should input 5 and the field should make it 005%.
Accordingly, user input 10 -> 010% and finally 100 -> 100%
Of course, the maximum input number should be the "100".
Any help?!?
Thank you in advance!
I assume the sum field total is calculated automatically using the calculate event, in that case you can use Javascript to display an error if all the field are filled and the total is not equal to 100.
For the dislpay, you need to use patterns, see documentation at : http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000490.html
For data validation, you can use validate event on the fields or manually check the value on the exit event of the field.
i have a content type and the possibility for logged in users to vote on it. there are 5 different fivestar votings (categories) on the node. now i want to add userpoints and wanted to ask if it is possible that when a user votes that he gets 1 point for every vote on a node, so 5 points if he votes in every category. he has the possibility to change the vote later, but then he shouldn´t get any points anymore. is this possible?
greets
While it doesn't look like there is an existing 7.x or 8.x module that accomplishes this, there are two ways you should be able to accomplish your goal:
Write a module. The Userpoints API is fairly well-documented and it should be possible to create a module to increment a user's userpoint count when a fivestar field is modified. To avoid duplication, note that this field looks like it should accomplish the de-duping you are looking for (assuming you set txn_id to some combination of the current node ID, field ID, and user ID:
'txn_id' => (int) Transaction ID of a current points record. If
present an UPDATE occurs
Use Rules. The userpoints module integrates with Rules, so you should be able to accomplish your userpoints use case without writing any code. According tho the Userpoints Rules integration notes, you can compare the current userpoints to the number of points before the transaction:
Compare Userpoints before the transaction
- This condition is used to compare the amount of userpoints the user had before the userpoints was added to/deducted from the user against a specified value.
- The 'Amount to compare' value is checked as >= (greater than or equal to) and the Negate checkbox will change the condition to < (less than) as it will be any value other than >=. If you would like to get an exact value, say 1, you can add two of the condition to use >= and < to specify one number. Simple math stuff here =)
I hope this helps. Let me know how it goes!
NewBee here. I am looking for a tutorial, article or sample code that details using first, last, next and previous buttons to display records from an SQLite database. Thanks in advance for your help, Jim
Look at the LIMIT and OFFSET clauses of SELECT:
http://www.sqlite.org/lang_select.html
All you need to do to build your pager device is to do a SELECT limiting to, say, 20 results, and supply an offset which is (page - 1) * 20. Your previous/next will decrement/increment your page number, and your first/last will set page to 1 or its maximum value respectively.
It is easy to calculate a sum, an average or a maximum accross set of fields using built-in xpath functions.
But is it possible to calculate a product?
Assuming I have repeating elements like
<my:table>
<my:row>
<my:value>10</my:value>
</my:row>
<my:row>
<my:value>20</my:value>
</my:row>
<my:row>
<my:value>30</my:value>
<my:row>
</my:table>
(the number of my:rows may vary).
i need to have a formula multiplying all my:values: 10*20*30 (and working with any number of rows).
Any ideas?
Please do not suggest code solutions, I need this for a restricted form.
Using conditional hack described here, I finally assembled the solution.
Inside my:row, create a running product field my:valueCumul, populated using a formula to refer to previous row, and leveraging the conditional hack to override NaN for the first row:
../my:value *
concat(
(count(../preceding-sibling::my:row[1]) = 0) * 1,
substring(../preceding-sibling::my:row[1]/my:valueCumul, 1, (count(../preceding-sibling::my:row[1]) = 1) * string-length(../preceding-sibling::my:row[1]/my:valueCumul))
)
Outside the table you can easily refer to my:valueCumul in the last row to get total product:
../my:row[count(../my:row)]/my:valueCumul
The nice features of this solution are:
Works in a browser form in any sharepoint environment
Is not impacted by "16 calculations" threshold
The formula is robust to row removal and shifts
You can't with the built in functions in InfoPath.
However, don't write off a code solution so fast. If you only access data elements in the form itself (nothing EXTERNAL) then you can leave the form as restricted security and the code will run with no problems - the user doesn't know the difference.
It is fairly trivial to attach to the right event, grab the nodes, and loop through them while multiplying. You don't even have to use managed code - use one of the script options. Comment back (or update your original post) if you run into any troubles and we can help resolve them.
I've got a list of items. Users can occasionally select them. Now I want to order the items by their popularity. What's a good weighting function for that?
Constraints:
The weight should be in [0,1)
Recursive calculation is prefered (not required)
Newer events must have more influence than old ones.
I'd favor approved functions. As I've developped something like this once and it worked not as expected.
Now I want to order the items by their popularity.
So you order by the number of times some user selected the item.
The weight should be in [0,1).
Fine, divide by the total number of times some user selected some item plus one.
Recursive calculation is prefered
Why? Maybe I'm missing the point of what you're trying to do because otherwise this constraint is lost on me.
Edit:
Responding to your edit, try
sum ( 1 / age of vote ) / age of item
the sum being taken over all votes for a given item.
If you have a counter of votes per item, you can use a 'fading constant' in order to make older votes "fade away" with time. Something like:
Nvotes(i) = IsClicked(i) + Nvotes(i) * Kfade
where: 0 < Kfade < 1
Thus, whenever a new click is intercepted, all counters are advanced where only the selected item is incremented by 1.
EDIT: Since the total is less than 1, you may want to normalize Nvotes by the total number of clicks so far.
Keep a list items of the items that need sorting. Let each item have a score. Keep a list clicks of the N most recent clicks, in order of decreasing recency. Each item can appear more than once in the list. Choose a constant fade a little smaller than 1. Then do:
for item in items:
item.score = 0.0
bonus = 1.0
for item in clicks:
item.score += bonus
bonus *= fade
Now sort the items by score, highest first.
The score isn't in the range 0 to 1, but i don't see why you actually need that. It would be straightforward to normalise the scores afterwards.
This isn't recursive, but it's straightforward to put in recursive form.
This isn't a known algorithm. I don't know of any known algorithms for this except move-to-front, which is almost certainly more aggressive than you want.