I wish I could give you guys some code but this question is more of a math problem and doesn't need code to solve.
I'm trying to find a number. The number shows the total count of users who have created Posts. Say my app has 25 posts and those posts come from 4 different users, then the count equals 4. How can I get this count??
The count is for this
#collections = Collection.all
Finding the number of users who have created a Collection.
Thanks so much.
You can do this:
Collection.distinct.count(:user_id)
This will execute a count query and only return the number of unique users who created a Collection.
Related
I am working on an application that retrieves the posts from firebase. The problem is I want to retrieve the first 20 posts and show in a table. When a user clicks the next button, it will retrieve the next 20 posts and show and so on.
I know firebase provides the following methods
queryLimitedToFirst
queryLimitedToLast
queryStartingAtValue
queryEndingAtValue
queryEqualToValue
But how do I use them in conjunction to retrieve the desired results like I want?
Here is the structure of the data I have:
You should order query by some property (I usually use timestamp). This organises your orders from latest to oldest. When you have them ordered you should limit them:
queryOrdered(byChild: "timestamp").queryLimited(toLast: UInt(limit))
As you can see we can limit results to whatever number we like. You can use this to read your posts each time for 20 results more.
So the first time you call it with a limit of 20, next time with a limit of 40, etc. Keep in mind that this will return posts that were already returned in the previous call.
Instead you could combine it with queryStartingAtValue and use your last post tiemstamp - this will "skip" your previous results and return only 20 posts you need.
This is just an idea but I think it should work like expected.
amazing experts.
I am still very new to Crystal, and only do it on the odd occasion, and seem to be going around in circles with this issue.
I work for a charity, and we would like to pull off a list of all our past donors who have not donated anything on the last 6 months.
I have tables for customer details, linked to another tables which shows their orders. They are linked based on the unique customer ID.
I have added all the customer orders, grouped by customer ID and then sported by OrderDate, and now I get stuck.
In my mind, I need to exclude anyone who has an order date that is less than 6 months old, and to do so I have tried using
{OrderDate} <= DateAdd ("m", -6, CurrentDate).
This however only seems to remove the customer orders that are less than 6 months old, not remove the customer records themselves.
I have tried using it both the "Select Expert" and also to suppress in the "Section Expert", but neither seem to be working to exclude the relevant Customer records.
I am certain there is a super easy way to do this, and I will kick myself when I know how to do it, but right now I have gone round the houses trying to find the solution.
So, if anyone out there has done this before and can help me out, i would greatly appreciate it.
Thank you all for your time!
this might solve your problem.
create a running summary field to count the number of rows return per group. if it is zero under the group section, under suppress , edit formula at put > 0
and run the report.
Let's say I have two collections: "Movies" and "Reviews." Users write reviews about movies and assign each movie a review score from 0 to 10. I want to make a list of the top 20 movies, based on each movie's average review score. Does anyone know how to set up the publish/subscription code? It's giving me the blues now. Everything I've read suggests this is a weak area for Meteor, and I can't seem to find a comparable example.
The solution is to store the average review score directly in the Movies collection and update it when a new review is added. This can be achieved by storing the total review score and number of reviews, which lets you update the average without having to retrieve all of the other reviews.
Update the average for a movie each time a review is posted and store that average in the movie document. It is more work at the time of creating the review, but querying the top 20 movies becomes trivial after that.
I had asked this question few days back but maybe as I was not clear as I didn't get much response.
let me try to rephrase my question to something like this:
I have few customers who are placing the orders with various products. and I am interested in knowing orders placed for various combinations of products and customers then bucket them into the number of orders last week, last fortnight, last month etc.
I am able to query the orders based on my criteria, but I am unable to understand how to then use this result in to data I need.
lets say my data is like this:
(c:Customer)<-[:PLACED_BY]-(o:Order)-[:HAS_PRODUCT]->(p:Product), (o)-[:PLACED_ON]->(d:Date)
and assuming that I have successfully found the Order's I am looking for, then how do I efficiently get the count i want out of these selected orders.
{... some queries that returns (o:Order) of interest ...}
With o
RETURN ??? as CountLastWeek, ??? as LastFortnight, ??? as LastMonth
BTW i also have OrderedDate property on the Order if that helps simplify the query.
is it even possible to achieve this in Cypher?
What you're looking to do is date time indexing. This is most certainly possible to achieve with Cypher.
You'll need to index your nodes via relationships. Each date is a day, you need to batch those into groups. Each day has a week that it is in, and a month that it is in. You just need to add in those groups to your dates and then aggregate on the collections of dates belonging to a week, a fort night, or a month.
I'm working on a research project which analyses closure patterns in social networks.
Part of my requirement is to collect followers and following IDs of thousands of users under scrutiny.
I have a problem with rate limit exceeding 350 requests/hour.
With just 4-5 requests my limit is exceeding - ie, when the number of followers I collected exceeds the 350 mark.
ie, if I have 7 members each having 50 followers, then when I collect the follower details of just 7 members, my rate exceeds.(7*50 = 350).
I found a related question in stackoverflow here - What is the most effective way to get a list of followers using Twitter4j?
The resolution mentioned there was to use lookupUsers(long[] ids) method which will return a list of User objects... But I find no way in the API to find the screen names of friends/followers of a particular "User" object. Am I missing something here.. Is there a way to collect friends/followers of thousands of users effectively?
(Right now, I'm using standard code - Oauth authentication(to achieve 350 request/hour) followed by a call to twitter.getFollowersIDs)
It's fairly straightforward to do this with a limited number of API calls.
It can be done with two API calls.
Let's say you want to get all my followers
https://api.twitter.com/1/followers/ids.json?screen_name=edent
That will return up to 5,000 user IDs.
You do not need 5,000 calls to look them up!
You simply post those IDs to users/lookup
You will then get back the full profile of all the users following me - including screen name.