incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kowsik <kow...@gmail.com>
Subject Re: Filtering a cloud of points
Date Wed, 04 Mar 2009 14:59:01 GMT
I was playing around with time slices and I see some similarities
here. Here's kinda how my docs look:

{
    start: 123345,
    ...
}

where start is in seconds (say). It's now possible to do this (call
this view 'time/slice'):

map: function(d) {
    emit('1m', Math.floor(d.start/60));
    emit('5m', Math.floor(d.start/60/5));
    emit('10m', Math.floor(d.start/60/10));
    emit('1h', Math.floor(d.start/60/60));
}

reduce: function(k, v) {
    return sum(v);
}

What this does is essentially chunk up the time into 1-dimensional
segments (of different granularity). This allows the application to
query time slices very easily like so:

_view/time/slice?startkey=['1h']&endkey=['1h',{}]&group=true

This gives me high level 1hr regions and a count of all documents that
fall into each hour. If you now want to "zoom in", here's what you do:

_view/time/slice?startkey=["1m",5]&endkey=["1m",10]&group=true

This returns all documents that fall within the 5 - 10 minute segment.
I'm sure you can partition the 2D space in similar ways using numbered
cells chunked up by some quantity. So your map might look like this:

map: function(d) {
    emit(['10x10xy', Math.floor(d.x/10), Math.floor(d.y/10)], 1);
    emit(['10x10yx', Math.floor(d.y/10), Math.floor(d.x/10)], 1);
}

So if you want to find out the count of documents in y-axis 50 between
x-axis 10 to 20, you could do this:

_view/cell/slice?startkey=["10x10yx", 5, 1]&endkey=["10x10yz", 5, 2]&group=true

Hope that helps,

K.

On Wed, Mar 4, 2009 at 6:36 AM, Jason Davies <jason@jasondavies.com> wrote:
> Hi Manuel,
>
> On 4 Mar 2009, at 11:19, Manuel UGFkcsOzbiBNYXLhcnTDrW5leg== wrote:
>
>> And tried to filter with start - end key (for example :
>> startkey=[[1],[0]]&endkey=[[3],[5]]) but I
>> get points that are out of region (like [[1][9]]).
>> I've also tried with objects, simple vectos ([X,Y]) and still the same
>> results.
>>
>> Anyone knows how to solve it? There any way ? Or should I make a view for
>> X coordinate, another for Y
>> coordinate and try to make a ""join"" in my program?
>
>
> CouchDB's views produce a linear (one-dimensional) keyspace, so
> multi-dimensional queries like this are currently not possible, unless, as
> you say, you do two separate queries on the X-keyspace and the Y-keyspace
> and then compute the intersection of the results in your client.
>
> There has been talk of supporting view intersections but at the moment this
> is still being discussed/dreamed of :-)  Essentially this would allow us to
> do a single query that performs two view queries on separate linear
> keyspaces and then intersects them server-side.  The obvious advantage here
> is that the discarded data doesn't needlessly get transferred across the
> wire.
>
> --
> Jason Davies
>
> www.jasondavies.com
>

Mime
View raw message