This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rakefile
142 lines (106 loc) · 3.81 KB
/
rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require 'fileutils'
$: << 'lib'
require 'dd_logger'
## JOBS module knows how to do stuff, and are used by more concise tasks below
module DD_JOBS
BASE_DIR = Dir.pwd
#csv files
RAW_DATA_DIR = File.join(BASE_DIR ,'data')
TECHNICAL_DATA_DIR = File.join(RAW_DATA_DIR, 'technical')
#html template directory
TEMPLATE_DIR = File.join(BASE_DIR, 'templates')
#output locatons for html and .png files
OUTPUT_DIR = File.join(BASE_DIR, 'output')
GRAPH_OUTPUT_DIR = File.join(OUTPUT_DIR, 'imgs')
#log the config
constants.each {|c|
dir = const_get(c)
Log.debug "Job Config: #{c.to_s} = '#{dir}'"
}
def raw_data_files
glob_str = File.join(RAW_DATA_DIR, "*.csv")
files = Dir[glob_str]
Log.error "No csv files found in '#{glob_str}'" unless files.length > 0
files
end
require 'dd_historical_update'
require 'dd_technical_update'
include DD_Updater
def update_historical_data_folder
data_files = raw_data_files
Log.error "No csv files found in '#{glob_str}'" unless data_files.length > 0
data_files.each do |data_file|
symbol = data_file.match(/([A-Z^]+)\.csv$/)[1]
Log.debug "Updating symbol '#{symbol}' into file '#{data_file}'"
update_historical_csv symbol, data_file
end
end
def update_technical_data_folder
FileUtils.mkdir_p TECHNICAL_DATA_DIR unless Dir.exist? TECHNICAL_DATA_DIR
data_files = raw_data_files
data_files.each do |input_file|
symbol = input_file.match(/([A-Z^]+)\.csv$/)[1]
output_file = File.join(TECHNICAL_DATA_DIR, "#{input_file.match(/([A-Z^]+)\.csv$/)[1]}_analysis.csv")
Log.debug "Updating symbol '#{symbol}'\n\tinput file='#{input_file}'\n\toutput file='#{output_file}'"
update_technical_analysis_csv input_file, output_file
end
end
###GRAPHICS
#require 'dd_graph_generator'
#include DD_GRAPH_GENERATOR
#
#def make_graphics
# FileUtils.mkdir_p GRAPH_OUTPUT_DIR unless Dir.exist? GRAPH_OUTPUT_DIR
#
# input_data_file = File.join(TECHNICAL_DATA_DIR, '^GSPC_analysis.csv' )
# output_image_file = File.join(GRAPH_OUTPUT_DIR, 'gspc_200_day_dma_band.png')
# generate_dma_band_chart input_data_file, output_image_file, :dma_period => 200, :chart_days => 1000
#end
## HTML FILES
require 'dd_build_html'
include DD_HTML_Builder
BLOG_INPUT_DATA = File.join(TECHNICAL_DATA_DIR, '^GSPC_analysis.csv' )
BLOG_TEMPLATE_NAME = File.join(TEMPLATE_DIR, 'goog_site.html.erb')
def update_html_files
FileUtils.mkdir_p OUTPUT_DIR unless Dir.exist? OUTPUT_DIR
generate_daily_dose_html BLOG_INPUT_DATA, BLOG_TEMPLATE_NAME, OUTPUT_DIR
end
end
include DD_JOBS
## TASKS
task :setup_seed_data do
unless Dir.exist? RAW_DATA_DIR
Log.info "Extracting seed data to '#{RAW_DATA_DIR}'"
system("tar -xzvf data_backup.tar.gz")
end
end
task :update_historical_data do
update_historical_data_folder
end
task :update_historical_data => [:setup_seed_data]
task :update_technical_data do
update_technical_data_folder
end
#task :update_technical_data => [:update_historical_data]
task :build_blog_html do
update_html_files
end
#task :build_blog_html => [:update_technical_data, :make_graphics]
task :build_blog => [:setup_seed_data, :update_historical_data, :update_technical_data, :build_blog_html]
task :default => [:build_blog]
## TESTING TASKS
#How do I get a common test task to work, having structured my tests inline in the files like I did?
require 'rake/testtask'
#this runs all the files, but the test code doesnt run due to __FILE__==$0 test in each file hiding the test code
Rake::TestTask.new('testx') do |t|
t.libs << 'lib'
t.test_files = Dir['lib/*.rb']
t.verbose = true
end
#this runs all the tests, but not in a common run, just file by file
task :test do |t|
files = Dir['lib/*.rb']
files.each do |test_file|
Kernel.system("ruby -I lib #{test_file}")
end
end