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

[GT] Re: extension in Text.pm



strangespider wrote:
Hi,

I observed a problem with the extension in the module Text.pm


=item DB::text::file_extension  string

To be appended to the code file name when
searching the data file.  For instance, if the data file is called EURUSD.csv
this variable would have the value '.csv' (without the quotes).

The default file_extension is '.txt'.


You can find this setting here:
Finance::GeniusTrader::Conf::default('DB::Text::file_extension', '.txt');





I can set the extension in the ~/.gt/options file, e.g you have csv-files:
DB::text::file_extension .csv

But how can I unset any extensions? My files are just the symbol name with no extension.
IBM
QQQQ
...

At the moment I edited Finance::GeniusTrader::Conf::default('DB::Text::file_extension', '.txt');
in the Text.pm file to
Finance::GeniusTrader::Conf::default('DB::Text::file_extension', '');



Am I doing something wrong with the options file?


Best regards


strangespider

please evaluate the following patch, relative to trunk branch (sorry) and report.
i don't use the text database much ...

aloha

ras

--- ../svn_repo/GT/DB/Text.pm	2009-11-12 13:11:13.576831000 -0800
+++ ../GT/DB/Text.pm	2009-11-12 14:11:46.611289000 -0800
@@ -63,14 +63,30 @@
 if you have data in different timeframes, for instance, EURUSD_hour.csv and
 EURUSD_day.csv, use the following value for this directive:
 
-=item DB::text::file_extension	_$timeframe.csv
+=item DB::text::file_extension	_\$timeframe.csv
+
+ notes: @ the leading backslash on perl variable $timeframe is needed,
+          but is not part of the actual filename. in this example the
+          filenames would look like:
+             IBM_10min.csv
+             IBM_day.csv
+             IBM_week.csv
+        @ you can use a null string (empty string) for the
+          file_extension by defining the key like so:
+             DB::text::file_extension	''
+          or
+             DB::text::file_extension	""
+
+=item DB::text::format		0|1|2|3 (default is 3)
 
-=item DB::text::format                0|1|2|3 (default is 3)
 The format of the date/time string. Valid values are: 
-0 - yyyy-mm-dd hh:nn:ss (the time string is optional)
-1 - US Format (month before day, any format understood by Date::Calc)
-2 - European Format (day before month, any format understood by Date::Calc)
-3 - Any format understood by Date::Manip
+
+ 0 - yyyy-mm-dd hh:nn:ss (the time string is optional)
+ 1 - US Format (month day year, any format understood
+     by Date::Calc)
+ 2 - European Format (day month year, any format understood
+     by Date::Calc)
+ 3 - Any format understood by Date::Manip
 
 =item DB::text::fields::datetime	number
 
@@ -112,7 +128,6 @@
 full of text files containing prices.
 
 =cut
-
 sub new {
     my $type = shift;
     my $class = ref($type) || $type;
@@ -175,28 +190,39 @@
     my ($self, $code, $timeframe) = @_;
     $timeframe = $DAY unless ($timeframe);
 
-    my $prices = GT::Prices->new;
+    #return GT::Prices->new() if ($timeframe > $DAY);
 
+    my $prices = GT::Prices->new;
     # WARNING: Can only load data that is in daily format or smaller
     # Trying to load weekly or monthly data will fail.
     return $prices if ($timeframe > $DAY);
 
     $prices->set_timeframe($timeframe);
-
+ 
     my %fields = ('open' => $self->{'open'}, 'high' => $self->{'high'},
                   'low' => $self->{'low'}, 'close' => $self->{'close'},
-		  'volume' => $self->{'volume'}, 'date' => $self->{'datetime'});
+                  'volume' => $self->{'volume'}, 'date' => $self->{'datetime'});
     $self->{'fields'} = \%fields;
 
     my $extension = $self->{'extension'};
     my $tfname = GT::DateTime::name_of_timeframe($timeframe);
     $extension =~ s/\$timeframe/$tfname/g;
 
-    my $file = $self->{'directory'} . "/$code" . $extension;
-
-    $prices->loadtxt($file, $self->{'mark'}, $self->{'date_format'},
-		     $self->{'header_lines'}, %fields);
+    my $file = ( $extension =~ m//o )
+     ? join "", $self->{'directory'}, "/$code"
+     : join "", $self->{'directory'}, "/$code", $extension;
+
+    $prices->loadtxt( $file,
+                      $self->{'mark'},
+                      $self->{'date_format'},
+                      $self->{'header_lines'},
+                      ,
+                      %fields,
+                    );
+#    $prices->loadtxt($file, $self->{'mark'}, $self->{'date_format'},
+#                    $self->{'header_lines'}, %fields);
     return $prices;
+
 }
 
 =pod
@@ -221,10 +247,13 @@
     $extension =~ s/\$timeframe/\.\*/g;
     my $file_exists = 0;
     my $file_pattern = $self->{'directory'} . "/$code$extension";
+    #my $file_pattern = "$code$extension";
 
     if ($extension =~ /\*/) {
         eval "use File::Find;";
-        find (  sub { $file_exists = 1 if ($_ =~ /$file_pattern/);  },$self->{'directory'});
+        find ( sub { $file_exists = 1 if ($_ =~ /$file_pattern/); },
+               $self->{'directory'}
+             );
     } else {
         $file_exists = 1 if (-e $file_pattern);
     }