-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
84 lines (67 loc) · 2.15 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
require 'rake/clean'
require 'httpclient'
require 'rspec/core/rake_task'
require 'csv'
require 'awesome_print'
if Gem::Platform.local.os == 'mingw32'
DEPLOY_DIR='C:/src/pages/grin'
elsif Gem::Platform.local.os == 'linux'
DEPLOY_DIR="#{ENV['HOME']}/src/pages/grin"
else
raise "unknown OS"
end
GRIN_URL='https://waterdata.grandriver.ca/KiWIS/KiWIS?service=kisters&type=queryServices&request=%s&datasource=0&format=csv'
begin
RSpec::Core::RakeTask.new(:spec)
end
task :default => :deploy
CLEAN.include('html/*.html')
CLOBBER.include('data/*', 'html/*', 'html', 'data')
def download_csv(request, filename)
File.open(File.dirname(__FILE__)+"/data/#{filename}", "w") do |csv|
csv.write(HTTPClient.new.get(GRIN_URL % request).body)
end
end
directory 'data'
file 'data/stations.csv' do
download_csv('getStationList', 'stations.csv')
end
file 'data/parameters.csv' do
download_csv('getParameterList', 'parameters.csv')
end
desc "download list of stations and list of possible parameters"
task :data_dir => ['data', 'data/stations.csv', 'data/parameters.csv'] do
end
directory 'html'
desc "create html files"
task :html_dir => ['html', :data_dir] do
ruby 'lib/create_html.rb'
ruby 'lib/download_timeseries.rb'
end
directory DEPLOY_DIR
desc "deploy html"
task :deploy do
puts "copy all and git push"
files = Rake::FileList['html/*.html']
files.each do |f|
puts "copy #{f} -> #{DEPLOY_DIR}"
FileUtils.cp(f, DEPLOY_DIR)
end
Dir.chdir(DEPLOY_DIR)
puts `git status`
end
desc "create hash of stations"
task :hash => :data_dir do
puts "create hash"
stations_lst = CSV.read(File.dirname(__FILE__) + "/data/stations.csv", { headers: true, converters: :numeric, header_converters: :symbol, col_sep: ';' })
parameters_lst = CSV.read(File.dirname(__FILE__) + "/data/parameters.csv", { headers: true, converters: :numeric, header_converters: :symbol, col_sep: ';' })
stations = {}
stations_lst.each do |row|
stations[row[:station_no]] = row.to_hash.merge(parameters: [])
end
parameters_lst.each do |row|
station_no = row[:station_no]
stations[station_no][:parameters] << (Hash[row.headers[1..-1].zip(row.fields[1..-1])])
end
ap stations
end