Calculation of available time after taking into account "outages".

I have two tables, travel and failures. The shift table contains one record per person (identified by an ID unique person) by date and a time field start time and end. The failures table contains documents showing when someone is unavailable and has a start date/time and end date/time.

What I need to do, is to create a view that returns one line per record shift, showing their hours available taking into account failures which cover this change. A failure may extend over several days, or there could be multiple failures within a single day. For example, if there is a power failure for a person from 12/01/2009-08:00 (DD/MM/YYYY HH24) and ends at 2009-02-12 10:00 and the movement of people both at the time is 08:00 - 16:00, it should return zero hour availability for 2009-01-12 and the availability of 6 hours for 2009-02-12. Similarly, assuming the same displacement from 08:00-16:00, a shift with 2 failures from 08:00 - 10:00 and 15:00 - 16:00 must return the availability of 5 hours. Failures for one person may not overlap.

Any ideas on how to go about it?

Hello

Welcome to the forum!

Not counting failures, the total duration (in days) is end_time less start_time, assuming that these columns are DATEs.
Subtract the total time when outages overlap shift multiply by 24 to change the units from days to hours.
One way to do that is:

SELECT     s.*     -- or whatever columns you want
,     24 * ( (end_time - start_time)
          - NVL ( ( SELECT  SUM  ( LEAST    (end_time,   s.end_time)
                        - GREATEST (start_time, s.start_time)
                        )
                 FROM    outage
                 WHERE   person_id  = s.person_id
                 AND     start_time < s.end_time
                 AND     end_time   > s.start_time
               )
             , 0
             )
          )     AS hours_available
FROM     shift     s
;

Maybe it's not obvious why the conditions

...                 AND     start_time < s.end_time
                 AND     end_time   > s.start_time

say if failure overlaps with shift.
Look at it this way: in which case failure to NOT overlap? They do not overlap when either
(a) the breakdown begins after the end of the SHIFT (i.e. start_time > s.end_time), or
(b) the failure ends before the start of the transition (i.e. end_time<>
The conditions of the query are the negation of these two conditions.

It would be in reality a little more correct to say that failure and shift overlap when

...                 AND     start_time <= s.end_time
                 AND     end_time   >= s.start_time

which would include cases where you start at the exact moment the other ends. Given that the total duration of such an overlap is 0, I left these cases limits out of the query.

This requires that start_time<= end_time="" in="" all="">
I made a few other assumptions, too. If I have something wrong, or if you need assistance for any reason, after the informatipn as mentioned centinul.

Published by: Frank Kulash, November 1, 2009 19:23

Tags: Database

Similar Questions

  • Smart playlist without taking into account the time of power

    For many of my songs, I put options in iTunes to start at some point (start for example, eliminated song a movie after the composers finished introduce), or stop at some point (for example, end "A Day in the Life" until the inner Groove goes off).  However, when I listen to them on my iPhone, via the list of each song, I said I love you, they begin to run and play all the way to the end.  Only when I listen to the song in a different playlist, or ask Siri Shuffle it for me, these options work as it should.  Does anyone else have this problem?  My solution would not work when I want to take the first song myself at the time.

    I also have this problem and it's really annoying! I'm on an iPhone iOS running 7 10.

    It occurs in every playlist I have regardless of whether it was a smart playlist or the normal playlist I made.

    Another thing that my phone has done is when the playlist rolls that some songs will be start of subject to halfway through the song. I don't know if it's because he plays from the point at which I jumped the song the day before. I manually checked every song in my iTunes library to make sure that the box saying "remember playback position" only is unchecked (took me a while). Each box is unchecked. Ugh. I hope it's a little bug iPhone will fix as soon as possible.

  • programs not responding, freezing, office does not properly taking into account the temporary office.

    When I start my computer, I get the Welcome screen and then my office takes over thereafter, is not loaded correctly, and I get temporary.  I have to restart. Virtually every day, windows mail opens then freezes, I get a program does not almost any time.    I do analysis antivirus regularly, clean and defragment.    can someone please tell me what to do with it.

    Read the info below:http://support.microsoft.com/kb/947242

    A temporary profile is loaded after you connect to a Windows Vista-based system

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://windowshelp.Microsoft.com/Windows/en-AU/help/769495bf-035C-4764-A538-c9b05c22001e1033.mspx

    Difficulty of a corrupted user profile

    After creating the profile, you can copy the files from the existing profile. You must have at least three user accounts on the computer to perform these operations, including the new account that you created.

    See you soon.

    Mick Murphy - Microsoft partner

  • Why is relativeInitalX value not taking into account the triggering delay? using scope OR with the PXI-5124

    Hi all

    play with a digitizer PXI-5124 in a case of PXI1042Q with a PXI8110 controller that runs labview 2012 (latest updates) with the latest version of the driver NIScope.

    I put in place an acquisition of off-delay (by assigning the triggering delay, for example 20us) which works very well (I can tell by the signal I get delay control works correctly), but the data returned in the info wfm cluster (using the 2D version of niScope I16 Fetch) does not have this delay.

    Description of the relativeInitialX within this cluster indicator indicates "is the time in seconds between the trigger and the first sample in the acquired waveform" but its never to return something around 1E-9 independent of trigger delay. Surely the relative initial x should reflect the triggering delay?

    I'm doing something wrong?

    Thanks for your help!

    So, I made a screenshot of the image in the section "Trigger Delay" link I sent you.

    Meaning of the symbol:

    T0 = original moment of relaxation

    T1 = time to trigger used in the acquired record (t1 = t0 + TriggerDelay)

    T2 = time of first sample in the record of the acquis.

    RX = relativeInitialX = t1 - t2

    Response to previous reviews

    «I understand what you're saying - so basically, if I want to know the delay of my trigger for the first sample in the record, I just add my delay time value to the relativeInitialX.»

    • Close, the delay of the original trigger (t0), for the first sample in the record (t2), would actually be TriggerDelay-relativeInitialX

    «.. . Nowhere does graphically describe where is the relative value of initialX real. »

    • Right, relativeInitialX is not a timestamp, so it is not a place on the timeline, it is the difference between two timestamps (t1 and t2 above), where the relativeInitialX name.

     

    "The trigger"record"is the straight line in the Middle, so expect relative to - 1/2 initialX record length?

    • Almost correct, because the reference trigger is relativeInitialX to the position of 50%, will be the time in seconds for 1/2 the record length. (i.e. If the registration has been long relativeInitialX, 2s = 1 s).  RelativeInitialX will always be the delta time between the trigger (t1) and the first sample returned in the record (t2).

    • For example using the picture above: If t0 is 10 sec, Trigger Delay = 3 sec, SampleRate = 1 kHz, = 1000 record size.  This means that t1 = 13 s.  Our record is long of 1s (1000 points to 1 DC between each = 1 s), if t2 = 12.5 sec.  If away from all these moments are absolute time, as the timestamps.  So relativeInitialX = t1 - t2 is 13-12, 5 = 0.5 sec.

    • As a side note, the reference position should not be 50%, you can configure to between 0-100%.

    Time not yet discussed record attributes

    I don't want to make you more confused, but there is another useful attribute in the waveform info that we've not yet discussed and its AbsoluteInitialX.  Starting from the NOR-SCOPE help file:"absoluteInitialX is the timestamp of the first sample of recoveries in seconds..." "So, using the above image, absoluteInitialX = t2.

    I hope this helps.  If a part is still not clear, let me know.

    -Nathan

  • Problem with convert to PDF from Excel without taking into account the layout and graphics/graphics

    I work with Excel files with graphics (clipart) and charts from the data on the worksheet. I use Excel 2007 and everything a year ago and a half downloaded the option "convert to PDF" on the Microsoft website. It has been working beautifully. In Excel, I've got a) set print area b) go to "adjust to a page" print preview can convert to PDF format and everything on the PDF page looked like exactly as it did in Excel print preview. It worked flawlessly...

    UNTIL...

    .. .the most recent "upgrades" have been installed. Now the menu reads, "Save as PDF or XPS" option and the PDF is a mess. Excel text comes out OK, but any graph or Excel charts will not resize itself, and are completely out of the page. For example, a chart that is supposed to be in the lower right corner must be resized in Excel, placed in the center of the worksheet, on the text and using this approach, resize, save a PDF routine about 50 times, and you can finally wrong PDF resembling the Excel worksheet. Of course, the Excel spreadsheet is totally messed up because you have to move the chart in the spreadsheet and it's a mess, not to mention a waste of time.

    I uninstalled the Converter Microsoft PDF and XPS, and then downloaded and installed the PDF Converter (alone). No luck. It's always a mess. My business is at a standstill until I get this sorted. Help, please!

    KFG

    There is a fix for this.  It is described in a strange article entitled ' Description of the fix Excel 2007 package (Excel-x - none.msp, Graph-x - none.msp, Xlview-x - none.msp): August 25, 2009 "located here: http://support.microsoft.com/kb/973402/

    Before installing, my PDF and XPS exporting from Excel had too much size images.  Now exports are correct, just like before the Service Pack.

    Unlike article, my patch was dated 13/10/2009, rather than 19/08/2009.

    See you soon!
    BillVo

  • Windows 7 without taking into account the power settings

    I have a dell xps 15z running under Windows 7 64-bit, and it was just openly ignoring my power settings.  The display turns off after 5 minutes, it never sleeps, nothing.  It will stay just the way it is left until it runs the battery down.  What can I do to fix this?

    Hi soveryconfused,

    Follow these methods.

    Method 1: Run the troubleshooter of power.

    http://Windows.Microsoft.com/en-us/Windows7/open-the-power-Troubleshooter

    Method 2: Follow the steps in the article.

    http://Windows.Microsoft.com/en-us/Windows7/solutions-to-common-power-problems

    Method 3: Perform a clean boot to see if there is a conflict of software like the clean boot helps eliminate software conflicts.

    Note: After the boot minimum troubleshooting steps, follow step 7 in the link to return the computer to a Normal startupmode.

  • taking into account user keeps me collapses of its Internet Explore first

    When I click on internet explore a box comes uo and the screen fades (the box shows the user account controls - may have been settle wronly) if I cancel this box then click on internet explore, once again, it opens allright.

    Hello

    What is the full error message that is displayed?

    Check out the link and follow the steps.
    Guided Help: adjust the settings of user account control in Windows 7
    http://support.Microsoft.com/kb/975787
    For more information, you can visit him follow the links:
  • Design taking into account future growth.

    Hi, I use 11.2.0.3 version of oracle.

    We are in the process on the introduction of a new table in our database, so it expected to grow considerably(~50GB) in the future, want to decide its strategy of indexing/partitioning from its inception. I have provided.

    (1) this table is to have two important columns customerid, taskid for each customer id it will be 10 different taskid and there will be about 200 clients whereas commercial future. the two columns are varchar2. a status (varchar2) column that contains 5 different registration and other status 8 columns describing more details.

    (2) this table will not have a primary key, because he will accept customer file data, and he must accept the records in doubles too without the slightest mistake on.

    (3) for most in functionality, this table is queried using two main column (custometid, taskid) and the app guys confirm they will not be able to query the table using the date column.

    So I think
    composite(List-List) of partitioning the table based on customerid (partition) and taskid (subpartition)
    should I create global index on customerid and partition local index taskid.
    or
    single global index on (customerid, taskid)?.

    Please suggest.

    933257 wrote:

    He should spend in the future considerably(~50GB)

    (1) this table is to have two important columns customerid, taskid for each customer id it will be 10 different taskid and there will be about 200 clients whereas commercial future. the two columns are varchar2. a status (varchar2) column that contains 5 different registration and other status 8 columns describing more details.

    (3) for most in functionality, this table is queried using two main column (custometid, taskid) and the app guys confirm they will not be able to query the table using the date column.

    composite(List-List) of partitioning the table based on customerid (partition) and taskid (subpartition)

    50 GB, 200 customerid, 10 taskids - is 2 000 combinations, which means 25 MB by combination, and queries are based on a single client and task. -unless there is any other queries involved predicates will be very slowly as time goes - especially if you have no way to "time-dependent" to avoid the older data.

    composite(List-List) is the best bet - but you don't need a clue to one of these two columns because any data segment will be only the data for a given client and task; the only clues you need are on the other predicates, and you can see that local indexing for columns is all you need.

    The threat of execution for local indexing appears only if you have specified (a) only the task id and some other predicate you must then probe 200 segments data and index; or (b) If you specified either customer or task because that would require a probe of 2 000 data and index segments.  If you have specified a client then the additional work done by 10 probes index would probably acceptable to avoid global indexing.

    Concerning

    Jonathan Lewis

  • Old problem with images HD upgrade taking into account

    Hi all

    I've been here with this issue since day one with my rig (2.5 years).

    I'm not able to edit HD images correctly, the editing process is super slow, I can't seem to get an overview of the sequence, because it comes to accuse.

    The images are numerous cameras each film, DSLR, GoPro, MTS, etc..

    I work at 90% of the time with a single video stream.


    My current setup is:

    I7 2600 k 3.4 (no OC), p8z68 v pro MOBO, 16 GB of ram (4x4Go G.Skill RipJaw X Edition Dual Channel CL7-8-7-24)

    GTX 560 Ti

    caviar black 500 GB sata for os 3

    2 * 1 TB caviar black sata 3 raid for project & media

    2 * 1 TB sata 3 raid of black caviar to Scartch, Renders, etc..

    caviar green 2 TB for backups.

    * using the embedded raid controller.


    My workflow is really painful, I work with proxy files to overcome the problem of slow editing;

    1. get clips hd from the client

    2 encoding files in low resolution avi/mpeg

    3 mounting

    4 link sequences HD media (manually - approx. 30-40 minutes)

    5 error checking

    6. review of the movie - very slow due to the HD

    7. export

    Then. any movie, takes forever.

    A lot of people are trying to help with my current hardware, but I couldn't find a single solution to the problem.

    So, I want your advice, I had to upgrade my rig? because if I know that the update in a budget will have things smooth, it will be worth it in the short term.

    If you recommend the upgrade, which should go for? What can I keep?

    Thank you and best regards,

    Mehdi.

    Biran, welcome to the forums

    Because of your GoPro and DSLR media without any overclocking you really need a lot more CPU power.  At least a hex-core.  But the first thing you need to do is read encyclopedia of prejudice on building a computer Assembly for Premiere Pro on our web site, in particular its Pages Tweakers.  Especially look at this chart to see why you need this upgrade of the CPU.

    Note that the GoPro and DSLR QT are both very intensive CPU.  Initially you could just start with a new motherboard, processor and CPU cooler; and possibly reuse your RAM, GPU and hard drives.  We should know more info about your business supply and power.  The next update (later) would be in the area on the hard disk.

  • IE is without taking into account some elements of my css, as images of bg, made weird gaps

    Here is my site, but ignore the home page, there is a slide show out there that does not work in IE or Safari: http://www.hopeedwards.com/TEST_new_website/Hope_website/assorted_art.htm
    Everything is fine in Firefox but in Internet Explorer (6) white repeat the background image in my middle tier div comes through at all on any of the pages and in the comments & Contact page there is a big gap between the NAV and the content below, and everything is pushed to the left. Yesterday, I added a few things to some div tags "display: inline" in order to stop IE doubling all margins and shoving all the tags div at the bottom of page. I don't know if it's relevant.

    Completely, I'd appreciate any help! I use Dreamweaver CS3 on an Intel Mac based.

    Jen_26059 wrote:
    > Here is my site, but ignore the home page, there is a slide show out there that
    > does not work in IE or Safari:
    > http://www.hopeedwards.com/TEST_new_website/Hope_website/assorted_art.htm
    > This is great in Firefox, but Internet Explorer (6) white
    > expandable background picture in my middle layer div comes about thanks to
    > about pages

    Once more good old IE is buggy. This time its something called "haslayout".

    Give your #copy

    the same width as your #container
    953px;

    Also add a nonbreaking space to your compensation

    for Mac, Firefox 1.

     

    If you add that creates havoc in any other browser, replace the

    with:


    and in the About & Contact page there is a big gap between
    > the net asset value and the content below, and everything is pushed to the left.

    I can't help you there, the code is so messy, it would take a month of
    Sunday to sort.

    For one, you have twotags in the page that will not help.

    I re - run the page and test step by step.

    Yesterday, I
    > added some things to some div tags "display: inline" in order to stop IE from
    > doubling all margins and pushing all the way divs to the bottom of the page. I don't know if
    > It's relevant.

    This isn't.

  • Browsers without taking into account the fixed font size, developing container

    I have a layout and in the right column I have a block of text aligned to justify this block when displayed in different browsers does not maintain the size of the font 11px but changes and changes differently in different browsers.  I tried to specify the size in divs which could affect it does not seem to do much, ideas on how to limit it to the specified size?

    Thank you

    Not sure that I understand very well your question, but maybe this will help you:

    http://ALT-Web.com/demos/font-sizes.shtml

    If what you want is your

    text in div #foo be 11px, try this in your CSS:

    p #foo {do-size: 11px}

    Nancy O.
    ALT-Web Design & Publishing
    Web | Graphics | Print | Media specialists
    www.Alt-Web.com/
    www.Twitter.com/ALTWEB

  • Each time after clicking the icon of user account on windows xp to change a password is crashes with this error message: Microsoft (R) HTML Application host has encountered a problem and needs to close.

    Each time after clicking the icon of user account on windows xp to change a password is crashes with this error message: Microsoft (R) HTML Application host has encountered a problem and needs to close.

    There is a Microsoft Knowledge base article which sets up a few steps to perform in the computer in order to solve the problem you are experiencing, read the article that you find on the link I am mentioning below and see if it helps the measures mentioned:

    http://support.Microsoft.com/kb/919751

  • I am trying to download CS on my HP Z400 running Windows 7 for the first time.  The installer won't boot.  It finally gives a "server not available" error after 30-45 minutes

    I am trying to download CS on my HP Z400 running Windows 7 for the first time.  The installer won't boot.  It finally gives a "server not available" error after 30 to 45 minutes.  I checked to be sure there is no Adobe folder in my program files.

    Hello

    Please check the help below document:

    Error download or update Adobe Creative Cloud applications

    You can also view the nets below where the issue has been addressed:

    Error 207 to "install Adobe".

    Adobe creative cloud installation does not work. Get the error code 207. All solutions?

    Kind regards

    Sheena

  • Wrong date. A day off. Does not take into account leap years.

    We don't want the date on my iMac. It is a day of rest. On March 3, it shows March 2. Of course, it didn't take leap years into account. When I tried to change it after you have unlocked the date/time, he wouldn't let me to change the date. It is automatically defined under Apple Americas/U.S. (time.apple.com site), but the automatic setting is false. How do override us the auto setting or have them repaired?

    Oops! My watch was the one who was wrong. Apple is very well. Sorry about that.

  • Calculation of availability constraints

    Hi all

    I leaned how to manually calculate the constraints of availability in a HA cluster active, I came across a blog that suggests the calculation can be developed by taking the amount of ram in your esx host more than dividing by the amount of ram in your computer more virtual and multiplying by the amount of guests you have after you maximum configured failover has occurred.

    So my smaller esx host has 16 GB of ram for example vm largest has 2 GB or ram configured and I have 5 servers in the cluster with the default host defined on a chess:

    16/2 = 8 8 x 4 = 32

    So if the failure of a vm 32 host altogether would be able to run a few hosts on the rest violate the constraints of availability. It is just that I googled a bit and can't find verification on this forumla?

    Concerning

    Dale

    Here is the formula that we use, it seems quite well

    http://www.vmwarewolf.com/HA-failover-capacity/

    You can also check the vSphere availability Guide

    .. .and finally

    http://www.yellow-bricks.com/VMware-high-availability-deepdiv/

Maybe you are looking for