[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GT] SVN Commit r649 - in branches/exp: GT GT/DB website



Author: joao
Date: 2008-07-24 11:49:17 +0200 (Thu, 24 Jul 2008)
New Revision: 649

Modified:
   branches/exp/GT/Conf.pm
   branches/exp/GT/DB/genericdbi.pm
   branches/exp/GT/Tools.pm
   branches/exp/website/box.html
Log:
Imported changes previously made to HEAD against the exp branch


Modified: branches/exp/GT/Conf.pm
===================================================================
--- branches/exp/GT/Conf.pm	2008-07-22 11:01:43 UTC (rev 648)
+++ branches/exp/GT/Conf.pm	2008-07-24 09:49:17 UTC (rev 649)
@@ -148,13 +148,20 @@
     close FILE;
 }
 
-=item C<< GT::Conf::get($key) >>
+=item C<< GT::Conf::get($key,$defaultValue) >>
 
-Return the configuration value for the given key. Returns undef if the
-key doesn't exist.
+Return the configuration value for the given key. If the
+key doesn't exist, it returns the optional defaultValue.
 
+If neither the key nor defaultValue exist, it returns undef.
+
 =cut
-sub get { return $conf{lc($_[0])}; }
+sub get { 
+    my $value = $conf{lc($_[0])};
+    return $value if (defined($value));
+    return $_[1] if(defined($_[1]));
+    return undef;
+}
 
 =item C<< GT::Conf::set($key, $value) >>
 

Modified: branches/exp/GT/DB/genericdbi.pm
===================================================================
--- branches/exp/GT/DB/genericdbi.pm	2008-07-22 11:01:43 UTC (rev 648)
+++ branches/exp/GT/DB/genericdbi.pm	2008-07-24 09:49:17 UTC (rev 649)
@@ -85,8 +85,8 @@
 	my $dbdriver= GT::Conf::get("DB::genericdbi::db");
 	my $dbname	= GT::Conf::get("DB::genericdbi::dbname");
 
-	die("Invalid configuration. Please specify a valid dbi driver in your options file") unless ($dbdriver);
-	die("Invalid configuration. Please specify a valid database name in your options file") unless ($dbname);
+	die("Invalid configuration. Please specify a valid dbi driver in your options file (DB::genericdbi::db)") unless ($dbdriver);
+	die("Invalid configuration. Please specify a valid database name in your options file (DB::genericdbi::dbname)") unless ($dbname);
 
 	eval "use DBD::" . $dbdriver . ";";
 
@@ -123,7 +123,7 @@
 
 =cut
 sub get_prices {
-	my ($self, $code, $timeframe) = @_;
+    my ($self, $code, $timeframe) = @_;
     return get_last_prices($self, $code, -1, $timeframe);
 }
 
@@ -136,23 +136,24 @@
 sub get_last_prices {
     my ($self, $code, $limit, $timeframe) = @_;
     $timeframe = $DAY unless ($timeframe);
-	$limit = 99999999 if ($limit==-1);
+    $limit = 99999999 if ($limit==-1);
 
     my $q = GT::Prices->new($limit);
     $q->set_timeframe($timeframe);
 
-	my $sql = GT::Conf::get("DB::genericdbi::prices_sql::$timeframe");
-	if (!defined($sql)) { $sql = GT::Conf::get("DB::genericdbi::prices_sql") || die("Invalid configuration. You must specify a valid prices sql statment for your database in the options file")};
-	$sql =~ s/\$code/$code/;
-	$sql =~ s/\$timeframe/$timeframe/;
-	$sql =~ s/\$limit/$limit/;
+    my $sql = GT::Conf::get("DB::genericdbi::prices_sql::$timeframe", GT::Conf::get('DB::genericdbi::prices_sql'));
+    die("Invalid configuration. You must specify a valid prices sql statment for your database in the options file") if (!defined($sql));
+    $sql =~ s/\$code/$code/;
+    my $tf_map_value = GT::Conf::get("DB::genericdbi::tf_map::$timeframe",$timeframe);
+    $sql =~ s/\$timeframe/$tf_map_value/;
+    $sql =~ s/\$limit/$limit/;
 
     my $sth = $self->{'_dbh'}->prepare($sql)
-    	|| die $self->{'_dbh'}->errstr;
+        || die $self->{'_dbh'}->errstr;
     if ($sth->execute()) {# || die $self->{'_dbh'}->errstr;
         my $array_ref = $sth->fetchall_arrayref();
         $q->add_prices_array(reverse(@$array_ref));
-	}
+    }
     return $q;
 }
 
@@ -166,7 +167,7 @@
 sub get_db_name {
     my ($self, $code) = @_;
 
-    my $sql = GT::Conf::get("DB::genericdbi::name_sql") || die("Invalid configuration. You must specify a valid data_available sql statment for your database in the options file");
+    my $sql = GT::Conf::get("DB::genericdbi::name_sql") || die("Invalid configuration. You must specify a valid name_sql sql statment for your database in the options file");
 	$sql =~ s/\$code/$code/;
 
     my $sth = $self->{'_dbh'}->prepare($sql) || die $self->{'_dbh'}->errstr;

Modified: branches/exp/GT/Tools.pm
===================================================================
--- branches/exp/GT/Tools.pm	2008-07-22 11:01:43 UTC (rev 648)
+++ branches/exp/GT/Tools.pm	2008-07-24 09:49:17 UTC (rev 649)
@@ -440,8 +440,13 @@
 die("Parameter \$db not set in get_timeframe_data") if (!defined($db));
 
 if (defined($available_timeframes)) {
-	foreach (split(',', $available_timeframes)) {
-		push @tf, GT::DateTime::name_to_timeframe($_);
+	foreach my $tf_name (split(',', $available_timeframes)) {
+	        my $tf_code = GT::DateTime::name_to_timeframe($tf_name);
+		push @tf, $tf_code;
+		if (!defined($tf_code)) {
+		    my $tfs = join("\n\t", map(GT::DateTime::name_of_timeframe($_), GT::DateTime::list_of_timeframe));
+		    die("Invalid timeframe name in available_timeframes configuration item: $tf_name\n\nValid timeframes are: \n\t" . $tfs . "\n\n");
+		}
 	}
 	@tf = sort(@tf);
 } else {
@@ -457,6 +462,12 @@
   last if ($q->count > 0);
 }
 
+if (!defined($q) || $q->count == 0) {
+my $msg="No data available to generate ".GT::DateTime::name_of_timeframe($timeframe)." data.";
+$msg.="\nAvailable timeframes are: ($available_timeframes)" if (defined($available_timeframes));
+die($msg);
+}
+
 warn ("No data is available to complete the request for $code") if ($q && $q->count == 0);
 my $calc = GT::Calculator->new($q);
 $calc->set_code($code);

Modified: branches/exp/website/box.html
===================================================================
--- branches/exp/website/box.html	2008-07-22 11:01:43 UTC (rev 648)
+++ branches/exp/website/box.html	2008-07-24 09:49:17 UTC (rev 649)
@@ -10,6 +10,7 @@
 </li>
 <li><a href="http://devel.geniustrader.org/";>Wiki</a></li>
 <li><a href="/cgi-bin/viewcvs.cgi/trunk/">Browse CVS tree</a></li>
+<li><a href="/wws/">Mailing List Services</a></li>
 <li><a href="/faq.html">FAQ</a></li>
 <li><a href="/screenshots.html">Screenshots</a></li>
 <li><a href="/links.html">Links</a></li>