Gossamer Forum
Home : Products : DBMan : Customization :

Meta-Data

Quote Reply
Meta-Data
Has anyone written a script for creating statistical/meta-data about a database. As a simple example, I have a database in which each record has an entry date, a completion date. I want to write a script that will open the database and calculate the elapsed time between the entry and completion dates for each record and return the mean "time-till completion" date for the whole database.

Thanks,

Lauren
Quote Reply
Re: Meta-Data In reply to
It's definately something custom, but wouldn't be that hard. Something like:

Code:
#!/usr/local/bin/perl

require "/path/to/default.cfg";

my $start = 1; # Start date position in db.
my $end = 2; # End date position in db.

open (DB, $db_file_name) or die "Nope: $!";
while (<DB> ) {
next if /^\s*$/;
next if /^#/;
chomp;
@data = split (/\|/, $_, $#db_cols);
$diff = &date_to_unix ($end) - &date_to_unix($start);
$total = $diff + $total;
$count++;
}
close DB;
print "Average: ";
print $total / $count;
print "\n";

sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = shift;
my ($i, $time) = 0;
my %months = qw!Jan 0 Feb 1 Mar 2 Apr 3 May 4 Jun 5 Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11!;
my ($day, $mon, $year) = split(/-/, $date);
($day and $mon and $year and exists $months{$mon}) or die "Can't convert date: $date";

eval {
use Time::Local;
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
$@ ? die "Can't convert date: $date. Err: $@" : return $time;
}

It's untested but hopefully should give you a start.

Cheers,

Alex
Quote Reply
Re: Meta-Data In reply to
Alex,

I put this into a file and ran it, but it gives internal server errors. Any ideas why ?
Quote Reply
Re: Meta-Data In reply to
Dear Alex,

Thanks for the prompt help. I see what you are trying to do, but I too get errors when I try to run the script. My errors are all syntax errors though, which I cannot figure out. They are errors like:

syntax error in file XXX at line 32, next 2 tokens "qw!"
syntax error in file XXX at line 30, next 2 tokens "my ("

I don't get it, because similar syntax works on the other dbman scripts.

Any ideas?

Lauren

Quote Reply
Re: Meta-Data In reply to
Katana Man:

It's not a cgi script, so it should produce 500 server errors when run from the web. You'll need to run it from telnet.

Lauren:

Syntactically it's ok (but it's not tested). Looks like you are using perl 4 to run it. (You can confirm by typing perl -v).

Cheers,

Alex