From: Filip Rembiałkowski <plk.zuber@gmail.com>
To: novice <user.postgresql@gmail.com>
Cc: pgsql-general@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: work hour calculations
Date: Sun, 9 Sep 2007 12:01:52 +0100
Message-ID: <92869e660709090401m37431819s630ae5c748c6fc76@mail.gmail.com> (raw)
In-Reply-To: <ddcb1c340709081806r6cbc6b75vf71e6cfe2f454129@mail.gmail.com>
References: <ddcb1c340709042045lbe5d58fode7497c8eb060c97@mail.gmail.com>
<ddcb1c340709042054w2dae6fe9v3abe53ecb4a2a0ce@mail.gmail.com>
<92869e660709070513t7d19e836sb6a4543e6beb3b0b@mail.gmail.com>
<ddcb1c340709081806r6cbc6b75vf71e6cfe2f454129@mail.gmail.com>
2007/9/9, novice <user.postgresql@gmail.com>:
> > > > The result I'm expecting for the above to be
> > > >
> > > > notification_time | finished_time | actual
> > > > ------------------------+------------------------+-----------------
> > > > 2007-07-06 15:50:00+10 | 2007-07-09 07:10:00+10 | 01:20:00
> > > > 2007-07-07 12:30:00+10 | 2007-07-09 07:20:00+10 | 00:20:00
> >
>
> create table log
> (
> id integer PRIMARY KEY,
> notification_time timestamp with time zone,
> finished_time timestamp with time zone
> );
>
> INSERT INTO log values (1, '2007-07-06 15:50', '2007-07-09 07:10');
> INSERT INTO log values (2, '2007-07-07 12:30', '2007-07-09 07:20');
>
> SELECT notification_time, finished_time, sum(finished_time -
> notification_time) as actual
> FROM log
> GROUP BY notification_time, finished_time;
>
OK. so I have bad news for you: with such structure, you will have to
write some function to calculate work time spent for each task.
general algorithm would be similar to
* take the notification time
* take the finished_time
* set pointer := notif. time
* set actual := 0
* while there is any weekend between the pointer and finished_time,
do the following
** set actual := actual + ( weekend begin - pointer )
** move pointer to the next monday morning
* set actual := actual + ( finished_time - pointer )
BUT:
this is ugly.
do you always assume that people are doing ONLY one task at a time?
maybe think of representing work sheets in the database?
maybe think of adding "work_time" field to your table (why not trust
people, they know best)
maybe the application you use for entering data could give some "hint"
basing on above algo.
good luck,
--
Filip Rembiałkowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: plk.zuber@gmail.com, user.postgresql@gmail.com, pgsql-general@postgresql.org
Subject: Re: work hour calculations
In-Reply-To: <92869e660709090401m37431819s630ae5c748c6fc76@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox