App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Series/GT.pm  view on Meta::CPAN

# Copyright 2008, 2009, 2010, 2024 Kevin Ryde

# This file is part of Chart.
#
# Chart is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3, or (at your option) any later version.
#
# Chart is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart.  If not, see <http://www.gnu.org/licenses/>.

package App::Chart::Series::GT;
use 5.010;
use strict;
use warnings;
use Carp;
use List::Util qw(min max);
use base 'App::Chart::Series';

use GT::Prices;
use GT::Conf;
use GT::Eval;
use GT::DateTime;
use GT::Tools;

use constant DEBUG => 0;


my %class_to_timeframe = ('App::Chart::Timebase::Days'   => $DAY,
                          'App::Chart::Timebase::Weeks'  => $WEEK,
                          'App::Chart::Timebase::Months' => $MONTH,
                          'App::Chart::Timebase::Years'  => $YEAR);

sub new {
  my ($class, $type, $parent, @args) = @_;
  if (DEBUG) { local $,=' '; print "GT->new type '$type' args", @args, "\n"; }
  my $indicator = GT::Eval::create_standard_object ($type, @args);
  my $nb_values = $indicator->get_nb_values;
  my $arrays = {};
  foreach my $i (0 .. $nb_values-1) {
    my $name = $indicator->get_name ($i);
    $arrays->{$name} = [];
  }
  my $array_aliases = { values => $indicator->get_name(0) };
  if (DEBUG) { require Data::Dumper;
               print "  ",Data::Dumper->Dump([$arrays],['arrays']);
               print "  ",Data::Dumper->Dump([$array_aliases],
                                             ['array_aliases']); }

  return $class->SUPER::new (parent        => $parent,
                             indicator     => $indicator,
                             arrays        => $arrays,
                             array_aliases => $array_aliases);
}

sub name {
  my ($self) = @_;
  my $indicator = $self->{'indicator'};
  return $indicator->get_name;
}

sub fill_part {
  my ($self, $lo, $hi) = @_;
  if (DEBUG) { print "GT fill_part $lo $hi\n"; }

  my $parent = $self->{'parent'};
  my $timebase = $self->timebase;
  my $indicator = $self->{'indicator'};

  require GT::DB::Chart;
  my $db = GT::DB::Chart->new ($parent, $hi);
  my $code = $parent->symbol || 'DUMMY-STOCK-CODE';
  my $timebase_class = ref $timebase;
  # ENHANCE-ME: can probably fallback to $DAYS or something for unknown
  # $timebase_class, not much in the GT indicators depends on the timebase
  my $timeframe = $class_to_timeframe{$timebase_class}
    || croak "Timebase class $timebase_class not known to GT";
  my $full = 0;
  my $start = $timebase->to_iso ($lo);
  my $end = $timebase->to_iso ($hi);
  my $nb_item = 0;
  my $max_loaded_items = $hi - $lo + 1 + $indicator->days_required;



( run in 1.334 second using v1.01-cache-2.11-cpan-39bf76dae61 )