I have joined 92 groups in SoundCloud, but when I do an SC.get("/me/groups"....etc I only get 50 returned to me. When I do a
curl http://api.soundcloud.com/users/6999000/groups.json?client_id=MY_CLIENT_ID
I only get 50 results returned to me? Any way to get the full number of group entries returned?
There is an offset GET parameter that you can pass in order to retrieve tracks above the 50 items limit.
curl http://api.soundcloud.com/users/6999000/groups.json?client_id=YOUR_CLIENT_ID&offset=50
I hope this helps.
You can use a loop and offset to get all.
Pseudo code...
String url = "http://api.soundcloud.com/users/6999000/groups.json?client_id=MY_CLIENT_ID";
getGroups(url);
int count = 50;
String newUrl = "http://api.soundcloud.com/users/6999000/groups.json?client_id=MY_CLIENT_ID&offset=50";
while( count < 92) {
getGroups(newUrl);
count = count + 50;
}
Look at http://developers.soundcloud.com/docs#pagination for more information on offsets.
Related
The datagrid that I use on the client is based on SQL row number; it also requires a total number of pages for its paging. I also use the PagedList on the server.
SQL Profiler shows that the PagedList makes 2 db calls - the first to get the total number of records and the second to get the current page. The thing is that I can't find a way to extract that total number of records from the PagedList. Therefore, currently I have to make an extra call to get that total which creates 3 calls in total for each request, 2 of which are absolutely identical. I understand that I probably won't be able to rid of the call to get the totals but I hate to call it twice. Here is an extract from my code, I'd really appreciate any help in this:
var t = from c in myDb.MyTypes.Filter<MyType>(filterXml) select c;
response.Total = t.Count(); // my first call to get the total
double d = uiRowNumber / uiRecordsPerPage;
int page = (int)Math.Ceiling(d) + 1;
var q = from c in myDb.MyTypes.Filter<MyType>(filterXml).OrderBy(someOrderString)
select new ReturnType
{
Something = c.Something
};
response.Items = q.ToPagedList(page, uiRecordsPerPage);
PagedList has a .TotalItemCount property which reflects the total number of records in the set (not the number in a particular page). Thus response.Items.TotalItemCount should do the trick.
Given:
CellTable<List<String>> table = new CellTable<List<String>>();
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDataDisplay(table);
List<List<String>> list = dataProvider.getList();
what is the simplest code to count total of rows in a celltable?
if getRowCount not working , why dont you try to get the size of the array u have , you must be pushing some array in the celltable , why don't just get the size of array ..
getRowCount() ??
Get the total count of all rows.
getVisibleItemCount()
Get the number of visible items being displayed. Note that this value might be less than the page size if there is not enough data to fill the page.
and also see the method getVisibleRange() which returns range oobject and then you can get by range.getLength()
I have a mongo collection with documents. There is one field in every document which is 0 OR 1. I need to random sample 1000 records from the database and count the number of documents who have that field as 1. I need to do this sampling 1000 times. How do i do it ?
For people coming to the answer, you should now use the new $sample aggregation function, new in 3.2.
https://docs.mongodb.org/manual/reference/operator/aggregation/sample/
db.collection_of_things.aggregate(
[ { $sample: { size: 15 } } ]
)
Then add another step to count up the 0s and 1s using $group to get the count. Here is an example from the MongoDB docs.
For MongoDB 3.0 and before, I use an old trick from SQL days (which I think Wikipedia use for their random page feature). I store a random number between 0 and 1 in every object I need to randomize, let's call that field "r". You then add an index on "r".
db.coll.ensureIndex(r: 1);
Now to get random x objects, you use:
var startVal = Math.random();
db.coll.find({r: {$gt: startVal}}).sort({r: 1}).limit(x);
This gives you random objects in a single find query. Depending on your needs, this may be overkill, but if you are going to be doing lots of sampling over time, this is a very efficient way without putting load on your backend.
Here's an example in the mongo shell .. assuming a collection of collname, and a value of interest in thefield:
var total = db.collname.count();
var count = 0;
var numSamples = 1000;
for (i = 0; i < numSamples; i++) {
var random = Math.floor(Math.random()*total);
var doc = db.collname.find().skip(random).limit(1).next();
if (doc.thefield) {
count += (doc.thefield == 1);
}
}
I was gonna edit my comment on #Stennies answer with this but you could also use a seprate auto incrementing ID index here as an alternative if you were to skip over HUGE amounts of record (talking huge here).
I wrote another answer to another question a lot like this one where some one was trying to find nth record of the collection:
php mongodb find nth entry in collection
The second half of my answer basically describes one potential method by which you could approach this problem. You would still need to loop 1000 times to get the random row of course.
If you are using mongoengine, you can use a SequenceField to generate an incremental counter.
class User(db.DynamicDocument):
counter = db.SequenceField(collection_name="user.counters")
Then to fetch a random list of say 100, do the following
def get_random_users(number_requested):
users_to_fetch = random.sample(range(1, User.objects.count() + 1), min(number_requested, User.objects.count()))
return User.objects(counter__in=users_to_fetch)
where you would call
get_random_users(100)
I've been looking at this tutorial http://www.codediesel.com/php/reading-google-analytics-data-from-php/ but am struggling as I only want to retrieve the total number of unique visitors which is a metric.
It appears that you have to use a 'dimension' to get the 'metric' when using their API.
Any ideas on how I can avoid using a dimension as all I want is the total.
Thanks
Dimension is not mandatory.
Use:
Metric: ga:visitors and do mention the start-date and end-date to get the data in the desired range, which is required.
You will get the desired total.( P.S. The calculation of ga:visitors has been changed to return the number of unique visitors across the date range )
$analytics = new Google_Service_Analytics($client);
$profileId = 'UA-00000000-1';
$yesterday=$startDate=$endDate=date("Y-m-d", time() - 60 * 60 * 24 );
$metrics = 'sessions';
$results = $analytics->data_ga->get('ga:'.$profileId, $startDate, $endDate, 'ga:'.$metrics);
Requires - https://github.com/google/google-api-php-client
I got a lucene.net index with bunch of documents. I pull these with MVC request and return to client as JSON. I want to return only top N documents starting from index I want. I need that to minimize data flow between server and client.
What I need is something like:
1) First query- Get top 20 docs
2) Second query - Get top 20 docs beginning from 20 - would be 21 - 41
3) .... and so on
Lucene allows me to set top items. But it only count those from the beginning from the index. Is there a build-in possibility to set start index for that ? Probably some advanced Indexer I am missing in lucene.net or something..
Thanks!
Take a look at this blog that explains pagination in lucene.
The crux of it is this:
int start = 20; int pageSize = 20;
Query query = qp.parse(searchTerm);
TopDocs hits = searcher.search(query, maxNumberOfResults);
for (int i = start; i < start + pageSize && i < hits.Length(); i++) {
int docId = hits.scoreDocs[i].doc;
}