App-Chart

 view release on metacpan or  search on metacpan

devel/convert-scm.pl  view on Meta::CPAN

#!/usr/bin/perl -w

# Copyright 2007, 2008, 2009, 2010, 2011, 2016 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/>.

use 5.006; # 3-arg open
use strict;
use warnings;
use Data::Dumper;
use File::Basename;
use List::Util qw(min max);
use POSIX;
use Scalar::Util;

use DBI;
use Lisp::Reader;
use File::Slurp;
use Date::Calc;

use App::Chart::Database;
use App::Chart::DBI;
use App::Chart::Download;
use App::Chart::Intraday;
use App::Chart::Gtk2::Symlist;


my $option_verbose = 1;

my $dbh = App::Chart::DBI->instance;
my $nbh = $dbh;
$Lisp::Reader::SYMBOLS_AS_STRINGS = 1;

sub directory_files {
  my ($dirname) = @_;
  return grep {/^[^.]/}
    map {File::Basename::basename($_)}
      glob "$dirname/*";
}

sub seconds_to_hmsstr {
  my ($seconds) = @_;
  return sprintf ('%02d:%02d:%02d', App::Chart::seconds_to_hms ($seconds));
}

sub insert_decimal {
  my ($str, $decimals) = @_;
  return $str if ($decimals == 0);
  my $sign = '';
  if ($str =~ /^(-)/) {
    $str = substr($str,1);
    $sign = '-';
  }
  $str = sprintf ("%0*s", $decimals+1, $str);
  substr($str,-$decimals,0, '.');

  return App::Chart::Download::trim_decimals ($sign . $str, 2);
}

sub convert_data {
  my @symbol_list = @_;
  print "database: ", scalar @symbol_list, " symbols\n";
  my $records = 0;

  foreach my $symbol (@symbol_list) {
    if ($option_verbose) {
      print "$symbol\n";
    }
    App::Chart::Database->add_symbol ($symbol);



( run in 2.410 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )