App/Chart/Suffix/KEX.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 85 CC 2 SCAR 10.0
CC
2
Cov
0%
intraday_url
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.7
1 # Kansai Commodities Exchange (KEX) setups. -*- coding: shift_jis -*-
2  
3 # Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2012 Kevin Ryde
4  
5 # This file is part of Chart.
6 #
7 # Chart is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3, or (at your option) any later version.
10 #
11 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Chart. If not, see <http://www.gnu.org/licenses/>.
18  
19 package App::Chart::Suffix::KEX;
20 use strict;
21 use warnings;
22 use Locale::TextDomain 'App-Chart';
23  
24 use App::Chart::Glib::Ex::MoreUtils;
25 use App::Chart;
26 use App::Chart::IntradayHandler;
27 use App::Chart::Sympred;
28 use App::Chart::TZ;
29 use App::Chart::Weblink;
30  
31  
32 my $pred = App::Chart::Sympred::Suffix->new ('.KEX');
33 App::Chart::TZ->tokyo->setup_for_symbol ($pred);
34  
35 # (source-help! kex-symbol?
36 # __p('manual-node','Kansai Commodities Exchange'))
37  
38 #------------------------------------------------------------------------------
39 # weblink - contract specifications
40 #
41  
42 # the english pages might be slightly old, but hopefully still accurate
43 my %specs = ('EBI' # frozen shrimp
44 => [ 'http://kanex.or.jp/yoko/yoko_ebi.html',
45 'http://kanex.or.jp/english/youkou-ebi-eng.htm' ],
46 'CF' # coffee
47 => [ 'http://kanex.or.jp/yoko/yoko_coffee.html',
48 'http://kanex.or.jp/english/youkou-cafe-eng.htm' ],
49 'KI' # corn75 index
50 => [ 'http://kanex.or.jp/yoko/yoko_corn_index.html',
51 'http://kanex.or.jp/english/youkou-corn-eng.htm' ],
52 'CO' # yellow corn
53 => [ 'http://kanex.or.jp/yoko/yoko_corn75.html',
54 undef ],
55 'RB' # azuki beans
56 => [ 'http://kanex.or.jp/yoko/yoko_azuki.html',
57 'http://kanex.or.jp/english/youkou-azuki-eng.htm' ],
58 'SG' # sugar
59 => [ 'http://kanex.or.jp/yoko/yoko_sugar.html',
60 'http://kanex.or.jp/english/youkou-sugar-eng.htm' ],
61 'SM' # soybean meal # gone as of Jul07
62 => [ 'http://kanex.or.jp/yoko/yoko_smeal.html',
63 undef ],
64 'BR' # broiler
65 => [ 'http://kanex.or.jp/yoko/yoko_broiler.html',
66 undef ],
67 'N' # non-gm soybeans
68 => [ 'http://kanex.or.jp/yoko/yoko_daizu.html',
69 'http://kanex.or.jp/english/youkou-non-eng.htm' ],
70 # 'RS' # raw silk
71 # #f
72 # undef
73 );
74  
75 App::Chart::Weblink->new
76 (pred => $pred,
77 name => __("KEX _Contract Specifications"),
78 desc => __("Open web browser at the Kansai Commodities Exchange contract specifications for this commodity"),
79 proc => sub {
80 my ($symbol) = @_;
81 my $commodity = App::Chart::symbol_commodity ($symbol);
82 my $elem = $specs{$commodity} || return undef;
83  
84 # selected en/ja language, but fallback to ja if the english is undef
85 my $url = App::Chart::Glib::Ex::MoreUtils::lang_select (ja => $elem->[0],
86 en => $elem->[1])
87 || $elem->[0];
88 return $url;
89 });
90  
91  
92 #-----------------------------------------------------------------------------
93 # intraday
94 #
95 # Daily data chart images are on the page
96 #
97 # http://kanex.or.jp/market/chart.html
98 # translated:
99 # http://translate.google.com/translate?u=http://kanex.or.jp/market/chart.html
100 #
101 # which results in images like
102 #
103 # http://kanex.or.jp/market/img/ebi_saki.jpg
104 #
105 # or for a particular month YYMM
106 #
107 # http://kanex.or.jp/market/img/cof_0705.jpg
108 #
109 # The commodity code parts are hard coded here, they're not quite the same
110 # as the download filenames.
111 #
112 # Not sure how much value there is in showing what's already available from
113 # the main chart graphs.
114  
115  
116 my %intraday_conv = ('EBI'=> 'ebi', # shimp
117 'N' => 'non', # non-gmo soy
118 'RB' => 'rbn', # azuki
119 'CF' => 'cof', # coffee index
120 'KI' => 'c75', # corn75
121 'SG' => 'sug'); # raw sugar
122 my $intraday_pred = App::Chart::Sympred::Proc->new
123 (sub {
124 my ($symbol) = @_;
125 my $commodity = App::Chart::symbol_commodity ($symbol);
126 return exists $intraday_conv{$commodity};
127 });
128  
129 App::Chart::IntradayHandler->new
130 (pred => $intraday_pred,
131 proc => \&intraday_url,
132 mode => 'daily',
133 name => __('_Daily'));
134  
135 sub intraday_url {
136 my ($self, $symbol, $mode) = @_;
137 my $commodity = App::Chart::symbol_commodity ($symbol);
138 App::Chart::Download::status (__x('KEX intraday {commodity}',
139 commodity => $commodity));
140 my $code = $intraday_conv{$commodity} || return;
141 my ($year, $month); # = App::Chart::symbol_ymd ($symbol);
142 if (defined $year) {
143 return sprintf 'http://kanex.or.jp/market/img/%s_%02d%02d.jpg',
144 $month, $year % 100;
145 } else {
146 return "http://kanex.or.jp/market/img/${code}_saki.jpg";
147 }
148 }
149  
150 1;
151 __END__