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

[GT] SVN Commit r629 - trunk/GT



Author: thomas
Date: 2008-06-10 07:10:25 +0200 (Tue, 10 Jun 2008)
New Revision: 629

Modified:
   trunk/GT/BackTest.pm
   trunk/GT/Tools.pm
Log:
As discussed in http://www.geniustrader.org/lists/devel/msg02588.html,
moved the responsibility for opening and closing DB back to the scripts.
Every script that needs to load market data, will have to go through
the following steps:
1. use vars qw($db);
2. my $db = create_db_object();
3. use the $db object, which typically will be
my ($calc, $first, $last) = 
    find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
4. $db->disconnect;
Care must be taken that there will be only one $db->disconnect encountered
during execution. If multiple databases are created, existing connections
are reused.


Modified: trunk/GT/BackTest.pm
===================================================================
--- trunk/GT/BackTest.pm	2008-06-10 04:59:06 UTC (rev 628)
+++ trunk/GT/BackTest.pm	2008-06-10 05:10:25 UTC (rev 629)
@@ -172,7 +172,7 @@
 
 
 sub backtest_multi {
-    my ($pf_manager, $sys_manager_ref, $broker_ref, $code_ref, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items, $init) = @_;
+    my ($db, $pf_manager, $sys_manager_ref, $broker_ref, $code_ref, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items, $init) = @_;
     my @sysmanager = @{$sys_manager_ref};
     my @brokers = @{$broker_ref};
     my @codes = @{$code_ref};
@@ -205,7 +205,7 @@
     my @calc;
     foreach my $i ( 0..$#codes ) {
 
-      my ($calc, $first, $last) = find_calculator($codes[$i], $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+      my ($calc, $first, $last) = find_calculator($db, $codes[$i], $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
 
       $calc[$i] = $calc;
 

Modified: trunk/GT/Tools.pm
===================================================================
--- trunk/GT/Tools.pm	2008-06-10 04:59:06 UTC (rev 628)
+++ trunk/GT/Tools.pm	2008-06-10 05:10:25 UTC (rev 629)
@@ -630,7 +630,7 @@
 =cut
 
 sub find_calculator {
-  my ($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items) = @_;
+  my ($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items) = @_;
   $nb_item ||= 0;
   $max_loaded_items ||= -1;
 
@@ -642,9 +642,7 @@
     die($msg);
   }
 
-  my $db = GT::Eval::create_db_object();
   my ($prices, $calc) = get_timeframe_data($code, $timeframe, $db, $max_loaded_items);
-  $db->disconnect;
 
   my $c = $prices->count;
   my $first;