incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Hallett <halle...@gmail.com>
Subject Re: Best way to handle data? Advice wanted
Date Mon, 31 Aug 2009 15:54:20 GMT
Not sure I understand completely; but it sounds like part of Andrew's
problem is tracking time for tasks that, in some time zone, start on one day
and finish on another day.  When calculating time for day 1, you only want
to include the portions of tasks that took place on day 1 - you don't want
the portions that extended into day 2.

I can think of two approaches to this issue.  One is to create a map
function that lists time spent for every hour.  For each task document emit
a key for the top of every UTC hour during which the task was active.  For
the values emit the number of hours the task was active during that hour.
Your view rows might look like this:

    [["2009", "08", "31", "09"], 0.3],
    [["2009", "08", "31", "10"], 1],
    [["2009", "08", "31", "11"], 1],
    [["2009", "08", "31", "12"], 0.5],

When performing a query work out the start and end times you want to the
nearest hour, translate those to UTC, and use the result as your start and
end keys.  But subtract 1 hour from the end key.  The query will hit your
reduce function which sums the values for each view row.

The other approach is to create a view that indexes time spent by day.  But
choose a canonical time zone that will be used for all time reporting.

On Aug 31, 2009 5:35 AM, "Simon Metson" <simonmetson@googlemail.com> wrote:

Hi,
       As your timestamps are just int's they're nicely sortable. Make a
view like:

function(doc) {
 emit(doc.timestamp, doc);
}

and query it like:

http://localhost:5984/test/_design/timestamp/_view/sort?startkey=12344&endkey=12347

which will give you documents with a timestamp between 12344 and 12347.
Cheers
Simon

On 31 Aug 2009, at 01:30, Andrew Mee wrote: > I have been using CouchDB
(trunk) for a couple of w...

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message