Changeset 19262
- Timestamp:
- 09/13/08 16:15:19 (5 years ago)
- Location:
- lang/perl/App-Hachero/trunk
- Files:
-
- 8 added
- 7 modified
-
config.yaml (modified) (2 diffs)
-
lib/App/Hachero.pm (modified) (4 diffs)
-
lib/App/Hachero/Plugin/Analyze/AccessCount.pm (modified) (1 diff)
-
lib/App/Hachero/Plugin/Input/File.pm (modified) (3 diffs)
-
lib/App/Hachero/Plugin/Output/HadoopReduce.pm (added)
-
lib/App/Hachero/Plugin/OutputLine (added)
-
lib/App/Hachero/Plugin/OutputLine/HadoopMap.pm (added)
-
lib/App/Hachero/Plugin/Parse/HadoopReduce.pm (added)
-
t/plugin/analyze/02_accesscount.t (modified) (4 diffs)
-
t/plugin/input/01_stdin.t (modified) (1 diff)
-
t/plugin/input/03_file.t (modified) (1 diff)
-
t/plugin/output/02_hadoop_reduce.t (added)
-
t/plugin/output_line (added)
-
t/plugin/output_line/01_hadoop_map.t (added)
-
t/plugin/parse/03_hadoop_reduce.t (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/App-Hachero/trunk/config.yaml
r18806 r19262 1 global:2 work_path: t/work3 4 1 plugins: 5 2 … … 14 11 time_zone: Asia/Tokyo 15 12 16 - module: Analyze::AccessCount 17 18 - module: Output::DBIC 19 config: 20 connect_info: 21 - dbi:mysql:test 13 - module: OutputLine::HadoopMap 14 # 15 # - module: Analyze::AccessCount 16 # 17 # - module: Output::DBIC 18 # config: 19 # connect_info: 20 # - dbi:mysql:test -
lang/perl/App-Hachero/trunk/lib/App/Hachero.pm
r19223 r19262 18 18 19 19 sub new { 20 my $class = shift; 21 my $args = $_[0]; 20 my ($class,$args) = @_; 21 $class->_setup_plugins_static($args); 22 my $self = $class->SUPER::new($args); 23 $self->result({}); 24 $context = $self; 25 $self; 26 } 27 28 sub _setup_plugins_static { 29 my ($class, $args) = @_; 22 30 my $config = $class->setup_config( $args->{config} ); 23 31 … … 36 44 $packages_from_plugin_path = $collect->modules; 37 45 } 38 39 46 $class->load_plugins(@plugins); 40 41 my $self = $class->SUPER::new(@_);42 $self->result({});43 $context = $self;44 $self;45 47 } 46 48 … … 53 55 sub run { 54 56 my $self = shift; 57 $self->log(debug => sprintf ('run start: %s', scalar localtime)); 55 58 $self->initialize; 56 59 $self->run_hook('fetch'); … … 59 62 $self->run_hook_and_check('classify') or next; 60 63 $self->run_hook_and_check('analyze') or next; 64 $self->run_hook('output_line'); 61 65 } 62 66 $self->run_hook('associate'); 63 67 $self->run_hook('output'); 68 $self->log(debug => sprintf ('run end: %s', scalar localtime)); 64 69 } 65 70 -
lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Analyze/AccessCount.pm
r18806 r19262 4 4 use base qw(App::Hachero::Plugin::Base); 5 5 use DateTime::Format::MySQL; 6 use Digest::MD5; 6 7 7 8 sub analyze : Hook { 8 9 my ($self, $context, $args) = @_; 9 10 my $req = $context->currentinfo->{request} or return; 11 my $truncate = $self->config->{config}->{truncate_to} || 'minute'; 10 12 my $time = DateTime::Format::MySQL->format_datetime( 11 $req->{datetime}->clone->truncate(to => 'minute')13 $req->{datetime}->clone->truncate(to => $truncate) 12 14 ); 13 $context->result->{'AccessCount'}->{$time} = { 15 my $hash = Digest::MD5::md5_base64($time); 16 $context->result->{'AccessCount'}->{$hash} = { 14 17 datetime => $time, 15 count => ($context->result->{'AccessCount'}->{$ time}->{count} || 0) + 1,18 count => ($context->result->{'AccessCount'}->{$hash}->{count} || 0) + 1, 16 19 } 17 20 } -
lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Input/File.pm
r18891 r19262 4 4 use base qw(App::Hachero::Plugin::Base); 5 5 use File::Find::Rule; 6 use File::stat; 6 7 7 8 sub init { … … 12 13 my ($self, $context) = @_; 13 14 $self->{rule} ||= $self->_get_rule($context); 14 my $file; 15 while (1) { 16 $file = $self->{rule}->match or return; 17 $file !~ /^\.{1,2}/ and last; 15 my $file = $self->{rule}->match or return; 16 17 if ($context->conf->{global}->{log}->{level} eq 'debug') { 18 $context->log(debug => "opening file: $file"); 19 $self->{readsize} = 0; 20 $self->{filesize} = stat($file)->size; 18 21 } 19 22 open my $fh, '<', $file or die; … … 34 37 my $fh = $self->{fh} || $self->_fetch($context) or return; 35 38 $line = <$fh>; 39 if ($context->conf->{global}->{log}->{level} eq 'debug') { 40 $self->{readsize}+= do {use bytes; length $line} if $line; 41 print STDERR "\rreading file: $self->{readsize}/$self->{filesize}"; 42 } 36 43 unless ($line) { 37 44 close $self->{fh}; -
lang/perl/App-Hachero/trunk/t/plugin/analyze/02_accesscount.t
r18891 r19262 14 14 { 15 15 module => 'Analyze::AccessCount', 16 config => { 17 18 }, 16 config => {truncate_to => 'hour'}, 19 17 } 20 18 ] … … 35 33 $app->run_hook('parse'); 36 34 $app->run_hook('analyze'); 37 is_deeply $app->result->{'AccessCount'}, $block->expected; 35 my $value = (values %{$app->result->{AccessCount}})[0]; 36 is_deeply $value, $block->expected; 38 37 } 39 38 … … 56 55 57 56 --- expected 58 '2008-08-07 00:00:00': 59 datetime: '2008-08-07 00:00:00' 60 count: 1 57 datetime: '2008-08-07 00:00:00' 58 count: 1 61 59 62 60 === test2 … … 75 73 76 74 --- expected 77 '2008-08-06 15:05:00': 78 datetime: '2008-08-06 15:05:00' 79 count: 1 75 datetime: '2008-08-06 15:00:00' 76 count: 1 77 -
lang/perl/App-Hachero/trunk/t/plugin/input/01_stdin.t
r18891 r19262 9 9 10 10 { 11 my $line = 'hoge hoge';11 my $line = 'hoge'; 12 12 my ($fh, $log) = File::Temp::tempfile; 13 13 print $fh $line; -
lang/perl/App-Hachero/trunk/t/plugin/input/03_file.t
r19113 r19262 10 10 11 11 my $config = { 12 global => {work_path => 't/work'}, 12 global => { 13 work_path => 't/work', 14 log => {level => 'error'}, 15 }, 13 16 plugins => [ 14 17 {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)