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


Groups > comp.lang.python > #95387

Re: How to model government organization hierarchies so that the list can expand and compress

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; '"""': 0.05; 'clause': 0.07; 'great.': 0.07; 'hierarchical': 0.07; 'subject:How': 0.09; 'part,': 0.09; 'postgres': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python.': 0.11; 'ignore': 0.14; '(say': 0.16; 'appreciated!': 0.16; 'describing': 0.16; 'forth.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reproduce': 0.16; 'row': 0.16; 'traverse': 0.16; 'tutorials.': 0.16; 'variations': 0.16; 'laura': 0.18; 'tree': 0.18; 'do.': 0.22; 'assumes': 0.22; 'skip:n 60': 0.22; 'trying': 0.22; 'decide': 0.23; 'select': 0.23; '(or': 0.23; 'help.': 0.23; 'seems': 0.23; 'wrote': 0.23; 'examples': 0.24; 'header:In-Reply- To:1': 0.24; 'example': 0.26; 'subject:list': 0.26; 'header:X -Complaints-To:1': 0.26; 'least': 0.27; "skip:' 10": 0.28; 'subject:that': 0.29; "i'm": 0.30; 'another': 0.32; 'run': 0.33; 'common': 0.33; 'changing': 0.34; 'equal': 0.34; 'structure': 0.34; 'could': 0.35; 'level': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'child': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'data': 0.39; 'sure': 0.39; 'subject:the': 0.39; 'expressed': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'called': 0.40; 'some': 0.40; 'your': 0.60; 'real': 0.62; 'course': 0.62; 'linked': 0.63; 'to,': 0.63; 'world': 0.64; 'places': 0.64; 'response.': 0.66; 'department.': 0.66; 'organisation': 0.66; 'quantity': 0.66; 'here': 0.66; 'union': 0.67; 'design.': 0.72; 'frank': 0.72; '100%': 0.72; 'deleted?': 0.84; 'post,': 0.84; 'glad': 0.87
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: How to model government organization hierarchies so that the list can expand and compress
Date Sat, 15 Aug 2015 07:59:06 +0200
References <b3c1e2da-9f72-420a-8b68-288dddf9fc67@googlegroups.com> <mailman.5.1439534188.4764.python-list@python.org> <ae4e203d-c664-4388-af0b-41c41d5ec724@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="iso-8859-1"; reply-type=original
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 197.89.14.139
In-Reply-To <ae4e203d-c664-4388-af0b-41c41d5ec724@googlegroups.com>
X-MSMail-Priority Normal
Importance Normal
X-Newsreader Microsoft Windows Live Mail 15.4.3502.922
X-MimeOLE Produced By Microsoft MimeOLE V15.4.3502.922
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Newsgroups comp.lang.python
Message-ID <mailman.16.1439618363.4764.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439618363 news.xs4all.nl 2835 [2001:888:2000:d::a6]:45573
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95387

Show key headers only | View raw


"Alex Glaros"  wrote in message 
news:ae4e203d-c664-4388-af0b-41c41d5ec724@googlegroups.com...

> Frank, thanks for describing the terminology of what I'm trying to do.
>
> 1. Do the recursive join Postgres examples you linked to, use a data 
> structure where the child has the adjoining parent-ID? Examples look 
> great.

I think that their example is very simple - it seems that each level 
contains one link to the level below, and the level below has no link to the 
level above (or at least they did not make use of it).

The following (untested) example assumes that each row can have multiple 
children, and each row has a link to its parent called parent_id.

    WITH RECURSIVE included_parts(part, quantity) AS (
        SELECT  part, quantity FROM parts WHERE part = 'our_product'
      UNION ALL
        SELECT p.part, p.quantity
        FROM included_parts pr, parts p
        WHERE p.parent_id = pr.part
      )
    SELECT part, SUM(quantity) as total_quantity
    FROM included_parts
    GROUP BY part

You will find many variations in various on-line tutorials. For example, you 
can traverse *up* the tree by changing the WHERE clause to WHERE p.part = 
pr.parent_id

>
> 2. Not 100% sure that hierarchical is the perfect solution but will go 
> with that now. Of course some agencies will be at equal levels; will 
> ignore for now.
>
> 3. Could not find Laura's response. Was it deleted?
>

Laura responded to this in another post, but in case you cannot see that one 
either, I reproduce it here -

"""
What I said was, that real agencies are almost never perfectly
heirarchical.  That's an oversimplification.  In the real world
Organisation A (say Army) and Organisation B (say Navy) decide they
have common interests and make a Joint Department.  If you run that
department you report to superiors in _both_ organisation A and
organisation B, get orders from both places and so on and so forth.
You must decide now what you want to do when you run into such
departments, because that will greatly influence your design.
"""

> 4. Solution will expressed in the DB, not Python.

> Much appreciated!

Glad I could help.

Frank

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


Thread

How to model government organization hierarchies so that the list can expand and compress Alex Glaros <alexglaros@gmail.com> - 2015-08-13 12:10 -0700
  Re: How to model government organization hierarchies so that the list can expand and compress "Stéphane Wirtel" <stephane@wirtel.be> - 2015-08-13 21:17 +0200
  Re: How to model government organization hierarchies so that the list can expand and compress Ian Kelly <ian.g.kelly@gmail.com> - 2015-08-13 13:26 -0600
  Re: How to model government organization hierarchies so that the list can expand and compress Laura Creighton <lac@openend.se> - 2015-08-13 21:43 +0200
  Re: How to model government organization hierarchies so that the list can expand and compress "Frank Millman" <frank@chagford.com> - 2015-08-14 08:36 +0200
    Re: How to model government organization hierarchies so that the list can expand and compress Alex Glaros <alexglaros@gmail.com> - 2015-08-14 16:42 -0700
      Re: How to model government organization hierarchies so that the list can expand and compress Rustom Mody <rustompmody@gmail.com> - 2015-08-14 18:21 -0700
      Re: How to model government organization hierarchies so that the list can expand and compress Laura Creighton <lac@openend.se> - 2015-08-15 06:54 +0200
      Re: How to model government organization hierarchies so that the list can expand and compress "Frank Millman" <frank@chagford.com> - 2015-08-15 07:59 +0200
  Re: How to model government organization hierarchies so that the list can expand and compress Friedrich Rentsch <anthra.norell@bluewin.ch> - 2015-08-14 23:25 +0200
  Re: How to model government organization hierarchies so that the list can expand and compress Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-14 19:38 -0400
  Re: How to model government organization hierarchies so that the list can expand and compress Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-15 22:51 +0000
    Re: How to model government organization hierarchies so that the list can expand and compress Alex Glaros <alexglaros@gmail.com> - 2015-08-17 13:37 -0700

csiph-web