quandl_operation 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.travis.yml +20 -0
- data/.yardopts +2 -0
- data/Gemfile +2 -0
- data/LICENSE +7 -0
- data/README.md +15 -0
- data/Rakefile +11 -0
- data/UPGRADE.md +3 -0
- data/lib/quandl/operation.rb +17 -0
- data/lib/quandl/operation/collapse.rb +57 -0
- data/lib/quandl/operation/collapse/guess.rb +93 -0
- data/lib/quandl/operation/common_logger.rb +21 -0
- data/lib/quandl/operation/core_ext.rb +4 -0
- data/lib/quandl/operation/core_ext/array.rb +5 -0
- data/lib/quandl/operation/core_ext/date.rb +25 -0
- data/lib/quandl/operation/core_ext/float.rb +7 -0
- data/lib/quandl/operation/core_ext/time.rb +19 -0
- data/lib/quandl/operation/parse.rb +96 -0
- data/lib/quandl/operation/transform.rb +131 -0
- data/lib/quandl/operation/version.rb +5 -0
- data/quandl_operation.gemspec +25 -0
- data/spec/quandl_operation_collapse_spec.rb +8 -0
- data/spec/spec_helper.rb +4 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 080bea06efe1f790ddb4d1e46750669198add637
|
4
|
+
data.tar.gz: 17ee6fd001ebc3d5fb4567e2ffb7bd14b489caf3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75d3ebbf079378077b588b5583eb38503a562bb4fd055ffb2e16aafda476a890f32900dc06ffdb7070e9ca4cc2e29836fcfef28c09604e404e1a78e3023a3817
|
7
|
+
data.tar.gz: 27ce390435c47961e805a31e5f3b27d2e8e13c1c015ae3b308b95664462751e7b6879ef9a9524533484c502aa9dad5eb4ef1720401e00ac52c7beb7ba6f203a8
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format=Fivemat
|
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 1.9.3
|
6
|
+
- 1.9.2
|
7
|
+
- 1.8.7
|
8
|
+
|
9
|
+
gemfile:
|
10
|
+
- Gemfile
|
11
|
+
- gemfiles/activemodel-4.0.gemfile
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
- rvm: 1.8.7
|
16
|
+
gemfile: gemfiles/activemodel-4.0.gemfile
|
17
|
+
- rvm: 1.9.2
|
18
|
+
gemfile: gemfiles/activemodel-4.0.gemfile
|
19
|
+
|
20
|
+
script: "echo 'COME ON!' && bundle exec rake spec"
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012-2013 Blake Hilscher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Quandl::Operation
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
|
5
|
+
data = [[2456461, 1, 2, 3],[2456460, 2, 3, 4]]
|
6
|
+
|
7
|
+
Quandl::Operation::Collapse.perform(data, :weekly)
|
8
|
+
Quandl::Operation::Transform.perform(data, :rdiff)
|
9
|
+
|
10
|
+
|
11
|
+
csv = "2456461,9.992941176470588,10.974117647058824\n2456459,9.960611072664358,10.92053813148789\n"
|
12
|
+
|
13
|
+
Quandl::Operation::Parse.perform(csv)
|
14
|
+
|
15
|
+
```
|
data/Rakefile
ADDED
data/UPGRADE.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "quandl/operation/version"
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/inflector"
|
5
|
+
require "active_support/core_ext/hash"
|
6
|
+
require "active_support/core_ext/object"
|
7
|
+
|
8
|
+
require 'quandl/operation/core_ext'
|
9
|
+
require 'quandl/operation/common_logger'
|
10
|
+
require 'quandl/operation/collapse'
|
11
|
+
require 'quandl/operation/transform'
|
12
|
+
require 'quandl/operation/parse'
|
13
|
+
|
14
|
+
module Quandl
|
15
|
+
module Operation
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# subclasses
|
2
|
+
require 'quandl/operation/collapse/guess'
|
3
|
+
# collapse
|
4
|
+
module Quandl
|
5
|
+
module Operation
|
6
|
+
|
7
|
+
class Collapse
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def perform(data, frequency)
|
12
|
+
data = Parse.sort( data )
|
13
|
+
data = collapse_and_log(data, frequency)
|
14
|
+
data
|
15
|
+
end
|
16
|
+
|
17
|
+
def collapse_and_log(*args)
|
18
|
+
t1 = Time.now
|
19
|
+
r = collapse(*args)
|
20
|
+
CommonLogger.debug "#{self.name}.perform (#{t1.elapsed.microseconds}ms)"
|
21
|
+
r
|
22
|
+
end
|
23
|
+
|
24
|
+
def collapse(data, frequency)
|
25
|
+
# store the new collapsed data
|
26
|
+
collapsed_data = {}
|
27
|
+
range = find_end_of_range( data[0][0], frequency )
|
28
|
+
# iterate over the data
|
29
|
+
data.each do |row|
|
30
|
+
# grab date and value
|
31
|
+
date, value = row[0], row[1..-1]
|
32
|
+
value = value.first if value.count == 1
|
33
|
+
# bump to the next range if it exceeds the current one
|
34
|
+
range = find_end_of_range(date, frequency) unless inside_range?(date, range)
|
35
|
+
# consider the value for the next range
|
36
|
+
collapsed_data[range] = value if inside_range?(date, range) && value.present?
|
37
|
+
end
|
38
|
+
collapsed_data
|
39
|
+
end
|
40
|
+
|
41
|
+
def frequency?(data)
|
42
|
+
Guess.frequency(data)
|
43
|
+
end
|
44
|
+
|
45
|
+
def inside_range?(date, range)
|
46
|
+
date <= range
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_end_of_range(date, frequency)
|
50
|
+
Date.jd(date).end_of_frequency(frequency).jd
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Operation
|
3
|
+
class Collapse
|
4
|
+
|
5
|
+
class Guess
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def frequency(data)
|
9
|
+
return :annual unless data && data[0] && data[0][0]
|
10
|
+
t1 = Time.now
|
11
|
+
# find the smallest point of difference between dates
|
12
|
+
gap = find_average_gap(data)
|
13
|
+
# ensure gap is not negative
|
14
|
+
gap = ensure_positive_gap(gap)
|
15
|
+
# determine the freq from the size of the smallest gap
|
16
|
+
freq = frequency_from_gap(gap)
|
17
|
+
CommonLogger.debug "#{self.name}.perform (#{t1.elapsed.microseconds}ms)"
|
18
|
+
freq
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_smallest_gap(data)
|
22
|
+
# init
|
23
|
+
gap = 100_000
|
24
|
+
pdate = nil
|
25
|
+
# find the smallest gap
|
26
|
+
data.each do |row|
|
27
|
+
# if the gap is 1, we're done
|
28
|
+
break if gap <= 1
|
29
|
+
# this row's date
|
30
|
+
date = row[0]
|
31
|
+
# only if pdate is present
|
32
|
+
if pdate
|
33
|
+
# calculate the gap
|
34
|
+
diff = (pdate - date).to_i
|
35
|
+
# replace the previous gap if it is smaller
|
36
|
+
gap = diff if diff < gap
|
37
|
+
end
|
38
|
+
# previous row's date
|
39
|
+
pdate = date
|
40
|
+
end
|
41
|
+
gap
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_average_gap(data)
|
45
|
+
# init
|
46
|
+
gap = 100_000
|
47
|
+
pdate = nil
|
48
|
+
row_count = data.count
|
49
|
+
majority_count = (row_count * 0.55).to_i
|
50
|
+
gaps = {}
|
51
|
+
# find the smallest gap
|
52
|
+
data.each do |row|
|
53
|
+
# this row's date
|
54
|
+
date = row[0]
|
55
|
+
# only if pdate is present
|
56
|
+
if pdate
|
57
|
+
# calculate the gap
|
58
|
+
diff = (pdate - date).to_i
|
59
|
+
# increment the gap counter
|
60
|
+
gaps[diff] ||= 0
|
61
|
+
gaps[diff] += 1
|
62
|
+
# if the diff count is greater than majority_count, we have a consensus
|
63
|
+
return diff if gaps[diff] > majority_count
|
64
|
+
end
|
65
|
+
# previous row's date
|
66
|
+
pdate = date
|
67
|
+
end
|
68
|
+
gaps.to_a.sort_by{|r| r[1] }.try(:last).try(:first)
|
69
|
+
end
|
70
|
+
|
71
|
+
def frequency_from_gap(gap)
|
72
|
+
|
73
|
+
case
|
74
|
+
when gap <= 1 then :daily
|
75
|
+
when gap <= 10 then :weekly
|
76
|
+
when gap <= 31 then :monthly
|
77
|
+
when gap <= 93 then :quarterly
|
78
|
+
else :annual
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def ensure_positive_gap(gap)
|
83
|
+
gap = gap.to_i
|
84
|
+
gap = gap * -1 if gap < 0
|
85
|
+
gap
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Operation
|
3
|
+
|
4
|
+
class CommonLogger
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
delegate :info, :debug, :with_time_elapsed, to: :logger, allow_nil: true
|
9
|
+
|
10
|
+
def logger
|
11
|
+
@@logger if defined?(@@logger)
|
12
|
+
end
|
13
|
+
def use(value)
|
14
|
+
@@logger = value
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
class Array
|
2
|
+
def self.forwardable_methods
|
3
|
+
[:reject, :keep_if, :permutation, :to_a, :cycle, :drop, :take_while, :map, :rotate, :each_slice, :pack, :select!, :combination, :repeated_combination, :shift, :select, :reverse!, :==, :clear, :rotate!, :inspect, :iter_for_each, :sort_by!, :compact!, :|, :copy_data_simple, :nitems, :zip, :take, :rassoc, :flatten!, :join, :compact, :[]=, :frozen?, :slice!, :drop_while, :reverse_each, :shuffle, :slice, :reverse, :insert, :uniq, :first, :count, :fetch, :hash, :to_ary, :find_index, :replace, :-, :product, :iter_for_reverse_each, :pop, :push, :sort, :fill, :uniq!, :length, :&, :flatten, :repeated_permutation, :[], :shuffle!, :sort!, :sample, :include?, :<<, :dimensions, :collect, :+, :rindex, :<=>, :eql?, :indices, :collect!, :iter_for_each_index, :iter_for_each_with_index, :index, :*, :indexes, :copy_data, :delete, :to_s, :assoc, :delete_at, :unshift, :delete_if, :empty?, :reject!, :last, :size, :concat, :map!, :at, :each_index, :transpose, :values_at, :each, :enum_cons, :group_by, :enum_with_index, :entries, :with_object, :chunk, :each_with_index, :min, :inject, :one?, :partition, :enum_slice, :none?, :max_by, :any?, :flat_map, :reduce, :each_entry, :find, :minmax_by, :collect_concat, :each_cons, :member?, :max, :sort_by, :detect, :all?, :minmax, :grep, :each_with_object, :find_all]
|
4
|
+
end
|
5
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Date
|
2
|
+
|
3
|
+
def start_of_frequency(freq)
|
4
|
+
case freq.to_sym
|
5
|
+
when :daily then self
|
6
|
+
when :weekly then self.beginning_of_week
|
7
|
+
when :monthly then self.beginning_of_month
|
8
|
+
when :quarterly then self.beginning_of_quarter
|
9
|
+
when :annual then self.beginning_of_year
|
10
|
+
when :annually then self.beginning_of_year
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def end_of_frequency(freq)
|
15
|
+
case freq.to_sym
|
16
|
+
when :daily then self
|
17
|
+
when :weekly then self.end_of_week
|
18
|
+
when :monthly then self.end_of_month
|
19
|
+
when :quarterly then self.end_of_quarter
|
20
|
+
when :annual then self.end_of_year
|
21
|
+
when :annually then self.end_of_year
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Operation
|
3
|
+
|
4
|
+
class Parse
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def perform(data)
|
9
|
+
return [] if data.blank?
|
10
|
+
t1 = Time.now
|
11
|
+
data = csv(data)
|
12
|
+
data = julian_string_to_integer(data)
|
13
|
+
data = sort(data)
|
14
|
+
CommonLogger.debug "#{self.name}.perform (#{t1.elapsed.microseconds}ms)"
|
15
|
+
data
|
16
|
+
end
|
17
|
+
|
18
|
+
def csv(data)
|
19
|
+
data = CSV.parse( data ) if data.is_a?(String)
|
20
|
+
data
|
21
|
+
end
|
22
|
+
|
23
|
+
def sort(data, order = :asc)
|
24
|
+
data_order = sort_order?(data)
|
25
|
+
# ascending
|
26
|
+
if order == :asc && data_order != :asc
|
27
|
+
data = sort_asc(data)
|
28
|
+
# descending
|
29
|
+
elsif order == :desc && data_order != :desc
|
30
|
+
data = sort_desc(data)
|
31
|
+
end
|
32
|
+
data
|
33
|
+
end
|
34
|
+
|
35
|
+
def sort_order?(data)
|
36
|
+
return :none if data.blank? || data[0].blank? || data[1].blank?
|
37
|
+
data[0][0] > data[1][0] ? :desc : :asc
|
38
|
+
end
|
39
|
+
|
40
|
+
def sort_asc(data)
|
41
|
+
data.sort_by{|r| r[0] }
|
42
|
+
end
|
43
|
+
|
44
|
+
def sort_desc(data)
|
45
|
+
data.sort_by{|r| r[0] }.reverse
|
46
|
+
end
|
47
|
+
|
48
|
+
def date_to_julian(data)
|
49
|
+
return data if data[0][0].is_a?(Integer)
|
50
|
+
# dont alter by reference
|
51
|
+
result = []
|
52
|
+
# for each row
|
53
|
+
data.each_with_index do |row, index|
|
54
|
+
# copy
|
55
|
+
nrow = row.dup
|
56
|
+
# string to date
|
57
|
+
date = nrow[0]
|
58
|
+
date = Date.parse(nrow[0]) if nrow[0].is_a?(String)
|
59
|
+
# date to julian
|
60
|
+
nrow[0] = date.jd if date.respond_to?(:jd)
|
61
|
+
# save result
|
62
|
+
result[index] = nrow
|
63
|
+
end
|
64
|
+
# all done
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def julian_to_date(data)
|
69
|
+
return data if data[0][0].is_a?(Date)
|
70
|
+
# dont alter by reference
|
71
|
+
result = []
|
72
|
+
# for each row
|
73
|
+
data.each_with_index do |row, index|
|
74
|
+
# copy
|
75
|
+
nrow = row.dup
|
76
|
+
# parse date
|
77
|
+
nrow[0] = Date.jd( nrow[0].to_i ) unless nrow[0].is_a?(Date)
|
78
|
+
# save result
|
79
|
+
result[index] = nrow
|
80
|
+
end
|
81
|
+
# all done
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
def julian_string_to_integer(data)
|
86
|
+
# skip when already formatted correctly
|
87
|
+
return data if data[0][0].is_a?(Integer) || data[0][0].is_a?(Date)
|
88
|
+
# otherwise cast string jds to int
|
89
|
+
data.collect{|r| r[0] = r[0].to_i; r }
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# collapse
|
2
|
+
module Quandl
|
3
|
+
module Operation
|
4
|
+
|
5
|
+
class Transform
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def perform( data, type)
|
9
|
+
data = Parse.sort( data, :asc )
|
10
|
+
data = transform_and_log( data, type)
|
11
|
+
data
|
12
|
+
end
|
13
|
+
|
14
|
+
def transform_and_log(*args)
|
15
|
+
t1 = Time.now
|
16
|
+
r = transform(*args)
|
17
|
+
CommonLogger.debug "#{self.name}.perform (#{t1.elapsed.microseconds}ms)"
|
18
|
+
r
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_transformation?(type)
|
22
|
+
valid_transformations.include?( type )
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_transformations
|
26
|
+
[ :diff, :rdiff, :cumul, :normalize ]
|
27
|
+
end
|
28
|
+
|
29
|
+
def transform( data, type)
|
30
|
+
return data if data.blank?
|
31
|
+
#Transforms table from actual data points
|
32
|
+
#to differences between points (:diff)
|
33
|
+
#or a ratio between points(:rdiff)
|
34
|
+
#If type is other than these two, nothing is done.
|
35
|
+
|
36
|
+
# ensure that type is in the expected format
|
37
|
+
type = type.to_sym
|
38
|
+
# nothing to do unless valid transform
|
39
|
+
return unless valid_transformation?( type )
|
40
|
+
|
41
|
+
temparr = Array.new
|
42
|
+
#first make a keylist
|
43
|
+
keylist = data.transpose.first
|
44
|
+
# now sort the keylist from oldest to newest
|
45
|
+
# unless there is only one point
|
46
|
+
if keylist.count > 1
|
47
|
+
keylist = keylist.reverse if keylist[0] > keylist[1] # better performance if we do this first
|
48
|
+
keylist.sort!
|
49
|
+
end
|
50
|
+
|
51
|
+
#find number of columns
|
52
|
+
numcols = data.first.size - 1
|
53
|
+
if type == :normalize
|
54
|
+
divisor = Array.new(numcols,nil)
|
55
|
+
0.upto(keylist.length - 1) do |i|
|
56
|
+
temparr[i] = []
|
57
|
+
curr_row = data[i][1..-1]
|
58
|
+
0.upto(numcols-1) do |x|
|
59
|
+
if curr_row[x].nil?
|
60
|
+
temparr[i][x] = nil
|
61
|
+
elsif divisor[x].nil?
|
62
|
+
if curr_row[x].to_f != 0
|
63
|
+
divisor[x] = curr_row[x].to_f
|
64
|
+
temparr[i][x] = 100.0
|
65
|
+
else
|
66
|
+
temparr[i][x] = 0
|
67
|
+
end
|
68
|
+
else
|
69
|
+
temparr[i][x] = curr_row[x] / divisor[x] * 100.0
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
0.upto(keylist.length-1) do |i|
|
74
|
+
data[i] = [keylist[i], temparr[i]].flatten
|
75
|
+
end
|
76
|
+
elsif [:diff, :rdiff].include? type
|
77
|
+
#now build temparr
|
78
|
+
1.upto(keylist.length - 1) do |i|
|
79
|
+
temparr[i] = []
|
80
|
+
curr_row = data[i][1..-1]
|
81
|
+
prev_row = data[i-1][1..-1]
|
82
|
+
0.upto(numcols-1) do |x|
|
83
|
+
if type == :diff
|
84
|
+
if !curr_row[x].nil? and !prev_row[x].nil?
|
85
|
+
temparr[i][x] = Float(curr_row[x]) - Float(prev_row[x])
|
86
|
+
else
|
87
|
+
temparr[i][x] = nil
|
88
|
+
end
|
89
|
+
else
|
90
|
+
if !curr_row[x].nil? and !prev_row[x].nil? and prev_row[x] != 0
|
91
|
+
temparr[i][x] = ( Float(curr_row[x]) - Float(prev_row[x]) ) / Float( prev_row[x] )
|
92
|
+
else
|
93
|
+
temparr[i][x] = nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#now put temparr into datapac
|
100
|
+
1.upto(keylist.length-1) do |i|
|
101
|
+
data[i] = [keylist[i], temparr[i]].flatten
|
102
|
+
end
|
103
|
+
|
104
|
+
#delete the first date in datapac (because there is no diff for that)
|
105
|
+
data.delete_at(0)
|
106
|
+
else
|
107
|
+
cumulsum = Array.new(numcols,0)
|
108
|
+
sumstarted = Array.new(numcols,false)
|
109
|
+
#now build temparr
|
110
|
+
0.upto(keylist.length - 1) do |i|
|
111
|
+
temparr[i] = []
|
112
|
+
curr_row = data[i][1..-1]
|
113
|
+
0.upto(numcols-1) do |x|
|
114
|
+
if !curr_row[x].nil?
|
115
|
+
cumulsum[x] = cumulsum[x] + curr_row[x]
|
116
|
+
sumstarted[x] = true
|
117
|
+
end
|
118
|
+
temparr[i][x] = cumulsum[x] if sumstarted[x]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
0.upto(keylist.length-1) do |i|
|
122
|
+
data[i] = [keylist[i],temparr[i]].flatten
|
123
|
+
end
|
124
|
+
end
|
125
|
+
data
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "quandl/operation/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "quandl_operation"
|
7
|
+
s.version = Quandl::Operation::VERSION
|
8
|
+
s.authors = ["Blkae Hilscher"]
|
9
|
+
s.email = ["blake@hilscher.ca"]
|
10
|
+
s.homepage = "http://blake.hilscher.ca/"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.summary = "For altering data"
|
13
|
+
s.description = "Data will be operated"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rake", "~> 10.0"
|
21
|
+
s.add_development_dependency "rspec", "~> 2.13"
|
22
|
+
s.add_development_dependency "fivemat", "~> 1.2"
|
23
|
+
|
24
|
+
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quandl_operation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blkae Hilscher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fivemat
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
description: Data will be operated
|
70
|
+
email:
|
71
|
+
- blake@hilscher.ca
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- .yardopts
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- UPGRADE.md
|
85
|
+
- lib/quandl/operation.rb
|
86
|
+
- lib/quandl/operation/collapse.rb
|
87
|
+
- lib/quandl/operation/collapse/guess.rb
|
88
|
+
- lib/quandl/operation/common_logger.rb
|
89
|
+
- lib/quandl/operation/core_ext.rb
|
90
|
+
- lib/quandl/operation/core_ext/array.rb
|
91
|
+
- lib/quandl/operation/core_ext/date.rb
|
92
|
+
- lib/quandl/operation/core_ext/float.rb
|
93
|
+
- lib/quandl/operation/core_ext/time.rb
|
94
|
+
- lib/quandl/operation/parse.rb
|
95
|
+
- lib/quandl/operation/transform.rb
|
96
|
+
- lib/quandl/operation/version.rb
|
97
|
+
- quandl_operation.gemspec
|
98
|
+
- spec/quandl_operation_collapse_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: http://blake.hilscher.ca/
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.0.3
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: For altering data
|
124
|
+
test_files:
|
125
|
+
- spec/quandl_operation_collapse_spec.rb
|
126
|
+
- spec/spec_helper.rb
|