Permalink
Browse files

Monthly jobs

  • Loading branch information...
wvanbergen committed Apr 28, 2012
1 parent ba2ffe0 commit 63487cc6abf289e44e0e63a097f7992e29714db9
@@ -0,0 +1,14 @@
+require 'rubygems'
+require 'mandy'
+
+Mandy.job "nasdaq_monthly_difference" do
+
+ map do |date, value|
+ symbol, volume, diff = value.split('|',3)
+ emit(date[0, 7], diff.to_f * volume.to_i)
+ end
+
+ reduce do |month, weighted_diffs|
+ emit(month, weighted_diffs.inject(0) { |sum, x| sum + x.to_f })
+ end
+end
View
@@ -0,0 +1,14 @@
+require 'rubygems'
+require 'mandy'
+
+Mandy.job "nasdaq_monthly_volume" do
+
+ map do |date, value|
+ symbol, volume, diff = value.split('|',3)
+ emit(date[0, 7], volume)
+ end
+
+ reduce do |month, volumes|
+ emit(month, volumes.inject(0) { |sum, x| sum + x.to_i })
+ end
+end
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+job_name = 'nasdaq_monthly_difference'
+require job_name
+
+describe job_name do
+
+ before(:all) do
+ @runner = Mandy::TestRunner.new(job_name)
+ end
+
+ it "should map a normal line properly" do
+ line = "1997-08-26\tDELL|30000|0.4"
+ @runner.map(line) do |mapper|
+ mapper.should_receive(:emit).with("1997-08", 12000.0)
+ end
+ end
+
+ it "should reduce properly" do
+ @runner.reduce("1997-08" => ['1', '2', '3']) do |mapper|
+ mapper.should_receive(:emit).with("1997-08", 6)
+ end
+ end
+end
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+
+job_name = 'nasdaq_monthly_volume'
+require job_name
+
+describe job_name do
+
+ before(:all) do
+ @runner = Mandy::TestRunner.new(job_name)
+ end
+
+ it "should map a normal line properly" do
+ line = "1997-08-26\tDELL|30000|0.4"
+ @runner.map(line) do |mapper|
+ mapper.should_receive(:emit).with("1997-08", "30000")
+ end
+ end
+
+ it "should reduce properly" do
+ @runner.reduce("1997-08" => ['1', '2', '3']) do |mapper|
+ mapper.should_receive(:emit).with("1997-08", 6)
+ end
+ end
+end

0 comments on commit 63487cc

Please sign in to comment.