Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106241

Re: Set type for datetime intervals

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: Set type for datetime intervals
Date Fri, 01 Apr 2016 11:45:37 -0400
Lines 78
Message-ID <mailman.319.1459525544.28225.python-list@python.org> (permalink)
References <56FE0625.5030901@shopzeus.com>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de chgc/hAESSdyTMmqTn7dkg2ix4jKtOytDgfSCfBK+pQw==
Return-Path <random832@fastmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'objects,': 0.07; 'type,': 0.07; 'minus': 0.09; 'received:internal': 0.09; 'python': 0.10; '"in"': 0.16; '::=': 0.16; 'elem': 0.16; 'element,': 0.16; 'element.': 0.16; 'element2,': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'operation.': 0.16; 'operation:': 0.16; 'operators.': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'set,': 0.16; 'side.': 0.16; 'sorting.': 0.16; 'subject:type': 0.16; 'symmetric': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'element': 0.18; '(not': 0.20; 'occurs': 0.22; 'seems': 0.23; 'elements': 0.23; 'sets': 0.23; 'this:': 0.23; 'properties': 0.24; 'header:In-Reply-To:1': 0.24; 'compare': 0.27; 'fri,': 0.27; 'start,': 0.27; 'function': 0.28; 'skip:( 20': 0.28; 'end,': 0.29; 'other,': 0.29; 'strings,': 0.29; "i'm": 0.30; "we're": 0.30; 'mention': 0.30; 'extend': 0.31; 'operations': 0.31; 'possibly': 0.32; 'useful': 0.33; 'particular,': 0.33; 'open': 0.33; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'really': 0.37; 'setting': 0.37; 'difference': 0.38; 'received:66': 0.38; 'mean': 0.38; 'why': 0.39; "didn't": 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'hello,': 0.40; 'some': 0.40; 'suitable': 0.61; 'header:Message-Id:1': 0.61; 'more': 0.63; 'respect': 0.65; '.....': 0.76; 'difference.': 0.84; 'elements:': 0.84; 'nagy': 0.84; 'sets,': 0.84; 'union,': 0.84; 'min': 0.91; 'shocked': 0.91; 'sorry.': 0.91; 'subject:Set': 0.91
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=5AXaENw7Z2I/6Gj8ldX2HWFFoQg=; b=uxFSgi bUamoMrsz7Tv9crzbtNQ9Jfrfa0Lmg6BYQHX1FxqCtdFxvHmgIirlgpPuBZq8G77 MPyVv3Ynn7oLjfyxeOb9Y+9NzlgZ0QUiIy4u5zltuKdWZ5EXVwwwKb6Rj1TAAth+ DjKuayMvwdp1CD+sol04dz+PkqYmCdA+Gn8s8=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=5AXaENw7Z2I/6Gj 8ldX2HWFFoQg=; b=SMySs79pTYwfNvqwdVGRg/SYnBw3ir9ciLcvxlY/QOACK0w /0DCDoRksPovG4EIAxcdpmF5FGRtUcbhNK9TwdKAG81TzXR66HPBrS4i9D4dxIuD o4kEx6JAXaI0qO33ECmV+c25uEzCxXDzYcoOMDD1ATUA8rp6PI0nObzRLvg8=
X-Sasl-Enc tHyA0GreeBmvMIPj9jUUU8mHEa4lwdK3VZmkZfQ4ffnu 1459525537
X-Mailer MessagingEngine.com Webmail Interface - ajax-2373d6a1
In-Reply-To <56FE0625.5030901@shopzeus.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:106241

Show key headers only | View raw


More thoughts... sorry.

On Fri, Apr 1, 2016, at 01:24, Nagy László Zsolt wrote:
>  
>   Hello,
> 
> I need to compare sets of datetime intervals, and make set operations on
> them: intersect, union, difference etc. One element of a set would be an
> interval like this:
> 
> element ::= (start_point_in_time, end_point_in_time)
> intervalset ::= { element1, element2, .... }
> 
> Operations on elements:


Eh... I think these should be realized as operations on an intervalset
with a single element, and that elements should simply have properties
like the start, end, and if it's open or closed on each side. In
particular, any one of these could return something that is not an
element.

> element1.intersect(element2)
May return the empty set, if they do not intersect.

> element1.union(element2)
May return {element1, element 2}

> element1.minus(element2)
May return { (start1, start2), (end2, end1) }... and the open/closeness
of the element2 endpoints is reversed.


> Operations on sets:
> 
> intervalset1.intersect(intervalset2)
> intervalset1.union(intervalset2)
> intervalset1.minus(intervalset2)

These should be operators. s1 & s2, s1 | s2, s1 - s2. There's also a s1
^ s2 operation for python sets, the symmetric difference.


Wouldn't it be useful to have some operations on datetimes?

intervalset1.ltall(dt)
.... all(dt < x.start or dt == x.start and x.startopen for x in dt)
intervalset1.gtall(dt)
.... all(dt > x.end or dt == x.end and x.endopen for x in dt)
intervalset1.leall(dt)
.... all(dt <= x.start for x in intervalset1) # I _think_ this is all
you need for this
intervalset1.geall(dt)
.... all(dt >= x.end for x in intervalset1)
dt in intervalset1
... any(dt in elem for x in intervalset1)
dt in elem
... dt > elem.start and dt < elem.end or dt == elem.start and not
elem.startopen or dt == elem.end and not elem.endopen
min and max
... seems trivial, but what to return if the first/last element is open?

I'm truly shocked you didn't even mention the "in" operation.

Also, as long as we're setting up an infinite (not really but anyway)
set, why not also have the ability to have open-ended intervals that
extend to infinity. Then you could invert the set too, for free given
the minus operation: ~x == {(-inf, inf)} - x.


It occurs to me that while I mentioned numbers, in principle you could
use _any_ total-ordered type*. strings, tuples...

*nitpicker's corner: here, "type" is used to mean any set/class/category
of objects, possibly of multiple python types and possibly not
comprising the entirety of a single type, which are total-ordered with
respect to each other, including the codomain of any key projection
function suitable for sorting.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Set type for datetime intervals Random832 <random832@fastmail.com> - 2016-04-01 11:45 -0400

csiph-web