Votingapi and vote up/down question - drupal

I have some nodes with a widget vote up/down. I can't understand how can i get integer votes value for various actions without sql requery. For example to hide nodes with rating < 10.

No matter what module you use,(Rate, Fivestar or anything else), all the data stored in Voting API module.
Using Rules module and VotingAPI Rules integration module you can check values of votes and take arbitrary(but possible) actions.
You may need to add new triggered rule on even "user votes on content" and check if the vote's value is < 10.
Voting API keeps data as a percentage so < 10 means < 10%. Vote count, value of each vote and percentage available as data.

Related

Firebase Dynamic Links Marketing Campaign dynamic_link_first_open filter event by parameter

I have created two Firebase Dynamic Links which has utm_source=twitter and utm_source=facebook.
After clicked the dynamic links, I able to see the dynamic_link_first_open events being logged, but the predefined audiences (dynamic_link_first_open count > 0, source = facebook / source = twitter) do not have any value (after one day).
Is this the correct way to filter the dynamic_link_first_open event by parameter?
Any steps I have missed?
The audience result should show up when the number of users that satisfy the audience filter is more than 10. Otherwise, it will show that there are < 10.

Top-50 click&time scored posts

We all know microscope from discovery meteor. The app is fine, it operates only with the number of upvotes. In the Best page it sorts posts by upvotes in descending order, upvote number is stored for each post and gets updated each time some user upvotes a post.
Imagine now we want to implement something like hacker news have - not only a click-based rating, but also a time-based rating. Lets now define that I will use word 'click' to describe an user action of clicking on post in the post list. This 'click' increases total number of clicks of this post by 1.
For thouse who do not knowe how hacker news algorithm work I will briefly explain. In common the total number of clicks of certain link (post) is divided by:
(T+2)^g
where T - total number of hours passed since post publishing time and now, and g is a "sensitivity" thing, lets call it that, which is just a number, 1.6, or 1.8, doesn't matter. This decrease influence of clicks as the time goes by. You can read more info (http://amix.dk/blog/post/19574)[here], for example.
Now, we want to have top-50 click&time-rated posts, so we need to query mongo to find all posts, sorted by score, calculated with formula from above.
I can see two major approaches to do so, and I find all of them quite bad.
First one, (the way I do now) subscribe to all posts, in template hepler prepare data for rendering by
rankedPosts: function() {
rawPosts = posts.find().map( function(item) { item.score = clicks/(T+2)^g; } ); // to add score for each post
rawPosts = _.sortBy( rawPosts, function(item) { return item.score*(-1); }) // to sort them by calculated score
rawPosts = _.first( rawPosts, 50 ); // to get only first 50
}
and then use rankedPosts for rendering. The bottleneck here is that each time I have to run through all posts.
Second one - somehow (I do not know how, or if it even possible) to subscribe for already scored/sorted/filtered collection, assuming meteor/mongodb can apply their magic to score/sort/filter (and recalculate score each new hour or new click) for me.
Now, obvious question, what will you recommend?
Thanks in advance.
Think about numbers. In a working page, you can have thousands of mosts, millions if the page is successful. Fetching all of them just to find the top 50 doesn't make sense.
I'd recommend storing the final calculated rating in a field. Then in subscription you apply sort by that field and desired limit. When post gain a new click, you simply recalculate the value and save it to db. Finally, in a cron job or meteor interval you update the rating of all items in the database.

Drupal 7 - Fivestar and Userpoints

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!

Pagination in application which use firebase.com as database

Front end application will use firebase.com as database.
Application should work like blog:
Admin add / remove posts.
There are "home" page which show several articles per page with "Next" and "Prev" buttons and page which show single article.
Also I need deep linking.
I.e. when user enter URL http://mysite.com/page/2/ I need that application show last articles from 10 to 20, when user enter URL http://mysite.com/page/20/ application show last articles from 200 to 210. Usual pagination.
Main question - is it possible to achieve this if use firebase.com.
I read docs at firebase.com, I read posts here. "offset()" and "count()" will be in the future, use priority, in order to know count of items and not load all of them use additional counter.
Based on this I suppose this:
ADD POST action:
get value of posts counter
set priority for new post data equals to value of posts counter
increase value of posts counter
DELETE POST action
get value of priority for post data
query posts data which have value of priority more than priority for post data which will be deleted and decrease their value
decrease value for posts counter
GET POSTS FROM x TO y
postsRef.startAt(null, x).endAt(null, y).on(... and so on)
Thing which I not like in this way are actions for DELETE POST. Because index of posts will be from 0 to infinity and post with less priority is considered as post which was created earlier so if I have 100000000 posts and if I need to delete 1st post then I need to load data for 99999999 next posts and update their priority (index).
Is there any another way?
Thanks in advance, Konstantin
As you mentioned, offset() will be coming, which makes your job easier.
In the meantime, rather than using startAt and endAt in combination, you could use startAt and limit in combination to ensure you always get N results. That way, deleted items will be skipped. You then need to check the last id of each page before moving to the next to find the proper id to start on.

filtering datagrids

In a simple scenario there is a webpage with a datagrid containing 2 columns; first name and country. There's a filter set on the grid to filter out all Australians. There's a form on the same page to add new records and a user decides to add someone from Australia. This record does not meet the filter criteria so would not normally display. However, this might be confusing from the users perspective as they might not have confidence that the person has been successfully added or have forgotten that the filter will mean the new entry is not displayed.
What is the best way to handle this from a usability perspective?:
display the new entry but leave the list in a state inconsistent
with the filter criteria?
filter out the new entry but risk confusing the user?
provide feedback to the user that the record was successfully
added but may be filtered out of the list?
?
Three tools I use, Mingle, Jira, and Quicken, use this implementation very effectively; a slight modification to your number 3:
Provide feedback to the user that the record was successfully added, but won't be shown, and provide a link to the record using its record identifier (record number + title).

Resources