in reply to Re^2: Pull data from two tables, insert into new table?
in thread Pull data from two tables, insert into new table?

My 2nd question really was 'How far into the future do you want the dates in the mysql table to go '.

It could get more complicated if you want to detect changes to the 2 oracle tables. Assuming the record count is in the hundreds, it might be simpler just to delete all future records and regenerate the table each night.

As a starter idea, here is a test script that generates the records you would need to insert.

#!perl use strict; use DBI; use Time::Piece; use Time::Seconds; my %regular = ( Mon => ['08:00','17:00'], Tue => ['08:00','17:00'], Wed => ['08:00','17:00'], Thu => ['08:00','17:00'], Fri => ['08:00','17:00'], Sat => ['08:00','12:00'], Sun => ['00:00','00:00'], ); my %except = ( '2016-05-30' => ['00:00','00:00'], '2016-07-04' => ['00:00','00:00'], '2016-09-05' => ['00:00','00:00'], '2016-10-10' => ['00:00','00:00'], '2016-11-08' => ['00:00','00:00'], '2016-11-11' => ['00:00','00:00'], '2016-11-24' => ['00:00','00:00'], '2016-12-26' => ['00:00','00:00'], ); my $t = localtime; my $end_date = '2016-12-31'; open OUT,'>','all_dates.csv' or die "$!"; my $id = 1; while ($t->ymd le $end_date){ my $ymd = $t->ymd; my $w = $t->wdayname; my $open = $except{$ymd}[0] || $regular{$w}[0]; my $close = $except{$ymd}[1] || $regular{$w}[1]; my $is_closed = ($open eq '00:00') ? 1 : 0; print OUT "$id,$ymd,$w,$open,$close,$is_closed\n"; $t += ONE_DAY; ++$id; } close OUT;
poj

Replies are listed 'Best First'.
Re^4: Pull data from two tables, insert into new table?
by Hans Castorp (Sexton) on Feb 16, 2016 at 19:04 UTC

    Thank you, poj.

    Yes, I think that is right--the table should be rewritten each night. We generally run our exception hours by the semester, so it can contain up to three months' worth. The beginning and end of the semesters can be dicey though, a lot of changes going on.

    I could also see the value, however, of keeping previous exception dates stored, so that the "analog" calendar the combined table populates can be turned back, say, to last year to see what hours we were keeping then--for statistical purposes or whatever.

    Thanks again--I'm going to start working with this and see what I come up with!

    HC

      Ok, the major complication I see is if you implement a change to the regular hours in the future. You would need to add valid_from_date ,valid_to_date fields to that table, or do they have them already ?

      poj

        :-) Yes, the calendar_begin_date is 8/10/2010 and the calendar_end_date is 8/31/2024.

        I was just thinking that, since the regular hours really do not change, I could just put them in the script as a hash--as you have done--and then grab the exception hours each night and somehow sort them through the regular hours to see where each exception would fit. (?) That way, if the regular hours change, all I need to do is change them in the script.

        So, if an exception, then exception hours. If no exception, then regular hours....

        Thanks for helping me think this through.