Populating number data in a sequential manner. 
Author Message
 Populating number data in a sequential manner.

Hi All,

I am a newbie to Perl and are trying to populate some data into our database
to do some testing. What I would like to achieve it's to help populate :

(a)  EMP_SEQ : Populate number at a incremental rate, ie. 1 -500000. (The
number
      generated must be unique and cannot have duplicate numbers)

(b)  EFFECTIVE_DATE : Populate EFFECTIVE_DATE at a random manner
      within a realistic "Given Threshold". ie. between (1-MAY-1980
07:29:141 to 3-MARCH-2000
      07:29:120) The time population is not mandatory, it would be fine if
we can populate just the
      date)

So far, I the number EMP_SEQ that I am generating seems to have many
duplicates and
the date generated are RANDOM at a unrealistic DATE frame.

If anyone can provide some pointers on ANY of the issue as above , it would
be very much appreciated.

Please let me know if you need more explicit information or if I am not
clear.

Thanks All in advance and you have a pleasant day.

Sample of my draft script :-

#global letters array.

 'JAN', 'FEB', 'MAR', 'APR',
 'MAY', 'JUN', 'JUL', 'AUG',
 'SEP', 'OCT', 'NOV', 'DEC'

my $i, $j;

open ( LOAD, ">Dept_History_Data.txt" ) or die "Can't open load.txt $!\n";

for ( $i = 0; $i < 5000; ++$i )
{
 for ( $j = 0; $j < 1000; ++$j )
{
  printf LOAD ( "%d,", $i * 10 + $j ); #EMP_SEQ (PrimaryKey)
  printf LOAD DeptSeq(1)  . ",";   #DEPT_SEQ NUMBER
  print LOAD  date_rand(1)  . "\n";   #EFFECTIVE_DATE      DATE
 }

 #user counter.
 print "$i\n";

Quote:
}

sub DeptSeq  # ( nLetters )
{

 my $i;
 my $Str;

 for ( $i = 0; $i < $nLetters; ++$i )
 {
  $Str .= $DeptSeq[int(rand(10))];
 }

 return $Str;

Quote:
}

sub date_rand
{
 my $Str;

 $Str = sprintf( "\'%02d-%3s-%02d %02d:%02d:%02d\'",
    int(rand(27)) + 1,
    $Months[int(rand(12))],
    int(rand(100)),
    int(rand(24)),
    int(rand(60)),
    int(rand(60)),
    );
 return $Str;

Quote:
}



Mon, 19 Aug 2002 03:00:00 GMT  
 Populating number data in a sequential manner.
Hi All,

Would this be the simple solution for issue (a)..? It seems to be generating
at a incremental rate..
but would like to have a confirmation from you guys...

Snippet.

  printf LOAD ( $a ++ ). ",";  #EMP_SEQ (PrimaryKey)
  print  LOAD  date_rand(10000). ",";    #EFFECTIVE_DATE      DATE
  printf LOAD (  $b ++ ). "\n"; #PROJ_SEQ (PrimaryKey)

Thanks.


Quote:

> Hi All,

> I am a newbie to Perl and are trying to populate some data into our
database
> to do some testing. What I would like to achieve it's to help populate :

> (a)  EMP_SEQ : Populate number at a incremental rate, ie. 1 -500000. (The
> number
>       generated must be unique and cannot have duplicate numbers)

> (b)  EFFECTIVE_DATE : Populate EFFECTIVE_DATE at a random manner
>       within a realistic "Given Threshold". ie. between (1-MAY-1980
> 07:29:141 to 3-MARCH-2000
>       07:29:120) The time population is not mandatory, it would be fine if
> we can populate just the
>       date)

> So far, I the number EMP_SEQ that I am generating seems to have many
> duplicates and
> the date generated are RANDOM at a unrealistic DATE frame.

> If anyone can provide some pointers on ANY of the issue as above , it
would
> be very much appreciated.

> Please let me know if you need more explicit information or if I am not
> clear.

> Thanks All in advance and you have a pleasant day.

> Sample of my draft script :-

> #global letters array.


>  'JAN', 'FEB', 'MAR', 'APR',
>  'MAY', 'JUN', 'JUL', 'AUG',
>  'SEP', 'OCT', 'NOV', 'DEC'
>  );

> my $i, $j;

> open ( LOAD, ">Dept_History_Data.txt" ) or die "Can't open load.txt $!\n";

> for ( $i = 0; $i < 5000; ++$i )
> {
>  for ( $j = 0; $j < 1000; ++$j )
> {
>   printf LOAD ( "%d,", $i * 10 + $j ); #EMP_SEQ (PrimaryKey)
>   printf LOAD DeptSeq(1)  . ",";   #DEPT_SEQ NUMBER
>   print LOAD  date_rand(1)  . "\n";   #EFFECTIVE_DATE      DATE
>  }

>  #user counter.
>  print "$i\n";
> }

> sub DeptSeq  # ( nLetters )
> {

>  my $i;
>  my $Str;

>  for ( $i = 0; $i < $nLetters; ++$i )
>  {
>   $Str .= $DeptSeq[int(rand(10))];
>  }

>  return $Str;
> }

> sub date_rand
> {
>  my $Str;

>  $Str = sprintf( "\'%02d-%3s-%02d %02d:%02d:%02d\'",
>     int(rand(27)) + 1,
>     $Months[int(rand(12))],
>     int(rand(100)),
>     int(rand(24)),
>     int(rand(60)),
>     int(rand(60)),
>     );
>  return $Str;
> }



Mon, 19 Aug 2002 03:00:00 GMT  
 Populating number data in a sequential manner.
Quote:

> Hi All,

> I am a newbie to Perl and are trying to populate some data into our database
> to do some testing. What I would like to achieve it's to help populate :

> (a)  EMP_SEQ : Populate number at a incremental rate, ie. 1 -500000. (The
> number
>       generated must be unique and cannot have duplicate numbers)

You can just loop through the range

Quote:

> (b)  EFFECTIVE_DATE : Populate EFFECTIVE_DATE at a random manner
>       within a realistic "Given Threshold". ie. between (1-MAY-1980
> 07:29:141 to 3-MARCH-2000
>       07:29:120) The time population is not mandatory, it would be fine if
> we can populate just the
>       date)

Here's what I made of that, the second number (DEPT_SEQ) seems to be a
random number between and incl. 0 and 9.
See: perldoc Time::Local
And: perldoc -f localtime

#!/usr/bin/perl -w
use strict;

use constant NUMBER_OF=>15; #set this to 500000
use Time::Local;

#feed the reverse time: 1 May 1980 07:29:14
my $fd_stamp = timelocal(14, 29, 07, 1, 5 - 1, 1980);
my $ld_stamp = timelocal(12, 29, 07, 3, 3 - 1, 2000);
#$ts_diff: the period between the two dates in seconds.
#add the start date to any number in the rage 0..$ts_diff
#to get a date in the right period (using 'localtime').
my $ts_diff = $ld_stamp - $fd_stamp;

for (my $i= 1; $i <= NUMBER_OF; $i++) {
  my $new_date = rand($ts_diff) + $fd_stamp;
  printf "%6d %2d %s\n", $i, int rand(10), scalar localtime($new_date);

Quote:
}

--
Good luck,
Abe


Tue, 20 Aug 2002 03:00:00 GMT  
 Populating number data in a sequential manner.
Thanks for the Feedback !


Quote:

> > Hi All,

> > I am a newbie to Perl and are trying to populate some data into our
database
> > to do some testing. What I would like to achieve it's to help populate :

> > (a)  EMP_SEQ : Populate number at a incremental rate, ie. 1 -500000.
(The
> > number
> >       generated must be unique and cannot have duplicate numbers)
> You can just loop through the range

> > (b)  EFFECTIVE_DATE : Populate EFFECTIVE_DATE at a random manner
> >       within a realistic "Given Threshold". ie. between (1-MAY-1980
> > 07:29:141 to 3-MARCH-2000
> >       07:29:120) The time population is not mandatory, it would be fine
if
> > we can populate just the
> >       date)

> Here's what I made of that, the second number (DEPT_SEQ) seems to be a
> random number between and incl. 0 and 9.
> See: perldoc Time::Local
> And: perldoc -f localtime

> #!/usr/bin/perl -w
> use strict;

> use constant NUMBER_OF=>15; #set this to 500000
> use Time::Local;

> #feed the reverse time: 1 May 1980 07:29:14
> my $fd_stamp = timelocal(14, 29, 07, 1, 5 - 1, 1980);
> my $ld_stamp = timelocal(12, 29, 07, 3, 3 - 1, 2000);
> #$ts_diff: the period between the two dates in seconds.
> #add the start date to any number in the rage 0..$ts_diff
> #to get a date in the right period (using 'localtime').
> my $ts_diff = $ld_stamp - $fd_stamp;

> for (my $i= 1; $i <= NUMBER_OF; $i++) {
>   my $new_date = rand($ts_diff) + $fd_stamp;
>   printf "%6d %2d %s\n", $i, int rand(10), scalar localtime($new_date);
> }

> --
> Good luck,
> Abe



Tue, 20 Aug 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Populating number data in a sequential manner.

2. Populating number data in a sequential manner.

3. newbie question: adding sequential numbers

4. sequential tracking numbers

5. Sequential numbering of submitted forms

6. Perl sequential number generator

7. REQ: help # Need sequential numbers augmented to @variable_name

8. *Passing Forms Data Input to sequential CGIs*

9. Passing forms data input to Sequential CGIs

10. Populating Complex Data Structure Problem

11. Using Getopts in a case-insensitive manner

12. FBox and FileSelect, making them beahve in a similar manner

 

 
Powered by phpBB® Forum Software