From user-return-20668-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Fri Apr 27 22:03:56 2012 Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A271FCC83 for ; Fri, 27 Apr 2012 22:03:56 +0000 (UTC) Received: (qmail 83091 invoked by uid 500); 27 Apr 2012 22:03:55 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 83035 invoked by uid 500); 27 Apr 2012 22:03:55 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 83025 invoked by uid 99); 27 Apr 2012 22:03:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Apr 2012 22:03:54 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [128.18.84.133] (HELO brightmail-internal4.sri.com) (128.18.84.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Apr 2012 22:03:47 +0000 X-AuditID: 80125485-b7f9a6d000000610-1f-4f9b17aeea9c Received: from exchange-hub01.SRI.COM (exchange-hub01.SRI.COM [128.18.23.153]) (using TLS with cipher AES128-SHA (AES128-SHA/128 bits)) (Client did not present a certificate) by brightmail-internal4.sri.com (SRI Internal SMTP Gateway) with SMTP id E8.76.01552.EA71B9F4; Fri, 27 Apr 2012 15:03:27 -0700 (PDT) Received: from EXCHANGE-DB08.SRI.COM ([fe80::58d8:a905:a3ba:cff3]) by exchange-hub01.SRI.COM ([fe80::4d8a:45c7:6965:e5f7%12]) with mapi id 14.01.0218.012; Fri, 27 Apr 2012 15:02:26 -0700 From: Jim Klo To: "" Subject: Re: Need some advice Thread-Topic: Need some advice Thread-Index: AQHNJKKg3G1khBdsQEC/pQMjcQTZ/ZavdkgAgAApCICAAA/nAA== Date: Fri, 27 Apr 2012 22:02:26 +0000 Message-ID: References: <4F9AE329.3030407@bardubitzki.com> <72490F54-126C-4CFB-B900-729466A5A86D@sri.com> <4F9B0A57.3060607@bardubitzki.com> In-Reply-To: <4F9B0A57.3060607@bardubitzki.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [192.12.16.203] Content-Type: multipart/signed; boundary="Apple-Mail-138-774720813"; protocol="application/pkcs7-signature"; micalg=sha1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrEIsWRmVeSWpSXmKPExsXSICQ+U3e9+Gx/g1mveSw69+xlc2D02Pjh OGMAYxSXTUpqTmZZapG+XQJXRvvDDtaCkx2MFXMbVrM0ME6t6GLk5JAQMJE4sPUiE4QtJnHh 3nq2LkYuDiGBnUwSRx7NYoJw9jFKnJl5jBWkik1AXuLw9gfMILaIgKXErQUfWUBsYQFZiZOn 3jNBxOUkJmw5yQZhO0kcPjAVLM4ioCqx4tY7sF5eASuJQ4tfg9UICbQwSrzfFgticwroS/y/ +Bsszgh00fdTa8B6mQXEJW49mQ91qYjEw4un2SBsUYmXj/+xQtiKEg039zNC1FdJLOt8xwSx S1Di5MwnLBMYRWYhGTULSdksJGUQcQ+JfcseskHY2hLLFr5mnsXIAWTrSExeyIgqDGF/PH8E aqSpxOujH6FqrCVm/DoINUZRYkr3Q/YFjNyrGGWSijLTM0pyEzNzdGHxaaJXXJSpl5yfu4kR HLMhrTsYV+wxPMQowMGoxMN7aP0sfyHWxLLiytxDjBIczEoivJl3gEK8KYmVValF+fFFpTmp xYcYpTlYlMR5v5nz+wsJpCeWpGanphakFsFkmTg4pRoY/e9eN1s44+v2G92T/Rvs/zwL+VhU GXhl2oOjZlETAgVaFAsjn5p95RTjXPKK/Yzatxku8i8EjnP7Jfzw3cu0sODrYpmzqqwBIje3 rGC6yvOf9/uS96srHH6erV7c5XduG9tp80NSBe/fdmx7IDNfU4278NqsExtMIgsE556NZzJe 5HVWN71ASYmlOCPRUIu5qDgRABZdVR/VAgAA X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-138-774720813 Content-Type: multipart/alternative; boundary=Apple-Mail-137-774720774 --Apple-Mail-137-774720774 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Okay, sorry, I missed the following days part. I'm not sure you can do = exactly what you want with a view only, but you probably want a list = function as well. the GeoCouch plugin would have been your best bet for = that... too bad...=20 You can still use the same type of view with keys like: [ date, eventid = ], then create a list function that uniques the eventid's; just do this = any time the eventid changes in the 'stream' you send the details once, = - and if you include with_docs; you could add the event details you want = as well.=20 I do something very similar to this here: = https://github.com/LearningRegistry/LearningRegistry/blob/master/data_serv= ices/standards-alignment-dct-conformsTo/lists/to-json.js#L18 Alternatively which is probably simpler: If you can place some kind maximum fixed range requirement that's = reasonable, like I always want to show events within 5 days of the each = event... you could artificially emit extra date keys in your map... 5 = days before and 5 days after the event... Say your event is for May 5, then you emit that event for every day in = the map from Apr 30 - May 10. You might have another event on the May = 2, which you emit dates from April 27 - May 7. If I search for May 2, = event.. i'll also get the may 5 event. Then when you query the view with a simple reduce for a specific day... = you should get a list of all events within 5 days (10 day range)... of = the date specified. If you put some kind of larger limit on that like = 14 days before and after.. then post filter the result set using a list = function into a smaller range, to dates before or after, and etc. - Jim Jim Klo Senior Software Engineer Center for Software Engineering SRI International On Apr 27, 2012, at 2:06 PM, Stephan Bardubitzki wrote: > Thanks for your suggestions Jim. >=20 > Unfortunately, I have to count out GeoCouch for now and your first = suggestion doesn't satisfy my requirements. It would yield the events = for a particular day, but not for all following days, requiring more = connections to the db which I want to avoid for a mobile app. >=20 > Before posting I have tried a couple days to find a clean solution, = but came up with the start_date as key. It gives me all events, = including past events, and the hard work has to be done on client side. >=20 > My finding works, just have the feeling there is a more efficient way. >=20 > Stephan >=20 >=20 > On 12-04-27 11:38 AM, Jim Klo wrote: >> There's a whole bunch of ways to do that... but here are 2: >>=20 >> 1. create a map function that emits all the days of the event as keys = - the searching for any particular day would yield those events >> 2. use geocouch, store the start & end dates as a box, then you can = use the current date as a bbox to find all events that overlap. Using = this method, you'd want to store time as an integer value and not a = string. >>=20 >> IMHO #2 is probably a cleaner approach, but requires GeoCouch. >>=20 >> - Jim >>=20 >> * >> * >> * >> *Jim Klo* >> Senior Software Engineer >> Center for Software Engineering >> SRI International >> * >> * >> * >>=20 >> On Apr 27, 2012, at 11:19 AM, Stephan Bardubitzki wrote: >>=20 >>> I have a database of events and since events can be multi-day events = all documents have a start_date and end_date. Now I want to get all = events that happen today and those that are starting in the coming days. >>>=20 >>> How should I determine if today is in the range of start_date and = end_date? >>>=20 >>> To make things more complex an event can be assigned to one or more = categories such as sports, music etc. So the next task would be to get = all events of a certain category that happen today and in the coming = days. >>>=20 >>> Since a db of events might be a common task I hope someone has = already come up with a solution. >>>=20 >>> Any advice would be greatly appreciated. >>>=20 >>> Stephan >>>=20 >>=20 --Apple-Mail-137-774720774 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii http= s://github.com/LearningRegistry/LearningRegistry/blob/master/data_services= /standards-alignment-dct-conformsTo/lists/to-json.js#L18
Alternatively which is probably = simpler:

If you can place  some kind = maximum fixed range requirement that's reasonable, like I always want to = show events within 5 days of the each event...  you could = artificially emit extra date keys in your map...  5 days before and = 5 days after the event...

Say your event is for = May 5, then you emit that event for every day in the map from Apr 30 - = May 10.  You might have another event on the May 2, which you emit = dates from April 27 - May 7.  If I search for May 2, event.. i'll = also get the may 5 event.

Then when you query = the view with a simple reduce for a specific day... you should get a = list of all events within 5 days (10 day range)... of the date = specified.  If you put some kind of larger limit on that like 14 = days before and after.. then post filter the result set using a list = function into a smaller range, to dates before or after, and = etc.


- = Jim

Senior Software = Engineer
Center for Software = Engineering
SRI = International

On Apr 27, 2012, at 2:06 PM, Stephan Bardubitzki = wrote:

Thanks for your suggestions = Jim.

Unfortunately, I have to count out GeoCouch for now and your = first suggestion doesn't satisfy my requirements. It would yield the = events for a particular day, but not for all following days, requiring = more connections to the db which I want to avoid for a mobile = app.

Before posting I have tried a couple days to find a clean = solution, but came up with the start_date as key. It gives me all = events, including past events, and the hard work has to be done on = client side.

My finding works, just have the feeling there is a = more efficient way.

Stephan


On 12-04-27 11:38 AM, Jim = Klo wrote:
There's a whole bunch of ways to = do that... but here are 2:

1. create a map = function that emits all the days of the event as keys - the searching = for any particular day would yield those = events
2. use geocouch, store = the start & end dates as a box, then you can use the current date as = a bbox to find all events that overlap. Using this method, you'd want to = store time as an integer value and not a = string.

IMHO #2 is = probably a cleaner approach, but requires = GeoCouch.

- = Jim

*
*
*
*Jim = Klo*
Senior Software = Engineer
Center for Software = Engineering
SRI = International
*
*
*

On Apr 27, = 2012, at 11:19 AM, Stephan Bardubitzki = wrote:

I have a database of events and since events can be = multi-day events all documents have a start_date and end_date. Now I = want to get all events that happen today and those that are starting in = the coming days.

How should I determine if today = is in the range of start_date and = end_date?

To make things more complex an = event can be assigned to one or more categories such as sports, music = etc. So the next task would be to get all events of a certain category = that happen today and in the coming = days.

Since a db of events might be a = common task I hope someone has already come up with a = solution.

Any advice would be greatly = appreciated.

Stephan



= --Apple-Mail-137-774720774-- --Apple-Mail-138-774720813 Content-Disposition: attachment; filename="smime.p7s" Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIJ/zCCBO0w ggRWoAMCAQICEBX3i1OyIZLyYjv7fwx/UYkwDQYJKoZIhvcNAQEFBQAwgdgxCzAJBgNVBAYTAlVT MRowGAYDVQQKExFTUkkgSW50ZXJuYXRpb25hbDEfMB0GA1UECxMWVmVyaVNpZ24gVHJ1c3QgTm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