next up previous contents index
Next: Manipulation of Interval Lengths Up: Test Data Creation Previous: Timestamps for R

Timestamps for Q

 

#!/usr/local/bin/perl

# ----------------------------------------------------------
# week-long lifespan, do not consider weekday (non-periodic)
# ----------------------------------------------------------
# This is a PERL script to convert the output of the "last" command.
# Day information is negelected, only login start and end times are
# considered. The login times are converted to minutes (eg. 9:24 ->
# 9*60+24 = 524) and the projected from a daytime base to a weektime
# base (eg. 524 -> 524*7+<random number between 0 and 6>  = 3948..3954).
# The result gives intervals within the lifespan 0..10079 
# (10080 = number of minutes within a week).


# number of minutes per day

$one_day = 24 * 60;


# initialise random generator

srand;


# subsequently read lines of standard input ...

while (<>) {

   # split an input line using white spaces as separators

   @fields = split(/\s+/,$_);

   # convert hh:mm start and end times into integers

   ($hours,$minutes) = split(/:/,$fields[6]);
   $start = $hours * 60 + $minutes;
   ($hours,$minutes) = split(/:/,$fields[8]);
   $end   = $hours * 60 + $minutes;

   # project daytime period to weektime period

   $start = $start * 7 + int(rand(7));
   $end   = $end   * 7 + int(rand(7));

   # deal with logins that ran over midnight

   if ($start > $end) {
      $end = $end + $one_day;
   }

   # write interval [$start,$end] to standard output;
   # if the [$start,$end] does not fall within the scope [0,10079]
   # then a "point" interval [$start,$start] is used

   if (($start <= $end) && ($end < 10080)) {
      print "[",$start,",",$end,"]\n";
   }
   else {
      print "[",$start,",",$start,"]\n";
   }
}



Thomas Zurek